如何使用 Grunt 丑化 subfolders/subdirectory 中的所有 javascript 文件?
How to uglify all javascript files in subfolders/subdirectory using Grunt?
我正在使用 Grunt 丑化我项目中的 javascipt 文件。
问题:
如何丑化 subfolders/subdirectory 中的所有 javascript 文件?
我在 Gruntfile.js 中所做的:
目前它只会丑化 js 文件夹中的那些 javascript 文件,因为我使用的是 src: 'js/*.js'。但是我在 js 文件夹中还有其他目录,其中包含 javascript 个文件:
├── 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' ]);
};
您可以使用 glob 模式,例如:src: '/**/*.js'
我正在使用 Grunt 丑化我项目中的 javascipt 文件。
问题:
如何丑化 subfolders/subdirectory 中的所有 javascript 文件?
我在 Gruntfile.js 中所做的:
目前它只会丑化 js 文件夹中的那些 javascript 文件,因为我使用的是 src: 'js/*.js'。但是我在 js 文件夹中还有其他目录,其中包含 javascript 个文件:
├── 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' ]);
};
您可以使用 glob 模式,例如:src: '/**/*.js'