2015-04-23 33 views
1

我爲我的一個項目使用angular-fullstack yeoman生成器,如果我運行grunt生成,我的index.html被grunt-injector發現的注入依賴項覆蓋。問題是我想指定以特定順序加載某些模塊,或者我只想忽略特定的文件夾。我怎樣才能做到這一點?目前一些javaScript文件的加載順序錯誤,每次運行grunt build時都會出現錯誤。Grunt在index.html中指定注入文件的順序

回答

3

你可以使用數組來指定順序,例如

// Inject application script files into index.html 
 
scriptsVendor: { 
 
    options: { 
 
     transform: function(filePath) { 
 
     filePath = filePath.replace('/app/', ''); 
 
     return '<script src="' + filePath + '"></script>'; 
 
     }, 
 
     starttag: '<!-- injector:js -->', 
 
     endtag: '<!-- endinjector -->' 
 
    }, 
 
    files: { 
 
     'app/index.html': [ 
 
     [ 
 
      'app/lib/js/jquery.js', 
 
      'app/lib/js/bootstrap.js', 
 
      'app/lib/js/angular.js' 
 
     ], 
 
     [ 
 
      'app/lib/js/angular-*.js', 
 
      'app/lib/js/ui-*.js' 
 
     ] 
 
     } 
 
    }

所以我jquery然後bootstrapangular之前加載。在下一個塊中,所有以angular-ui-開頭的角度模塊。

忽略某些文件或文件夾

!app/lib/js/*.min.js 
!app/lib/js/folder_to_ignore/*.js 

即使有點晚了,我希望它可以幫助:-)

在我的情況
0

我有幾個角模塊,以配置和運行功能,在分隔三個文件名爲xyz.module.js,xyz.config.js,xyz.run.js

Gulp搜索所有.js文件:「**/*。js」和注入時使用的字母順序,因此* .module.js在* .config.js之後加載,它提供了有關缺少xyz模塊定義的錯誤。

所以順序應該切換。我不想使用硬編碼數組,我想繼續使用通配符。

解決這確實是在我的情況: https://ww

使用(在gulpfile):

var angularFilesort = require('gulp-angular-filesort'); 
gulp.src(['./src/app/**/*.js']).pipe(angularFilesort()) 
相關問題