起初我认为这与任务的依赖性有关,所以我选择了run-sequence,甚至尝试在任务中定义依赖关系。但我无法在compress
之后运行copy
任务。或者,即使它说它确实完成了压缩任务,压缩只有在我自己在visual studio内的任务运行器中运行compress时才有效。我还可以尝试在复制后进行压缩吗?
/// <binding BeforeBuild='default' />
/*
This file is the main entry point for defining Gulp tasks and using Gulp plugins.
Click here to learn more. https://go.microsoft.com/fwlink/?LinkId=518007
*/
var gulp = require("gulp");
var debug = require("gulp-debug");
var del = require("del");
var uglify = require("gulp-uglify");
var pump = require("pump");
var runSequence = require("run-sequence");
var paths = {
bower: "./bower_components/",
lib: "./Lib/"
};
var modules = {
"store-js": ["store-js/dist/store.legacy.js"],
"bootstrap-select": [
"bootstrap-select/dist/css/bootstrap-select.css",
"bootstrap-select/dist/js/bootstrap-select.js",
"bootstrap-select/dist/js/i18n/*.min.js"
]
}
gulp.task("default", function (cb) {
runSequence("clean", ["copy", "compress"], cb);
});
gulp.task("clean",
function () {
return del.sync(["Lib/**", "!Lib", "!Lib/ReadMe.md"]);
});
gulp.task("compress",
function (cb) {
pump([
gulp.src(paths.lib + "**/*.js"),
uglify(),
gulp.dest(paths.lib)
], cb);
});
gulp.task("copy",
function (cb) {
prefixPathToModules();
copyModules();
cb();
});
function prefixPathToModules() {
for (var moduleIndex in modules) {
for (var fileIndex in modules[moduleIndex]) {
modules[moduleIndex][fileIndex] = paths.bower + modules[moduleIndex][fileIndex];
}
}
}
function copyModules() {
for (var files in modules) {
gulp.src(modules[files], { base: paths.bower })
.pipe(gulp.dest(paths.lib));
}
}
答案 0 :(得分:0)
我不熟悉runSequence。但是你为什么不试试以下。通过这种方式,您的默认任务取决于压缩和压缩取决于副本。因此,'copy'将首先运行,然后'压缩'
gulp.task('default', ['copy','compress'], function(cb){});
gulp.task('compress',['copy'], function(cb){});
Gulp返回一个steam,因为你在for循环中调用它,所以在第一次迭代过程中会返回流。
将copyModule更新为以下内容,您可以尝试使用像Kirill发布的runSequence或按照我的方法
function copyModules() {
var inputFileArr = [];
for (var files in modules) {
inputFileArr = inputFileArr.concat(modules[files]);
};
return gulp.src(inputFileArr, { base: paths.bower })
.pipe(gulp.dest(paths.lib));
}
答案 1 :(得分:0)
您使用run-sequence和您的代码
runSequence("clean", ["copy", "compress"], cb);
按此顺序运行
这样写,压缩将在复制后
runSequence("clean", "copy", "compress", cb);