[英]Can I pass arguments to a gulp task?
我在Visual Studio中仅使用gulp作为客户端构建工具。
我有很多任务在各个项目中通用,因此我将它们移到单独的文件中,并在项目的gulpfile.js
引用它们,如下所示:
require("../path/to/task/files/fooCommon.js"); // has a task called "fooCommon"
然后在gulpfile.js
包装在一个任务中:
gulp.task("foo", ["fooCommon"], function () { });
这很好用,我可以在项目中重用常见任务。
但是,某些任务需要只能在gulpfile.js
访问的gulpfile.js
- 如何将它们作为参数传递给任务?
我想到两件事。 第一是,与其fooCommon.js
创建任务,它可以创建可用的东西gulp
插件,所以然后使用它,你只是通过你的配置参数插件。 如果在这种情况下不合适,则可以将任务逻辑移到包装函数中,例如
module.exports = function(gulp, config){
gulp.task("fooCommon", function () {
// Use the config here
});
};
// Define whatever config you need
var gulp = require('gulp');
var config = {...}
var taskCreator = require('../path/to/task/files/fooCommon.js');
// Call the function in 'fooCommon.js', which will be passed the config, and
// will create all the tasks you have in common.
taskCreator(gulp, config);
// Register a task depending on the task created by the exported function.
gulp.task("foo", ["fooCommon"], function () { });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.