首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >grunt bower-install links bower_components to current directory

grunt bower-install links bower_components to current directory
EN

Stack Overflow用户
提问于 2014-02-19 01:21:53
回答 1查看 920关注 0票数 1

我最近与Grunt和Bower一起启动了一个新项目,使用的是约曼角度生成器。

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

无论出于什么原因,这些资产都链接到当前目录,而不是根目录,所以当我导航到一个超过一层深的新Url时,我的所有依赖项都会断开。

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

当前结果:

代码语言:javascript
复制
<script src="bower_components/modernizr/modernizr.js"></script>

期望的结果:

代码语言:javascript
复制
<script src="/bower_components/modernizr/modernizr.js"></script>

Gruntfile文件:

代码语言:javascript
复制
'bower-install': {
  app: {
    html: '<%= yeoman.app %>/index.html',
    ignorePath: '<%= yeoman.app %>/'
  }
}
EN

回答 1

Stack Overflow用户

发布于 2014-06-24 06:56:55

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

代码语言:javascript
复制
// 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}}" />'
        }
      }
    }
  }
},
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21860918

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档