問題描述
是否可以有一個主要的 gulpfile.js 來調用其他 gulp files.js 的任務?將子 gulpfile.js 簡單地要求"到主文件中是行不通的.我有一個平臺項目,其中包括幾個帶有單獨 gulpfile 的子項目,所以我需要一個解決方案來管理主要項目中的所有子 gulpfile
Is it possible to have one main gulpfile.js from which to call tasks from other gulp files.js? Simple "require" of child gulpfile.js into main one doesn't work. I have a platform project which includes several sub projects with separate gulpfiles, so I need a solution to manage all child gulpfiles from within main one
推薦答案
如果我想讓它面向未來并且不想安裝怎么辦另一個包.
And what if I want to make it future-proof and don't want to install another package for it.
以下內容適用于 gulp 4,沒有任何額外的插件.
The following works for me with gulp 4, without any extra plugins.
在taskfile.js
中:
const { src, dest } = require('gulp');
const mytask = function () {
return src('assets/**/*')
.pipe(dosomething())
.pipe(dest('dest');
}
module.exports = {
mytask
}
在 gulpfile.js
中:
const { mytask } = require('taskfile.js');
// use in other tasks
gulp.task('manythings', gulp.series(..., mytask, ...));
// or use directly as 'gulp mytask'
module.exports = {
mytask
}
這篇關于如何從另一個 gulp file.js 導入所有任務的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!