【问题标题】:Combine gulp tasks to avoid creating the unnecessary files合并 gulp 任务以避免创建不必要的文件
【发布时间】:2015-10-19 13:38:01
【问题描述】:

我正在使用两个单独的 gulp 任务将模板缩小为 js 文件 (1),并将项目的所有 js 文件合并为唯一的缩小文件 (2)。

gulp.task('templates', function() { // RESULT of this task
    return gulp.src('templates/**/*.html')
        .pipe(dotify({
            root : 'templates'
        }))
        .pipe(concat('templates.js'))
        .pipe(gulp.dest('js'));
    });


gulp.task('minifyJs', ['templates'], function() {
    return gulp.src([
        'js/templates.js',
        'js/plugins/*.js',
        'js/*.js'
    ])
    .pipe(concat('scripts-all.js'))
});

问题是:我是否能够通过处理从第一个任务到第二个任务的结果来避免创建 templates.js 文件以将其与其余的 js 连接起来?

【问题讨论】:

    标签: javascript gulp gulp-concat dot.js


    【解决方案1】:

    解决方法:应该使用 addSrc

    return gulp.src('templates/**/*.html')
        .pipe(dotify({
            root : 'templates'
        }))
        .pipe(addSrc([
            'js/plugins/*.js',
            'js/common/*.js',
            'js/ui/*.js',
            'js/pages/*.js',
            'js/*.js'
        ]))
        .pipe(concat('scripts-all.js'))
        .pipe(gulp.dest('js/'));
    

    【讨论】:

      猜你喜欢
      • 2018-05-23
      • 1970-01-01
      • 1970-01-01
      • 2019-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多