我正在使用 grunt usemin 来优化我的 css 和 js 文件。我想为 css 文件定制 concat:generated 任务,而不是 js 文件。但是我注意到即使我在 post 对象中指定了 css 键,生成的配置也会使用相同的选项来完成此任务:
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']);
};
生成的concat任务是
concat: {
generated: {
files: [
{
dest: 'path to optimized css',
src: [ 'css files...' ]
},
{
dest: 'path to optimized js',
src: [ 'js files...' ]
}
],
options: { process: [Function] }
}
}
有没有办法实现这个?谢谢