gpt4 book ai didi

javascript - 当 gulpfile 中不存在用户要求的任务时运行特定任务

转载 作者:行者123 更新时间:2023-11-30 21:03:17 25 4
gpt4 key购买 nike

当用户提供的任务不在 gulpfile 中时,是否有任何方法可以运行特定任务。

例如,如果用户运行 gulp buildbuild 任务不在 gulpfile 中,那么一个特定的任务(或默认任务,对我来说无关紧要)应该运行。

作为类比,将指定任务视为 gulp404 页面

最佳答案

gulp继承自 orchestrator ,其中包含一个 tasks 实例变量,它是一个普通对象,其键是添加到实例中的任务名称。如果您将 tasks 替换为 proxy ,您可以使用 get 陷阱处理程序让它返回一个默认任务,例如 default:

const gulp = require('gulp')

gulp.tasks = new Proxy(gulp.tasks, {
get (target, property) {
if (target.hasOwnProperty(property)) {
return target[property]
}

return target.default
}
})

即使在某些任务已经添加到 gulp 实例之后,该代码也可以在任务序列开始之前的任何时间运行。

关于javascript - 当 gulpfile 中不存在用户要求的任务时运行特定任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46894102/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com