我使用 Gulp 在非 JavaScript 项目中运行一个简单的任务。我正在尝试从 3.9.1 升级到 4.0,以摆脱“已弃用”和“安全”警告的泛滥。连同诸如切换到 gulp 4 的快速指南之类的文章,我已经在本地升级,删除gulp-util
并最终得到了这个package.json
:
{
"name": "redacted",
"main": "gulpfile.js",
"private": true,
"devDependencies": {
"ansi-colors": "^3.0.5",
"fancy-log": "^1.3.2",
"gulp": "^4.0.0",
"gulp-zip": "^4.2.0",
"temp": "^0.8.3"
}
}
但我不是 Node.js 专家,我显然遗漏了一些东西。我的旧式任务:
var gulp = require('gulp');
var log = require('fancy-log');
gulp.task('hi', function() {
log('Hello, World!');
});
… 扳机:
PS D:\Redacted> gulp hi
[10:25:58] Using gulpfile D:\Redacted\gulpfile.js
[10:25:58] Starting 'hi'...
[10:25:58] Hello, World!
[10:25:58] The following tasks did not complete: hi
[10:25:58] Did you forget to signal async completion?
如果我按照文章的建议注入gulp.series()
并删除匿名函数:
function hi() {
log('Hello, World!');
}
gulp.task('hi', gulp.series(hi));
…然后任务运行两次或其输出显示两次(不确定)但警告仍然存在:
PS D:\Redacted> gulp hi
[10:28:47] Using gulpfile D:\Redacted\gulpfile.js
[10:28:47] Starting 'hi'...
[10:28:47] Starting 'hi'...
[10:28:47] Hello, World!
[10:28:47] The following tasks did not complete: hi, hi
[10:28:47] Did you forget to signal async completion?
我错过了什么?有更好的升级指南吗?