2014-10-07 93 views
0

我想用grunt併發來並行地縮小我的JavaScript文件。我也使用usemin和ngmin。uglify與咕嚕併發不工作

當我使用醜化不咕嚕,同時我得到這個日誌輸出預期的結果:

Running "uglify:dist" (uglify) task 

Running "uglify:dist/scripts/jquery_and_angular.js" (uglify) task 
File dist/scripts/jquery_and_angular.js created. 

Running "uglify:dist/scripts/external-non-angular-libraries.js" (uglify) task 
File dist/scripts/external-non-angular-libraries.js created. 

Running "uglify:dist/scripts/modules.js" (uglify) task 
File dist/scripts/modules.js created. 

Running "uglify:dist/scripts/scripts.js" (uglify) task 
File dist/scripts/scripts.js created. 

但是當我嘗試使用咕嚕,同時通過這種結構來執行此任務:

concurrent: { 
     lessAndMinify: [ 
      'ngmin', 
      'less' 
     ], 
     uglify: [ 
      'uglify:dist/scripts/jquery_and_angular.js', 
      'uglify:dist/scripts/external-non-angular-libraries.js', 
      'uglify:dist/scripts/modules.js', 
      'uglify:dist/scripts/scripts.js', 
      'uglify:dist/scripts/templates.js' 
     ] 
    }, 

我得到這個任務沒有配置信息:

Running "concurrent:uglify" (concurrent) task 
Warning: Running "uglify:dist/scripts/jquery_and_angular.js" (uglify) task 
Verifying property uglify.dist/scripts/jquery_and_angular\.js exists in config...ERROR 
>> Unable to process task. 
Warning: Required config property "uglify.dist/scripts/jquery_and_angular\.js" missing. Use --force to continue. 

Aborted due to warnings. Used --force, continuing. 

Running "uglify:dist/scripts/jquery_and_angular.js" (uglify) task 
Verifying property uglify.dist/scripts/jquery_and_angular\.js exists in config...ERROR 
>> Unable to process task. 
Warning: Required config property "uglify.dist/scripts/jquery_and_angular\.js" missing. Use --force to continue. 

Aborted due to warnings. 
    Warning: Running "uglify:dist/scripts/modules.js" (uglify) task 
Verifying property uglify.dist/scripts/modules\.js exists in config...ERROR 
>> Unable to process task. 
Warning: Required config property "uglify.dist/scripts/modules\.js" missing. Use --force to continue. 

Aborted due to warnings. Used --force, continuing. 

Running "uglify:dist/scripts/modules.js" (uglify) task 
Verifying property uglify.dist/scripts/modules\.js exists in config...ERROR 
>> Unable to process task. 
Warning: Required config property "uglify.dist/scripts/modules\.js" missing. Use --force to continue. 

我生成任務配置IST這樣的:

grunt.registerTask('build', [ 
    'clean:dist', 
    'ngtemplates', 
    'copy:indexHtml', 
    'replace', 
    'useminPrepare', 
    'concat', 
    'copy:dist', 
    'copy:generated', 
    'concurrent:lessAndMinify', // ngmin and less 
// 'concurrent:uglify', 
    'uglify', 
    'rev', 
    'usemin' 
]); 

的問題是,如何才能讓使用咕嚕,同時與醜化和usemin/ngmin的?

回答

0

usemin在任務中將任務添加到uglify,但它們出於任何原因在grunt-concurrent中不可見。 爲了解決這個問題,你必須手動添加文件到醜化:

uglify: { 
     dist: { 
      options: { 
       sourceMap: true 
      }, 
      files: { 
      } 
     }, 

     // you have to add this manually! 
     "dist/scripts/jquery_and_angular.js": "dist/scripts/jquery_and_angular.js", 
     "dist/scripts/external-non-angular-libraries.js": "dist/scripts/external-non-angular-libraries.js", 
     "dist/scripts/modules.js": "dist/scripts/modules.js", 
     "dist/scripts/scripts.js": "dist/scripts/scripts.js", 
     "dist/scripts/templates.js": "dist/scripts/templates.js" 
    }, 

的問題是,這是不幹燥。你必須在index.html,grunt-concurrent和uglify中配置它。