在运行具有依赖项(顺序和并行)的任务时,我在命令行上遇到gulp
问题。这可能是我的环境所特有的,我需要帮助才能看到或者如何使它变得更加冗长。
会发生什么:
我跑gulp bundle
它开始了:
Starting 'build'
Starting 'unbundle'
Finished 'unbundle' after 11ms
Starting 'clean'
然后我回到我的命令提示符。没有错误消息,退出代码甚至是0
。
然后我再次运行它:gulp bundle
Starting 'build'
Starting 'unbundle'
Finished 'unbundle'
Starting 'clean'
Finished 'clean'
Starting 'build-system'
Starting 'build-html'
Starting 'build-css'
Starting 'build-style'
Starting 'build-locales'
Finished 'build-css'
Finished 'build-locales'
Finished 'build-style'
Finished 'build-html'
Finished 'build-system'
Finished 'build'
Starting 'bundle'
Finished 'bundle'
这次它奏效了。我想再次做gulp bundle
我必须再次运行两次。
还有其他涉及更多依赖项的任务,我必须在它运行之前输入相同的命令 4x 。
每次退出代码0.即使使用标记-LLLL
,我也没有得到任何结果。 Gulp版本是3.9.1。
我从不同的文件中收集了所有受影响的任务,并结合了他们的要求。
var gulp = require('gulp');
var runSequence = require('run-sequence');
var changed = require('gulp-changed');
var plumber = require('gulp-plumber');
var sourcemaps = require('gulp-sourcemaps');
var paths = require('../paths');
var assign = Object.assign || require('object.assign');
var notify = require('gulp-notify');
var typescript = require('gulp-tsb');
var exec = require('child_process').exec;
var print = require('gulp-print');
var sass = require('gulp-sass');
var autoprefixer = require('gulp-autoprefixer');
var vinylPaths = require('vinyl-paths');
var del = require('del');
var bundler = require('aurelia-bundler');
var bundles = require('../bundles.js');
var sassOptions = {
outputStyle: 'expanded'
};
var autoPrefixerOptions = {
browsers: ['last 2 versions', '> 1%']
};
var typescriptCompiler = typescriptCompiler || null;
gulp.task('build-system', function() {
if(!typescriptCompiler) {
typescriptCompiler = typescript.create(require('../../tsconfig.json').compilerOptions);
}
return gulp.src(paths.dtsSrc.concat(paths.source))
.pipe(plumber())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(typescriptCompiler())
.pipe(sourcemaps.write('.', {includeContent: false, sourceRoot: '/src'}))
.pipe(gulp.dest(paths.output));
});
gulp.task('build-html', function() {
return gulp.src(paths.html)
.pipe(changed(paths.output, {extension: '.html'}))
.pipe(gulp.dest(paths.output));
});
gulp.task('build-css', function() {
return gulp.src(paths.css)
.pipe(changed(paths.output, {extension: '.css'}))
.pipe(sourcemaps.init())
.pipe(sass(sassOptions).on('error', sass.logError))
.pipe(sourcemaps.write())
.pipe(autoprefixer())
.pipe(gulp.dest(paths.output));
});
gulp.task('build-style', function () {
return gulp.src(paths.style)
.pipe(changed(paths.outputStyle, { extension: '.css' }))
.pipe(sourcemaps.init())
.pipe(sass(sassOptions).on('error', sass.logError))
.pipe(sourcemaps.write())
.pipe(autoprefixer())
.pipe(gulp.dest(paths.outputStyle));
});
gulp.task('build-locales', function () {
return gulp.src(paths.locales)
.pipe(changed(paths.output, { extension: '.json' }))
.pipe(gulp.dest(paths.output));
});
gulp.task('build', function(callback) {
return runSequence(
'clean',
['build-system', 'build-html', 'build-css', 'build-style', 'build-locales'],
callback
);
});
gulp.task('clean', ['unbundle'], function() {
return gulp.src([paths.output])
.pipe(vinylPaths(del));
});
var config = {
force: true,
baseURL: './wwwroot',
configPath: './wwwroot/config.js',
bundles: bundles.bundles
};
gulp.task('bundle', ['build'], function() {
return bundler.bundle(config);
});
gulp.task('unbundle', function() {
return bundler.unbundle(config);
});
每个任务都返回一个gulp管道,一个调用回调方法的承诺。
我不知道为什么会发生这种情况以及为什么多次调用gulp会解决问题一次(然后你必须多次调用它)。
答案 0 :(得分:0)
要将问题记录在答案中:
问题是使用clean
任务的管道模型破损。
我使用另一种方法解决了这个问题,这里只需调用del
,它返回一个Promise(返回)。
gulp.task('clean', ['unbundle'], function() {
return del([paths.output]);
});