我有任务要在生产中缩小JS文件
function scriptsToMinify() {
if(require('yargs').argv.production)
{
return gulp.src(src.JSFile)
.pipe(sourcemaps.init())
.pipe(ngAnnotate(
{
remove: true,
add: true,
single_quotes: true
}))
.pipe(concat('app.min.js'))
.pipe(uglify())
.on('error', function (err) { gutil.log(gutil.colors.red('[Error]'), err.toString()); })
.pipe(sourcemaps.write())
.pipe(gulp.dest('public'));
}
}
当我在本地运行时,它不运行依赖任务
gulp.task('inject-scripts', gulp.series(scriptsToMinify, function() {
var thridPartyScripts = gulp.src(src.thirdPartyJS, { read: false })
var scripts = gulp.src([src.app_js, src.directiveJS], { read: false })
return gulp.src('views/index.html')
.pipe(inject(series(thridPartyScripts, scripts))) // Inject files in an order to run the application without any dependency error.
.pipe(cachebust({ // Add the timestamp to the injected files to avoid cache issue
type: 'timestamp'
}))
.pipe(gulp.dest('views'));
});
以上任务使我陷入错误。
The following tasks did not complete: default, inject-scripts, scriptsToMinify
Did you forget to signal async completion?
答案 0 :(得分:1)
将您的scriptsToMinify任务更改为
function scriptsToMinify(done) {
if(require('yargs').argv.production)
{
return gulp.src(src.JSFile)
.pipe(sourcemaps.init())
.pipe(ngAnnotate(
{
remove: true,
add: true,
single_quotes: true
}))
.pipe(concat('app.min.js'))
.pipe(uglify())
.on('error', function (err) { gutil.log(gutil.colors.red('[Error]'), err.toString()); })
.pipe(sourcemaps.write())
.pipe(gulp.dest('public'));
}
else{
done();
}
}
您必须在任务完成后返回信号,所以您必须传递回调。