I rely on grunt-contrib-concat for merging files and then use grunt-contrib-uglify to compress the resulting merged file.
Here is an example of my concatenation task:
concat : {
options : {
stripBanner : true
},
header : {
src : [header1.js, header2.js, header3.js],
dest : ['/path/to/js/tmpfolder/', '<%=pkg.name %>.header.js'].join('/')
},
application : {
src : [app1.js, app2.js, app3.js],
dest : ['/path/to/js/tmpfolder/', '<%=pkg.name %>.app.js'].join('/')
}
}
Similarly, my minification task looks like this:
uglify : {
all : {
options : {
banner : "/*! <%= pkg.name %> - v<%= pkg.version %> - <%= grunt.template.today(\"yyyy-mm-dd\") %> \n <%= pkg.author %> */",
dead_code : true
},
files : uglifyFiles
}
}
To make it work, I also have to define the `uglifyFiles` variable as follows:
uglifyFiles = {};
uglifyFiles['/path/to/js/tmpfolder/<%=pkg.name %>.header.min.js'] = '/path/to/js/tmpfolder/<%=pkg.name %>.header.js';
uglifyFiles['/path/to/js/tmpfolder/<%=pkg.name %>.app.min.js'] = '/path/to/js/tmpfolder/<%=pkg.name %>.app.js';