问题
Needed something like this:
gulp.src(path.join(conf.paths.src, '/**/*.less'))
.pipe($.less()) // already have some result, but HUGE changes are needed
.pipe(HERE_I_GET_IT_AS_A_TEXT(function(str){
// a lot of different changes
return changed_str;
}))
.pipe(rename('styles.css')) // go on doing smth with changed_str
.pipe(gulp.dest('./app/theme/'));
Is there something in gulp to get some transitional result as text, process text with js and pass it to the next pipes? Everywhere I find only solution with reading files directly, this way is pointless for me.
回答1:
Use map-stream:
var gulp = require('gulp');
var map = require('map-stream');
gulp.src(path.join(conf.paths.src, '/**/*.less'))
.pipe($.less())
.pipe(map(function(file, done) {
var str = file.contents.toString();
str = str.replace(/foo/, "bar");
file.contents = new Buffer(str);
done(null, file);
}))
.pipe(rename('styles.css')) // go on doing smth with changed_str
.pipe(gulp.dest('./app/theme/'));
来源:https://stackoverflow.com/questions/36422699/gulp-how-to-get-gulp-result-as-variable