自耕农建造过程

时间:2012-11-06 19:53:34

标签: gruntjs yeoman

所以我现在正在使用我非常喜欢的Yeoman。我有一个任务要抓住我的角度应用程序并使其无服务器。基本上这意味着抓取所有模板并使用

将它们插入到index.html文件中
<script type="text/ng-template" id="dir to template"> ..template html goes here </script>

现在自己有了自己的grunt文件,我完全是Grunt的新手,所以我想知道是否
a)这应该是由grunt处理的任务?
b)我应该调整现有的grunt文件还是创建一个新文件? c)我在哪里可以找到关于如何做到这一点的文件的任何好主意?

谢谢!

2 个答案:

答案 0 :(得分:11)

我们正在努力使Yeoman更容易定制,但与此同时,你可以通过在Gruntfile中添加这个来覆盖build任务:

grunt.renameTask('build', 'oldbuild');
grunt.registerTask('build', 'your-task oldbuild');

这将允许您向构建过程添加任何您想要的任务。


如果您想进一步自定义,可以覆盖build,只需将自己想要的内容拼凑成自己提供的任务:usemin-handler rjs concat css min img rev usemin manifest html

示例:

grunt.registerTask('build', 'your-task rjs concat css whatever-you-want');

答案 1 :(得分:0)

目前无法自定义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来源复制,如果更新,您必须自己做。