【问题标题】:Multitask in GulpJSGulpJS 中的多任务
【发布时间】:2015-03-16 14:47:11
【问题描述】:

你们好吗?

如何在 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"]);
}

谢谢!

【问题讨论】:

    标签: node.js gruntjs gulp


    【解决方案1】:

    我相信您正在寻找的是,如何运行一系列任务。以下是你的做法:

    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

    【讨论】:

    • 不,我真的想运行单独的任务,但任务在另一个里面。我知道这很奇怪,但就是这样。 :S
    • 为每个组合创建一个任务,也可以使用提供常用选项的功能
    猜你喜欢
    • 1970-01-01
    • 2014-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-16
    • 2012-05-29
    相关资源
    最近更新 更多