GulpJS中的多任务

时间:2015-03-16 14:47:11

标签: node.js gruntjs gulp

你们好吗?

如何在GulpJS中创建类似于在GruntJS中创建的任务? 有可能吗?

示例:

module.exports = function(grunt) {
    "use strict"

    grunt.initConfig({

        uglify: {
            options: {
                manage: false
            },
            dev: {...},
            prod: {...}
        },

        less: {
            options: {
                cleancss: true
            },
            dev: {...},
            prod: {...}
        }

    });

    grunt.registerTask("dev", ["uglify:dev", "less:dev"]);
    grunt.registerTask("prod", ["less:prod", "less:prod"]);
}

谢谢!

1 个答案:

答案 0 :(得分:0)

我相信你要找的是,如何在一系列中运行任务。以下是您将如何做到这一点:

var gulp = require('gulp');

// takes in a callback so the engine knows when it'll be done
gulp.task('one', function(cb) {
    // do stuff -- async or otherwise
    cb(err); // if err is not null and not undefined, the orchestration will stop, and 'two' will not run
});

// identifies a dependent task must be complete before this one begins
gulp.task('two', ['one'], function() {
    // task 'one' is done now
});

gulp.task('default', ['one', 'two']);
// alternatively: gulp.task('default', ['two']);

您可以在此处详细了解:https://github.com/gulpjs/gulp/blob/master/docs/recipes/running-tasks-in-series.md