angularjs – 在yeoman角度应用程序中使用bower时,我可以更改渲
我在我的角度应用程序中使用
html5mode,但是当我使用grunt运行bower install时,它将路径呈现为
< script src =“bower_components / ... 我可以改成这个吗? < script src =“/ bower_components / ...? 我添加了< base href =“/”>标记到我的< head />部分,但当我的网页尝试加载JavaScript时,他们仍然在寻找相对的网址. 因此对于/bower_components/script.js中的脚本,当前呈现为 当打开/登录时,页面尝试加载/login/bower_components/script.js 编辑 // Automatically inject Bower components into the app 'bower-install': { app: { html: '<%= yeoman.app %>/index.html',ignorePath: '<%= yeoman.app %>/',fileTypes: { html: { block: /(([st]*)<!--s*bower:*(S*)s*-->)(n|r|.)*?(<!--s*endbowers*-->)/gi,detect: { js: /<script.*src=['"](.+)['"]>/gi,css: /<link.*href=['"](.+)['"]/gi },replace: { js: '<script src="/{{filePath}}"></script>',// <-- Change this line css: '<link rel="/stylesheet" href="{{filePath}}" />' } },yml: { block: /(([st]*)#s*bower:*(S*)s*)(n|r|.)*?(#s*endbowers*)/gi,detect: { js: /-s(.+)/gi,css: /-s(.+)/gi },replace: { js: '- {{filePath}}',css: '- {{filePath}}' } } } } }, 它仍然可以正确编译,但文件呈现方式相同. 解决方法
首先,确保你的bower-install在最新版本:v0.8.0(yeoman当前正在使用v0.7.0),然后下面的代码应该工作:
'bower-install': { app: { src: ['<%= yeoman.app %>/index.html'],fileTypes: { html: { replace: { js: '<script src="/{{filePath}}"></script>',css: '<link rel="stylesheet" href="/{{filePath}}" />' } } } } } 如果您不想更新或此方法不起作用,请尝试以下方法:???????将ignorePath:’<%= yeoman.app%> /’更改为ignorePath:’<%= yeoman.app%>‘,然后它应该适用于您的目的. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |