I've been trying to figure out how to add a line of text to any type of file using Gulp.
For instance add:
@import 'plugins'
to my main.sass file.
Or add a CDN to an index.html file.
I did try:
gulp.task('inject-plugins', function(){
gulp.src('src/css/main.sass')
.pipe(inject.after('// Add Imports', '\n@import \'plugins\'\n'));
});
with no joy. Any idea how I could achieve this please?
Depends on what you want to do.
If you just want to add text to the beginning or end of a file
gulp-header
andgulp-footer
are your friends:If you have some kind of "anchor" text in your file you can use
gulp-replace
:Finally there's the swiss army knife of vinyl file manipulation:
map-stream
. This gives you direct access to file contents and allows you to do any kind of string manipulation that you can think of in JavaScript: