Open yairEO opened 9 years ago
+1. I was using insert.prepend
but was getting a similar issue. I wanted to prepend a shebang to the file, but gulp-insert was editing the end of the file regardless. If there is a way to strictly just prepend (or append as @yairEO would like) a string of text then please let us know. Thanks.
You could use gulp-concat
to concat your files first and then use insert.append
to add your text at the end.
concat = require 'gulp-concat'
insert = require 'gulp-insert'
gulp.src ['.ext']
.pipe doYourStuff()
.pipe concat 'together.ext'
.pipe insert.append '# something at the end'
.pipe gulp.dest '/target'
I want to insert something only of some condition has been met. What in your opinion would be the best way? I can't insert an if
statement in the middle of functions chaining. I guess I could save the stream into a variable, test the condition, and only in the end save the stream to disk using dest
function
I'd suggest gulp-if
var gulpif = require('gulp-if');
var insert = require('gulp-insert');
var condition = true; // TODO: add business logic
gulp.task('task', function() {
gulp.src('./src/*.js')
.pipe(doYourStuff())
.pipe(gulpif(condition, insert.append('# something at the end')))
.pipe(gulp.dest('./dist/'));
});
I don't want to insert text into every file. I only want to add it to the end of the whole stream, so if I have many files in my
gulp.src()
it would be added to the end. is that possible?