I'm using grunt usemin to optimize my css and js files. I want to customize concat:generated task for css files only, not js files. But i noticed that the generated config uses the same options for this task even if i specify css key in the post object :
module.exports = function(grunt) {
require('load-grunt-tasks')(grunt);
grunt.initConfig({
copy: {
ejs: {
src: 'index.html',
dest: 'index.prod.html'
}
},
useminPrepare: {
html: 'index.html',
options: {
dest: 'static',
root: 'static',
flow: {
steps: {
'js': ['concat', 'uglifyjs'],
'css': ['concat', 'cssmin']
},
post: {
js: [{
name: 'uglify',
createConfig: function (context, block) {
// console.log('\ncontext:\n',context,'\nblock:\n',block);
context.options.generated.options = {
// options for uglify:generated task
};
}
}],
css: [{
name: 'concat',
createConfig: function (context, block) {
// console.log('\ncontext:\n',context,'\nblock:\n',block);
context.options.generated.options = {
process: function (src, filepath) {
// options for concat:generatedCSS
console.log('\nfilepath: ', filepath);
return src;
}
};
}
}]
}
}
}
},
usemin: {
html: [ 'index.prod.html' ]
}
});
grunt.registerTask('default', ['watch']);
grunt.registerTask('min', ['copy', 'useminPrepare', 'concat', 'uglify', 'usemin']);
};
The generated concat task is
concat: {
generated: {
files: [
{
dest: 'path to optimized css',
src: [ 'css files...' ]
},
{
dest: 'path to optimized js',
src: [ 'js files...' ]
}
],
options: { process: [Function] }
}
}
Is there a way to implement this? Thanks
Unfortunately usemin does not support your scenario. But you can do it as a trick:
For example if I want to concat only JS files by the
;
separator, I can do this:concat configuration for both CSS/JS
remove all
;
separators - wrong in CSS filesHope this help