【问题标题】:Utilising the output of two previous gulp streams利用前两个 gulp 流的输出
【发布时间】:2015-05-31 09:16:36
【问题描述】:

我想取一个CSS处理步骤getCss和一个JS处理步骤getJs的结果,然后用这两个结果创建一个名为index.html的文件,这是内联处理后的结果将 CSS 和 JS 处理成一个名为 index-template.html 的模板。

有人可以帮助我更好地了解如何实现这一目标吗?

这就是我目前所拥有的......

gulp.task('build', function() {
    eventStream.merge(getCss.bind(gulp), getJs.bind(gulp))
        .pipe(inlineJsAndCss.bind(gulp));
});

function getCss() {
    return this.src(options.lessGlob)
        .pipe(less())
        .pipe(minifyCss());
}

function getJs() {
    return this.src(options.jsGlob)
        .pipe(uglify());
}

function inlineJsAndCss() {
    // Take the CSS and the JS generated by 
    // previous steps and inline them into 
    // index-template.html
    //...
    .pipe(this.dest('index.html'));
}

编辑:将中间步骤的结果存储在内存中,然后从中创建一个流,这是实现此目的的规范方法吗?

https://github.com/gulpjs/gulp/blob/master/docs/recipes/make-stream-from-buffer.md

【问题讨论】:

    标签: javascript stream gulp


    【解决方案1】:

    不需要使用eventStream.merge

    只需将 CSS 和 JS 处理步骤的结果输出到最后一步可见的内存区域中,然后相应地配置 gulp 依赖项。

    类似这样的:

    const sharedMemory = {};
    gulp.task('css', partial(getCss, sharedMemory));
    gulp.task('js', partial(getJs, sharedMemory));
    gulp.task('inline', ['css', 'js'], partial(inline, sharedMemory));
    gulp.task('build', ['replace']);
    gulp.task('default', ['build']);
    

    【讨论】:

      猜你喜欢
      • 2018-07-02
      • 2016-05-10
      • 2011-07-15
      • 1970-01-01
      • 1970-01-01
      • 2017-05-30
      • 1970-01-01
      • 1970-01-01
      • 2022-03-23
      相关资源
      最近更新 更多