要使代码按您所描述的那样工作,则需要将回调函数作为参数传递给.series()
。例如:
Gulp.task('clean',function () {
console.log('Clean');
return Gulp.src("./dbSchema/*")
.pipe(VinylPaths(Del));
})
Gulp.task('copy:db',Gulp.series(clean,function () {
console.log('Copy DB');
return Gulp.src("./db/*")
.pipe(Gulp.dest("./dbSchema"));
}))
Gulp.task('default',Gulp.series(copy:db,function () {
console.log('defaulp');
return TypeScriptProject.src()
.pipe(TypeScriptProject())
.js.pipe(Gulp.dest('dist'));
}));
恕我直言,拥有三个完全独立的任务会更简单:
Gulp.task('clean',function () {
console.log('Clean');
return Gulp.src("./dbSchema/*")
.pipe(VinylPaths(Del));
});
Gulp.task('copy:db',function () {
console.log('Copy DB');
return Gulp.src("./db/*")
.pipe(Gulp.dest("./dbSchema"));
});
Gulp.task('default',function () {
console.log('defaulp');
return TypeScriptProject.src()
.pipe(TypeScriptProject())
.js.pipe(Gulp.dest('dist'));
});
,然后使用以下任一方法呼叫他们:
Gulp.task('default',gulp.series(clean,copy:db,js));
或
Gulp.task('default',gulp.parallel(copy:db,js)));
希望有帮助:)
附加说明:
-
gulp / vars的命名约定通常为camelCase,例如:gulp
和typeScriptProject
而非Gulp
或TypeScriptProject
。
-
您可以使用gulp.
完全消除编写var {gulp,task,src,dest,watch,series,parallel} = require('gulp');
的麻烦。
-
与其直接定义任务,不如使用CommonJS exports
模块表示法声明任务来使代码更易于阅读。
-
如果您在使用引号时保持一致,则可以使生活更轻松一些,而不是混合使用单打和双打。两者都允许
遵循Gulp自己的文档也许是一个起点,their sample code on github提供了一些设置基本gulpfile的好例子。
如果将所有内容都打包,就会得到:
/*
* Example of requires with gulp methods also requiring gulp.
*/
var {
gulp,parallel,watch
} = require('gulp'),vinylPaths = require('vinyl-paths'),// may not be required,see note in clean func.
del = require('del'),ts = require('gulp-typescript');
/*
* Added a basic TypeScript Project so the example is complete and could run.
*/
var typeScriptProject = ts.createProject({
declaration: true
});
/*
* Your tasks converted to plain/standard js functions.
*/
function clean () {
return src('dbSchema/*')
.pipe(vinylPaths(del));
// Looking at your example code the vinylPaths is redundant,// as long as you’re using del ^2.0 it will return its promise,// so you could replace the above with:
return del([ 'dbSchema' ]);
}
function copyDb () {
return src('db/*')
.pipe(dest('dbSchema'));
}
function scripts () {
// example src path
return src('lib/*.ts')
.pipe(typeScriptProject())
.pipe(dest('dist'));
}
/*
* By defining all the tasks separately it makes it really clear how the tasks will run.
*/
var build = gulp.series (
clean,gulp.parallel (
copyDb,scripts
)
);
/*
* Example of using `exports` module notation to declare tasks.
*/
exports.clean = clean;
exports.copyDb = copyDb;
exports.scripts = scripts;
exports.build = build;
/*
* Good practise to define the default task as a reference to another task.
*/
exports.default = build;
本文链接:https://www.f2er.com/3154140.html