gpt4 book ai didi

javascript - Gulp:如何将 gulp 结果作为变量

转载 作者:行者123 更新时间:2023-11-29 21:31:12 26 4
gpt4 key购买 nike

需要这样的东西:

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 处理文本并将其传递给下一个管道?我到处都只能找到直接读取文件的解决方案,这种方式对我来说毫无意义。

最佳答案

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

关于javascript - Gulp:如何将 gulp 结果作为变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36422699/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com