我正在运行一些Gulp任务,并且在使用del npm模块执行干净任务后,我无法完全清理dist /文件夹,这是Gulp建议删除文件夹和文件的。我的Gulpfile.js如下:
// Setup modules/Gulp plugins
var gulp = require('gulp'),
del = require('del'),
less = require('gulp-less'),
minifyCSS = require('gulp-minify-css'),
fileinclude = require('gulp-file-include'),
streamify = require('gulp-streamify'),
order = require('gulp-order'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
sourcemaps = require('gulp-sourcemaps'),
imagemin = require('gulp-imagemin'),
pngquant = require('imagemin-pngquant'),
plumber = require('gulp-plumber'),
connect = require('gulp-connect');
// Configure file paths
var path = {
DEST: 'dist/',
SRC: 'src/',
INCLUDES: 'include/',
LESS_SRC: 'src/frontend/less/',
LESS_MANIFEST: 'src/frontend/less/all.less',
CSS_DEST: 'dist/frontend/css/',
JS_SRC: 'src/frontend/js/',
JS_MINIFIED_OUT: 'all.js',
JS_DEST: 'dist/frontend/js',
IMG_SRC: 'src/frontend/img/',
IMG_DEST: 'dist/frontend/img/',
};
// Clean out build folder each time Gulp runs
gulp.task('clean', function (cb) {
del([
path.DEST
], cb);
});
// Compile LESS
gulp.task('less', function(){
return gulp.src(path.LESS_MANIFEST)
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(less())
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(path.CSS_DEST));
// Copy src folders into dist folder
// gulp.src(path.LESS_SRC + '**')
// .pipe(gulp.dest(path.CSS_DEST + 'less/'));
});
// Allow HTML files to be included
gulp.task('html', function() {
return gulp.src([path.SRC + '*.html'])
.pipe(connect.reload())
.pipe(plumber())
.pipe(fileinclude({
prefix: '@@',
basepath: path.INCLUDES
}))
.pipe(gulp.dest(path.DEST));
});
// Concatenate and minify JavaScript
gulp.task('js', function() {
return gulp.src(path.JS_SRC + '**/*.js')
.pipe(order([
path.JS_SRC + 'framework/*.js',
path.JS_SRC + 'vendor/*.js',
path.JS_SRC + 'client/*.js'
], {base: '.'} ))
.pipe(concat(path.JS_MINIFIED_OUT))
.pipe(uglify())
.pipe(gulp.dest(path.JS_DEST));
});
// Minify images
gulp.task('imagemin', function () {
return gulp.src(path.IMG_SRC + '*')
.pipe(imagemin({
progressive: true,
use: [pngquant()]
}))
.pipe(gulp.dest(path.IMG_DEST));
});
// Copy folders
gulp.task('copy', function() {
return gulp.src(path.SRC + 'extjs/*')
.pipe(gulp.dest(path.DEST + 'extjs/'));
});
// Watch files
gulp.task('watch', function(){
gulp.watch(path.LESS_SRC + '**/*.less', ['less']);
gulp.watch(path.SRC + '*.html', ['html']);
gulp.watch(path.JS_SRC + '**/*.js', ['js']);
});
// Connect to a server and livereload pages
gulp.task('connect', function() {
connect.server({
root: path.DEST,
livereload: true
});
});
// Default task
gulp.task('default', [
'clean',
'less',
'html',
'js',
'imagemin',
'copy',
'watch',
'connect'
]);
通常每次运行此操作时,我都会在控制台中出现某种错误,并且在终端中运行gulp
后,它并没有完全删除dist /文件夹。
[14:34:12] Using gulpfile ~/Desktop/outerbox/odot/Gulpfile.js
[14:34:12] Starting 'clean'...
[14:34:12] Starting 'less'...
[14:34:12] Starting 'html'...
[14:34:12] Starting 'js'...
[14:34:12] Starting 'imagemin'...
[14:34:12] Starting 'copy'...
[14:34:12] Starting 'watch'...
[14:34:12] Finished 'watch' after 16 ms
[14:34:12] Starting 'connect'...
[14:34:12] Finished 'connect' after 7.64 ms
[14:34:12] Server started http://localhost:8080
[14:34:12] LiveReload started on port 35729
[14:34:13] Finished 'html' after 303 ms
[14:34:13] 'clean' errored after 360 ms
[14:34:13] Error: ENOTEMPTY, rmdir '/Users/jacobtarr/Desktop/outerbox/odot/dist'
at Error (native)
[14:34:13] 'js' errored after 340 ms
[14:34:13] Error: ENOENT, stat '/Users/jacobtarr/Desktop/outerbox/odot/dist/frontend/js/all.js'
at Error (native)
[14:34:13] 'copy' errored after 330 ms
[14:34:13] Error: ENOENT, stat '/Users/jacobtarr/Desktop/outerbox/odot/dist/extjs/ext-all.js'
at Error (native)
[14:34:13] Finished 'less' after 388 ms
[14:34:14] gulp-imagemin: Minified 30 images (saved 139.74 kB - 17.5%)
[14:34:14] Finished 'imagemin' after 1.49 s
如何修复此错误?如何在运行gulp之前正确刷出dist /文件夹?