我最近与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 %>/'
}
}发布于 2014-06-24 06:56:55
我在YO1.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}}" />'
}
}
}
}
},https://stackoverflow.com/questions/21860918
复制相似问题