Angularjs   发布时间:2022-04-20  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了angularjs – 在yeoman角度应用程序中使用bower时,我可以更改渲染的路径吗?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我在我的角度应用程序中使用 @L_250_0@mode,但是当我使用grunt运行bower install时,它将路径呈现为

< script src =“bower_components / ... 我可以改成这个吗? < script src =“/ bower_components / ...? 我添加了< base href =“/”>标记到我的< head />部分,但当我的网页尝试加载JavaScript时,他们仍然在寻找相对的网址.

因此对于/bower_components/script.js中的脚本,当前呈现为
< script src =“bower_components / script.js”>< / script>,

当打开/登录时,页面尝试加载/login/bower_components/script.js

编辑
按照@ sharpper的建议,我在下面添加代码块,最后在Gruntfile.js中使用了它:

// Automatically inject Bower components into the app
'bower-install': {
  app: {
    html: '<%= yeoman.app %>/index.html',ignorePath: '<%= yeoman.app %>/',fileTypes: {
      html: {
        block: /(([\s\t]*)<!--\s*bower:*(\S*)\s*-->)(\n|\r|.)*?(<!--\s*endbower\s*-->)/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: /(([\s\t]*)#\s*bower:*(\S*)\s*)(\n|\r|.)*?(#\s*endbower\s*)/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%>‘,然后它应该适用于您的目的.

大佬总结

以上是大佬教程为你收集整理的angularjs – 在yeoman角度应用程序中使用bower时,我可以更改渲染的路径吗?全部内容,希望文章能够帮你解决angularjs – 在yeoman角度应用程序中使用bower时,我可以更改渲染的路径吗?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。