我正在使用gulp将javascript / css文件复制到dist文件夹。有时它可以工作,但有时2个任务仍未完成。我以为这是一个时序问题,所以我已经安装了运行顺序,但是即使那样,并且.on('end')回调我的代码似乎也不起作用。所以我可能一直想念其他东西。
/// / * 该文件位于定义Gulp任务和使用Gulp插件的主要入口点。 点击这里了解更多。 http://go.microsoft.com/fwlink/?LinkId=518007 * /
'use strict';
// include plug-ins
var gulp = require('gulp');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var jshint = require('gulp-jshint');
var sass = require('gulp-sass');
var clean = require('gulp-clean')
var minifyCSS = require('gulp-minify-css');
var angularFilesort = require('gulp-angular-filesort');
var minify = require('gulp-minify');
var rev = require('gulp-rev');
var revFormat = require('gulp-rev-format');
var runSequence = require('run-sequence');
var config =
{
//Include all js files but exclude any min.js files
jsSrc: ['./client/app/**/*.module.js', './client/app/**/*.js'],
cssSrc: ['./client/css/errorPage.css', './client/css/fonts.css', './client/css/loginPage.css'],
minimalJsSrc: [
'node_modules/jquery/dist/jquery.min.js',
'node_modules/bootstrap/dist/js/bootstrap.min.js'
],
minimalCss: [
'node_modules/bootstrap/dist/css/bootstrap.min.css',
],
vendorjs: [
'node_modules/jquery/dist/jquery.min.js',
'node_modules/angular/angular.min.js',
'node_modules/bootstrap/dist/js/bootstrap.min.js',
'node_modules/angular-filter/dist/angular-filter.min.js',
'node_modules/angular-animate/angular-animate.min.js',
'node_modules/angular-sanitize/angular-sanitize.min.js',
'node_modules/angular-ui-router/release/angular-ui-router.min.js',
'node_modules/angular-loading-bar/build/loading-bar.min.js',
'node_modules/ui-select/dist/select.min.js',
'node_modules/angular-ui-sortable/sortable.min.js',
'node_modules/restangular/dist/restangular-min.js',
'node_modules/toastr/build/toastr.min.js',
'node_modules/sortablejs/Sortable.min.js',
'node_modules/adal-angular/dist/adal.min.js',
'node_modules/adal-angular/lib/adal-angular.js',
'node_modules/lodash/dist/lodash.min.js',
'node_modules/moment/min/moment.min.js',
'node_modules/moment/min/moment-with-locales.min.js',
'node_modules/moment-timezone/builds/moment-timezone-with-data.js',
'node_modules/underscore/underscore-min.js',
'node_modules/sortablejs/Sortable.min.js',
'node_modules/restangular/dist/restangular.min.js',
'node_modules/ngstorage/ngStorage.min.js',
'Client/app/layout/bootstrap.file-input.js',
'node_modules/ui-router-extras/release/ct-ui-router-extras.min.js',
'node_modules/ui-router-extras/release/modular/ct-ui-router-extras.core.min.js',
'node_modules/ui-router-extras/release/modular/ct-ui-router-extras.future.min.js',
'node_modules/angular-wizard/dist/angular-wizard.min.js',
'node_modules/api-check/dist/api-check.min.js',
'node_modules/angular-formly/dist/formly.min.js',
'node_modules/angular-formly-templates-bootstrap/dist/angular-formly-templates-bootstrap.min.js',
'node_modules/ng-office-ui-fabric/ngOfficeUiFabric.min.js',
'node_modules/bootbox/bootbox.min.js',
'scripts/ui-bootstrap-1.1.2.min.js',
'scripts/ui-bootstrap-tpls-1.1.2.js',
'node_modules/datatables.net/js/jquery.dataTables.js',
'node_modules/datatables.net-responsive/js/dataTables.responsive.js',
'node_modules/angular-datatables/dist/angular-datatables.min.js',
'node_modules/angular-translate/dist/angular-translate.min.js',
'node_modules/angular-ui-grid/ui-grid.min.js',
'node_modules/applicationinsights-js/dist/ai.0.js',
'node_modules/powerbi-client/dist/powerbi.min.js',
'node_modules/angular-ui-tinymce/dist/tinymce.min.js',
'node_modules/tinymce/tinymce.min.js',
'node_modules/tinymce/themes/modern/theme.min.js',
'node_modules/tinymce/themes/modern/theme.js',
'node_modules/tinymce/themes/inlite/theme.js',
'node_modules/tinymce/themes/mobile/theme.js',
'node_modules/tinymce/plugins/insertdatetime/plugin.min.js',
'node_modules/tinymce/plugins/table/plugin.min.js',
'node_modules/tinymce/plugins/wordcount/plugin.min.js',
'node_modules/tinymce/plugins/link/plugin.min.js',
'node_modules/tinymce/plugins/paste/plugin.min.js',
'node_modules/tinymce/plugins/code/plugin.min.js'
],
vendorCss: [
'node_modules/toastr/toastr.min.css',
'node_modules/bootstrap/dist/css/bootstrap.min.css',
'node_modules/ui-select/dist/select.min.css',
'node_modules/angular-loading-bar/build/loading-bar.min.css',
'node_modules/angular-wizard/dist/angular-wizard.min.css',
'node_modules/office-ui-fabric/dist/css/fabric.min.css',
'node_modules/office-ui-fabric/dist/css/fabric.components.min.css',
'node_modules/office-ui-fabric-core/dist/css/fabric.min.css',
'node_modules/datatables.net-responsive-dt/css/responsive.dataTables.min.css',
'node_modules/angular-datatables/dist/css/angular-datatables.min.css',
'node_modules/angular-ui-grid/ui-grid.min.css',
'node_modules/font-awesome/css/font-awesome.min.css',
'node_modules/open-iconic/font/css/open-iconic-bootstrap.min.css',
]
}
gulp.task('clean', function () {
gulp.src('./client/dist/*')
.pipe(clean({ force: true }));
return;
});
gulp.task('minify-js', function(done) {
gulp.src(config.jsSrc)
.pipe(concat('all.min.js'))
.pipe(uglify({ mangle: false }))
.pipe(gulp.dest('./client/dist'))
.on('end', function() {
done();
});
});
//used for the login and error page
gulp.task('minimal-package-js', function (done) {
gulp.src(config.minimalJsSrc)
.pipe(concat('minimal-package.js'))
.pipe(uglify({ mangle: false }))
.pipe(gulp.dest('./client/dist'))
.on('end', function () {
done();
});
});
gulp.task('minify-js-vendor', function () {
gulp.src(config.vendorjs)
.pipe(concat('vendor.min.js'))
.pipe(gulp.dest('./client/dist'))
return;
});
gulp.task('copy-bootstrap', function(done) {
gulp.src('node_modules/bootstrap/dist/css/bootstrap.css')
.pipe(gulp.dest('./client/dist'))
.on('end', function () {
done();
});
});
gulp.task('copy-fonts', function () {
gulp.src(['node_modules/font-awesome/fonts/*', 'node_modules/open-iconic/font/fonts/*', 'node_modules/bootstrap/fonts/*'])
.pipe(gulp.dest('./client/fonts'));
return;
});
gulp.task('minify-css', function () {
gulp.src(config.cssSrc)
.pipe(minifyCSS())
.pipe(concat('all.min.css'))
.pipe(gulp.dest('./client/dist'))
return;
});
gulp.task('minify-css-vendor', function () {
gulp.src(config.vendorCss)
.pipe(concat('vendor.min.css'))
.pipe(gulp.dest('./client/dist'))
return;
});
//Set a default tasks
gulp.task('default', function() {
return runSequence('clean', [
'copy-fonts',
'minimal-package-js',
'minify-js',
'minify-js-vendor',
'minify-css',
'minify-css-vendor',
'copy-bootstrap',
])
});
function errorHandler(error) {
console.log(error.toString());
this.emit('end');
}
错误日志保持空白,因此我不知道在哪里查找。
任何想法都将不胜感激。干杯!
答案 0 :(得分:0)
您必须在任务中返回流,而不仅仅是从任务结束处返回。参见signal task completion及其中的示例。
当流,promise,事件发射器,子进程或可观察对象为 从任务返回时,成功还是错误通知gulp是否 继续或结束。
所以
gulp.task('clean', function () {
return gulp.src('./client/dist/*')
.pipe(clean({ force: true }));
// return;
});
对所有任务进行更改。