Gulp – 如何追加到dest而不是replace

我有一个代码:

gulp.task('concat-uglify-js', function() { return gulp.src(src + 'js/*.js') .pipe(concat('angular-filemanager.min.js')) .pipe(uglify()) .pipe(gulp.dest(dst)) }); gulp.task('cache-templates', function () { return gulp.src(tplPath + '/*.html') .pipe(templateCache('cached-templates.js', { module: 'FileManagerApp', base: function(file) { return tplPath + '/' + path.basename(file.history); } })) .pipe(uglify()) .pipe(gulp.dest(dst)); }); 

我想合并这两个任务输出在一个文件中…“angular-filemanager.min.js”

有一个选项可以做类似的事情

 .pipe(gulp.dest(dst, {mode: "APPEND_INSTEAD_OF_REPLACE"})); 

谢谢!

我没有testing过,但尝试使用gulpfilter :

 var gulpFilter = require('gulp-filter'); gulp.task('concat-uglify-js', function() { var filter = { html: gulpFilter('*.html'), js : gulpFilter('*.js') }; return gulp .src([src + 'js/*.js', tplPath + '/*.html']) .pipe(filter.html) .pipe(templateCache('cached-templates.js', { module: 'FileManagerApp', base: function(file) { return tplPath + '/' + path.basename(file.history); } })) .pipe(filter.html.restore) .pipe(filter.js) .pipe(concat('angular-filemanager.min.js')) .pipe(uglify()) .pipe(gulp.dest(dst)); }); 

现在可能没有什么帮助,因为它还没有发布 ,但是4.0中的gulp.dest会添加一个默认为true 的overwrite选项 ,但是可以设置为false来添加:

.pipe(gulp.dest(path, { overwrite: false }))

您可以将函数调用templateCache ,然后使用add-stream将该函数的输出与concat-uglify-js任务中的js文件add-stream组合起来。

我不确定你正在使用什么angular度模板caching插件,但我在这里更详细地写了这个情况。

 var addStream = require('add-stream'); gulp.task('concat-uglify-js', function() { return gulp.src(src + 'js/*.js') // add js file containing cached templates to stream of js files .pipe(addStream.obj(cacheTemplates())) .pipe(concat('angular-filemanager.min.js')) .pipe(uglify()) .pipe(gulp.dest(dst)) }); // is this task still needed? gulp.task('cache-templates', function () { return cacheTemplates() .pipe(uglify()) .pipe(gulp.dest(dst)); }); // this returns a stream of one js file function cacheTemplates() { return gulp.src(tplPath + '/*.html') // (you may want to minify html here) .pipe(templateCache('cached-templates.js', { module: 'FileManagerApp', base: function(file) { return tplPath + '/' + path.basename(file.history); } })); }