目前无法自定义 yeoman 构建过程。但是您可以使用此解决方法。将以下代码复制到您自己的 Gruntfile 中:
// Clobber the original targets
var targets = {
// Add as many custom targets as you want, using custom modules, etc.
// Keep the existing targets
default : ' rjs concat css min img rev usemin manifest',
usemin : 'usemin-handler rjs concat css img rev usemin manifest',
text : 'usemin-handler rjs concat css min rev usemin manifest',
buildkit : 'usemin-handler rjs concat css min img rev usemin manifest html:buildkit',
basics : 'usemin-handler rjs concat css min img rev usemin manifest html:basics',
minify : 'usemin-handler rjs concat css min img rev usemin manifest html:compress',
test : 'usemin-handler rjs concat css img rev usemin manifest',
yourbuild : 'intro clean mkdirs rjs'
};
// If we clobber targets, we have to rebuild targetList, the below is copy paster from Yeoman.js
var targetList = grunt.log.wordlist(Object.keys(targets));
// We also have to rebuild the build task with the new targetList
grunt.registerTask('build', 'Run a predefined target - build:<target> \n' + targetList, function(target) {
var valid = Object.keys(targets);
target = target || 'usemin';
if ( valid.indexOf( target ) === -1 ) {
grunt.log
.error('Not a valid target')
.error(grunt.helper('invalid targets', targets));
return false;
}
var tasks = ['intro', 'clean coffee compass mkdirs', targets[target], 'copy time'].join(' ');
// Now overwrite the task for our costume build
if( target === 'yourbuild') {
tasks = targets[target];
}
// Conditionally remove compass / manifest task if either compass or
// phantomjs binary is missing. Done only for `test` target (specifically
// used for our `npm test`). For each, output warning infos.
if( target === 'test' ) {
tasks = grunt.helper( 'build:skip', tasks, 'compass' );
tasks = grunt.helper( 'build:skip', tasks, 'phantomjs', 'manifest' );
}
grunt.log.subhead('Running ' + target + ' target')
.writeln(' - ' + grunt.log.wordlist(tasks.split(' '), { separator: ' ' }));
grunt.task.run(tasks);
});
现在您可以更改以下行来自定义您自己的构建过程:
yourbuild : 'intro clean mkdirs rjs'
但请记住,此代码是从 yeoman 源复制的,如果更新,您必须自己执行相同操作。