2

我有一個討厭的問題,其中uglify(通過grunt-usemin調用)無法解析名爲flow.js的包的url。該軟件包作爲ng-flow的依賴來安裝。Uglify無法解析「flow.js」

的URL看起來是這樣的:

bower_components/flow.js/dist/flow.js 

當我運行咕嚕的身材,我得到以下錯誤:

Warning: Unable to read "dist/public/bower_components/flow.js" file (Error code: EISDIR). Use --force to continue. 

因爲我不知道很多關於usemin和醜化,我可以不要把我的手指放在這個問題上。我的猜測是,當它到達url的第一個「flow.js」時,它會中斷。所以,我試圖在我的bower.json中將flow.js安裝爲flowjs,但由於它是ng-flow的依賴關係,所以在運行bower更新時它仍然會得到flow.js。

任何人都可以告訴我有關此錯誤的更多信息,或者建議我使用一種解決方法來重命名依賴包?

編輯:中,使用https://github.com/DaftMonk/generator-angular-fullstack

+0

Gruntfile的相關部分是什麼樣子的? – doelleri 2015-02-10 22:00:52

回答

3

問題產生的咕嚕文件的Gruntfile

useminPrepare: { 
    html: ['<%= yeoman.client %>/index.html'], 
    options: { 
    dest: '<%= yeoman.dist %>/public' 
    } 
}, 
usemin: { 
    html: ['<%= yeoman.dist %>/public/{,*/}*.html'], 
    css: ['<%= yeoman.dist %>/public/{,*/}*.css'], 
    js: ['<%= yeoman.dist %>/public/**/*.js'], 
    options: { 
    assetsDirs: [ 
     '<%= yeoman.dist %>/public', 
     '<%= yeoman.dist %>/public/assets/images' 
    ], 
    // This is so we update image references in our ng-templates 
    patterns: { 
     js: [ 
     [/(assets\/images\/.*?\.(?:gif|jpeg|jpg|png|webp|svg))/gm, 'Update the JS to reference our revved images'] 
     ] 
    } 
    } 
} 
grunt.registerTask('build', [ 
'clean:dist', 
'injector:less', 
'concurrent:dist', 
'injector', 
'wiredep', 
'useminPrepare', 
'autoprefixer', 
'ngtemplates', 
'concat', 
'ngAnnotate', 
'copy:dist', 
'cdnify', 
'cssmin', 
'uglify', 
'rev', 
'usemin']); 

對於記錄usemin部分是步兵不能在」的.js結尾的目錄之間進行區分'和一個.js文件。

解決方法是使用通配符表達式來獲取flow.js中的文件並排除目錄本身。

編輯:您將需要從usemin和rev中排除flow.js。

usemin: { 
    html: ['<%= yeoman.dist %>/public/{,*/}*.html'], 
    css: ['<%= yeoman.dist %>/public/{,*/}*.css'], 
    js: { 
    src: ['<%= yeoman.dist %>/public/{,*/}*.js', '!<%= yeoman.dist %>/public/bower_components/flow.js'], 
    }, 
    ... 

rev: { 
    dist: { 
    files: { 
     src: [ 
     '<%= yeoman.dist %>/public/{,*/}*.js', 
     '<%= yeoman.dist %>/public/{,*/}*.css', 
     '<%= yeoman.dist %>/public/assets/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}', 
     '<%= yeoman.dist %>/public/assets/fonts/*', 
     '!<%= yeoman.dist %>/public/bower_components/flow.js' 
     ] 
    } 
    } 
}, 
+0

不幸的是,它仍然試圖包括文件夾和崩潰:(。(我試圖改變順序,但它沒有任何影響) – user3220633 2015-02-10 22:15:06

+0

看到更新的答案。你需要排除usemin和rev。 – doelleri 2015-02-10 22:38:36

+0

是的!從現在開始,我會給你打電話Grandmaster! – user3220633 2015-02-10 22:46:26

0

The problem is that Grunt can't distinguish between a directory ending in '.js' and a .js file.

這是一個錯誤的說法。 Grunt使用minimatch lib來配置如何搜索文件,並且有一個isFile篩選器,您可以將其設置爲true以僅搜索文件。 See grunt.file.expand

正在關注this link您會找到一個filter: 'isFile'的示例。

通過你應該升級到usemin V3,因爲這個問題似乎得到解決,你可以在issue #474

看你看我的補丁here在那裏我已經遷移項目usemin 3和開關咕嚕的方式-rev to grunt-filerev。

+0

謝謝你提供這個信息,我指出了這個角度滿塔的傢伙! – user3220633 2015-02-25 17:43:39