Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/437.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Gulp:如何将Gulp结果作为变量_Javascript_Gulp_Less - Fatal编程技术网

Javascript Gulp:如何将Gulp结果作为变量

Javascript Gulp:如何将Gulp结果作为变量,javascript,gulp,less,Javascript,Gulp,Less,需要这样的东西: 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;

需要这样的东西:

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/'));
gulp中是否有一些东西可以作为文本获得过渡结果,用js处理文本并将其传递给下一个管道?无论我在哪里都能找到直接读取文件的唯一解决方案,这种方式对我来说毫无意义。

使用:

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/'));