加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 在gulp中组合多个src流?

发布时间:2020-12-17 08:46:52 所属栏目:安全 来源:网络整理
导读:我想知道是否有办法将这两个单独的任务合二为一. 此concat-js任务要求在运行之前存在生成的文件.任务cache-angular-templates生成该文件.生成的文件需要包含在concat输出中.在完成concat-js之后,可以删除该文件 – 不再需要它. 似乎我应该以某种方式能够将ca
我想知道是否有办法将这两个单独的任务合二为一.

此concat-js任务要求在运行之前存在生成的文件.任务cache-angular-templates生成该文件.生成的文件需要包含在concat输出中.在完成concat-js之后,可以删除该文件 – 不再需要它.

似乎我应该以某种方式能够将cache-angular-tempaltes中使用的流管道输入到concat-js使用的流中.

gulp.task('concat-js',['cache-angular-templates'],function () {
    var concatOutputPath = path.dirname(paths.compiledScriptsFile),concatOutputFileName = path.basename(paths.compiledScriptsFile),jsFiles = [].concat(
            paths.libScripts,paths.appScripts,paths.templateScriptFile,notpath(paths.compiledScriptsFile),notpath(paths.specMockScripts),notpath(paths.specScripts)
        );

    return gulp
        .src(jsFiles)
        .pipe(buildTools.concat(concatOutputFileName))
        .pipe(gulp.dest(concatOutputPath))
        .on('end',function () {
            del(paths.templateScriptFile);
        })
    ;
});

gulp.task('cache-angular-templates',function () {
    var cacheOutputPath = path.dirname(paths.templateScriptFile),cacheOutputFileName = path.basename(paths.templateScriptFile);

    var options = {
        root: '/' + cacheOutputPath,standalone: true,filename: cacheOutputFileName
    };

    return gulp
        .src(paths.templates)
        .pipe(buildTools.angularTemplatecache(options))
        .pipe(gulp.dest(cacheOutputPath))
    ;
});
确实你应该合并它们,因为Gulp的一个想法是消除中间临时文件.

实现它的方法之一是:

>将cache-angular-templates转换为返回模板流的函数,我们称之为getTemplateStream;
>从中删除.pipe(gulp.dest(cacheOutputPath));
>在将流连接到主任务之前使用event-stream合并流.你的主要任务将是这样的:

var es = require('event-stream');

gulp.task('concat-js',notpath(paths.specScripts)
        );

    return es.merge(gulp.src(jsFiles),getTemplateStream())
        .pipe(buildTools.concat(concatOutputFileName))
        .pipe(gulp.dest(concatOutputPath));
});

function getTemplateStream() {
    var options = {
        root: '/' + cacheOutputPath,filename: cacheOutputFileName
    };

    return gulp
        .src(paths.templates)
        .pipe(buildTools.angularTemplatecache(options));
}

通过执行此操作,您将合并两个流,并且getTemplateStream的输出文件将沿管道发送.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读