2016-09-02 19 views
0

我正在使用Grunt來醜化我的項目中的javascipt文件。如何uglify使用Grunt的子文件夾/子目錄中的所有javascript文件?

問:

如何醜化子文件夾/子目錄中的所有JavaScript文件?

我在Gruntfile.js做什麼:

目前,它只會醜化那些因爲我使用的src中的js文件夾中的JavaScript文件: 'JS/* JS'。不過,我有在具有JavaScript文件夾的js其他目錄:

├── CommonUtil.js 
├── Paging 
│   ├── dirPagination.js 
│   └── dirPagination.tpl.html 
├── angular-chart.js 
├── angular-elastic-input.min.js 
├── angularAlt.js 
├── authenticationChallengeHandler 
│   └── loginChallengeHandler.js 

Gruntfile.js

module.exports = function (grunt) { 
    grunt.initConfig({ 
     // define source files and their destinations 
     uglify: { 
      files: { 
       src: 'js/*.js', // source files mask 
       dest: 'jsm/', // destination folder 
       expand: true, // allow dynamic building 
       flatten: true, // remove all unnecessary nesting 
       ext: '.min.js' // replace .js to .min.js 
      } 
     }, 
     watch: { 
      js: { files: 'js/*.js', tasks: [ 'uglify' ] }, 
     } 
    }); 

// load plugins 
grunt.loadNpmTasks('grunt-contrib-watch'); 
grunt.loadNpmTasks('grunt-contrib-uglify'); 

// register at least this one task 
grunt.registerTask('default', [ 'uglify' ]); 


}; 
+1

或許這將告訴您如何? http://stackoverflow.com/questions/19138329/grunt-recursive-copy – mplungjan

+0

@mplungjan thx! – user1872384

回答

1

您可以使用glob模式,如:src: '/**/*.js'

+0

Thx for replying ..我用scr修改了我的Guntfile.js:'**/*。js'但是,我在終端中運行grunt後遇到了這個錯誤。 JS_Parse_Error { 消息: '語法錯誤:意外標記:PUNC(。)',文件名 :」 ../*.js', 行:1, 西:0, POS:0, 堆棧: – user1872384

+1

需要提到一個根文件夾。你可以像上面提到的那樣嘗試'/ **/*。js'嗎? – nikjohn

+0

重擊:致命錯誤:CALL_AND_RETRY_LAST分配失敗 - JavaScript堆內存不足,但我認爲你的回答應該工作... – user1872384

相關問題