【问题标题】:Gulp file change into a concat streamGulp 文件更改为 concat 流
【发布时间】:2016-04-13 07:03:48
【问题描述】:

我使用我的 gulp 文件(dev、uat 等)设置了多个构建,我需要在我的 app.js 文件中定义某些变量,然后将它们连接到我的主包文件中。

我不想创建编辑后的文件然后连接该文件。是否可以更改变量然后将更改的文件放入内存并在 concat 中使用?

gulp.src('_app.js').pipe(replace("'baseURL':", "'baseURL':'www.test.com'"))
            .pipe(concat(['list of files','file in memory']));

【问题讨论】:

    标签: gulp gulp-concat


    【解决方案1】:

    您可以使用gulp-replace 在您的app.js 中进行实际替换,然后使用merge-stream 将其与您的其他源文件结合起来:

    var replace = require('gulp-replace');
    var merge = require('merge-stream');
    var order = require('gulp-order');
    
    gulp.task('concat', function() {
      var appStream = gulp.src('app.js')
        .pipe(replace(/'baseURL':/, "'baseURL':'www.test.com'"));
      return merge(appStream, gulp.src(['list of files']))
        .pipe(order(['app.js', '*.js']))
        .pipe(concat('concatenatedFile.js'))
        .pipe(gulp.dest('dist'));
    });
    

    【讨论】:

    • 感谢您的帮助,我查看了合并,但在进入上下文之前它对我没有意义。再次感谢您。
    • 如何设置合并的顺序?
    • 查看gulp-order。我已经用一个将app.js 放在所有其他.js 文件前面的示例更新了我的答案。
    • 我最终使用 gulp streamque
    猜你喜欢
    • 1970-01-01
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多