2014-02-18 35 views
1

我最近使用帶Grunt和Bower的Yeoman Angular發生器啓動了一個新項目。grunt-bower-install將bower_components鏈接到當前目錄

每當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 %>/' 
    } 
} 
+1

[Grunt不斷刪除我的絕對路徑]的可能重複(http://stackoverflow.com/questions/21722097/grunt-keeps-removing-my-absolute-paths) – Stephen

回答

3

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