我写了一个快速吞咽任务,它合并了几个来源。它首先清除所有内容的现有 JS 构建文件夹,然后构建 AngularJS 模板缓存,最后缩小并合并文件以在应用程序中使用,但是运行 gulp 的 4 次中有 3 次抛出错误,指示文件或文件夹在构建期间已存在:
$ gulp compress
[13:29:52] Using gulpfile D:\projects\app\mobile\gulpfile.js
[13:29:52] Starting 'compress'...
stream.js:74
throw er; // Unhandled stream error in pipe.
^
Error: EEXIST: file already exists, mkdir 'D:\projects\app\mobile\www\js\components'
at Error (native)
但是 clear 应该在此子任务运行之前删除所有文件和文件夹:
gulp.task('compress', function (done) {
// Clear existing build files
var clear = gulp.src('./www/js/**/*')
.pipe(vinylPaths(del));
// Build the template cache
var cache = gulp.src('./www/templates/**/*.tpl.html')
.pipe(templateCache('app-templates.js', {
root: 'templates',
transformUrl: function (url) {
return url.replace(/\.tpl\.html$/, '.html')
}
}))
.pipe(gulp.dest('./www/js'))
// Minify and concatenate the application
var build = gulp.src('./src/**/*.js')
.pipe(uglify({
mangle: false
}))
.pipe(gulp.dest('./www/js'))
.pipe(concat('app.min.js'))
.pipe(gulp.dest('./www/js/build'));
// Merge multiple sources into a single task
return merge(clear, cache, build);
});
有什么我错过的想法吗?还是有更好的方法来完成此类任务?除了没有清除旧版本之外,它似乎工作得很好。