Gulp:如何将gulp结果变为变量 [英] Gulp: how to get gulp result as variable

查看:158
本文介绍了Gulp:如何将gulp结果变为变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要这样的东西:

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

有什么东西可以获得一些过渡结果作为文本,使用js处理文本并将其传递给下一个管道?在任何地方我都找到了直接读取文件的解决方案,这种方式对我来说毫无意义。

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.

推荐答案

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

这篇关于Gulp:如何将gulp结果变为变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆