Trying to do this with Grunt. I have a file structure like this:
/app
--app.js
--/module1
----module1.js
----module1Model.js
--/module2
----module2.js
----module2Model.js
How can I concatenate & minify each module into one file so it looks like:
/app
--app.min.js
--module1.min.js
--module2.min.js
We want this to be scalable so when we add module3, 4 it'll still work. Thank you for your help!
you can use uglify for solution and "dist" and "src" can be changed according to use:
uglify:{
liveproject:{
files:{
'dist/js/main.min.js' : ['src/js/*.js'],
'dist/js/m1.min.js' : ['src/js/easing.js','src/js/modernizer.js'],
}
}
},
I derived my answer from this post: Using grunt to concat many files from many dirs into single renamed file in new directory
grunt.registerTask('prepareModule', 'process dist module for concat', function() {
//get configured concat task object
var concat = grunt.config.get('concat') || {};
//iterate through all file/folders at build/src/app/
grunt.file.expand(grunt.config('build_dir') + '/src/app/*').forEach(function(dir) {
//grab the last path name
var dirName = dir.substr(dir.lastIndexOf('/') + 1);
//filter for folders only
if (dirName.slice(-3) !== '.js') {
//add target for each module
concat[dirName] = {
src: [grunt.config('build_dir') + '/src/app/' + dirName + '/*.js'],
dest: grunt.config('dist_dir') + '/src/app/' + dirName + '/' + dirName + '.js'
};
}
});
grunt.config.set('concat', concat);
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.