2016-09-02 20 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

相关问题