Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gulp: How do I read file content into a variable?

I have a gulp task that needs to read a file into a variable, and then use its content as input for a different function that runs on the files in the pipe. How do I do that?

Example psuedo-psuedo-code

gulp.task('doSometing', function() {   var fileContent=getFileContent("path/to/file.something"); //How?    return gulp.src(dirs.src + '/templates/*.html')     .pipe(myFunction(fileContent))     .pipe(gulp.dest('destination/path)); }); 
like image 949
OpherV Avatar asked Apr 21 '15 10:04

OpherV


1 Answers

Thargor pointed me out in the right direction:

gulp.task('doSomething', function() {   var fileContent = fs.readFileSync("path/to/file.something", "utf8");    return gulp.src(dirs.src + '/templates/*.html')     .pipe(myFunction(fileContent))     .pipe(gulp.dest('destination/path')); }); 
like image 112
OpherV Avatar answered Sep 17 '22 15:09

OpherV