【问题标题】:grunt-bower-install links bower_components to current directorygrunt-bower-install 将 bower_components 链接到当前目录
【发布时间】:2014-02-18 17:21:53
【问题描述】:

我最近使用 Yeoman Angular 生成器和 Grunt 和 Bower 开始了一个新项目。

每当 grunt 构建我的应用程序时,grunt-bower-install 都会在 index.html 文件中重新生成指向我的 bower_components 的所有链接。

无论出于何种原因,这些资产都链接到当前目录而不是根目录,因此当我导航到超过一层深度的新 URL 时,我的所有依赖项都会中断。

如何使组件链接到根目录而不是当前目录?

当前结果:

<script src="bower_components/modernizr/modernizr.js"></script>

想要的结果:

<script src="/bower_components/modernizr/modernizr.js"></script>

Gruntfile:

'bower-install': {
  app: {
    html: '<%= yeoman.app %>/index.html',
    ignorePath: '<%= yeoman.app %>/'
  }
}

【问题讨论】:

标签: javascript gruntjs yeoman bower


【解决方案1】:

我在 yo 1.1.2 遇到了同样的问题,这就是我解决问题的方法,在 Gruntfile.js 中,在wiredep 任务中添加 fileTypes 选项:

// Automatically inject Bower components into the app
wiredep: {
  app: {
    src: ['<%= yeoman.app %>/index.html'],
    ignorePath: new RegExp('^<%= yeoman.app %>/|../'),
    fileTypes: {
      html: {
        replace: {
          js: '<script src="/{{filePath}}"></script>',
          css: '<link rel="stylesheet" href="/{{filePath}}" />'
        }
      }
    }
  }
},

【讨论】:

    猜你喜欢
    • 2023-03-30
    • 2014-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-17
    • 1970-01-01
    • 2014-07-05
    相关资源
    最近更新 更多