簡體   English   中英

grunt-bower-install將bower_components鏈接到當前目錄

[英]grunt-bower-install links bower_components to current directory

我最近用Grunt和Bower開始了一個使用Yeoman Angular發生器的新項目。

每當grunt構建我的應用程序時,grunt-bower-install都會重新生成index.html文件中我的bower_components的所有鏈接。

無論出於何種原因,這些資產都鏈接到當前目錄而不是root,因此當我導航到一個深度超過一級的新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 %>/'
  }
}

我和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}}" />'
        }
      }
    }
  }
},

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM