node.js - How to inject script with gulp -


i have installed https://www.npmjs.com/package/gulp-inject-string

and create gulpfile.js :

// include gulp var gulp = require('gulp');   // include our plugins var inject = require('gulp-inject-string');  gulp.task('default', function(){     gulp.src('index.html')         .pipe(inject.before('</body>', '<script src="myscript.js"></script>\n'))         .pipe(gulp.dest('./test'));     console.log('myscript.js injected'); }); 

when executing gulp, console.log executed correctly index.html has not been injected script before /body tag.

what should fix ?

update : tested folder, index.html written no script injected.

though have injected haven't written output file.

you can try this

gulp.task('default', function(){     gulp.src('index.html')         .pipe(inject.before('</body>', '<script src="myscript.js"></script>\n')) .pipe(rename('<name of file>')) .pipe(gulp.dest('<output folder>'));     console.log('myscript.js injected'); }); 

Comments