Gulp Equivalent(来自Grunt) - 多个src文件

时间:2014-01-31 12:06:08

标签: gruntjs gulp

我一直在修补GulpJS并认为这是Grunt的下一步,但是在比较中我遇到了一些语法问题。

以下是我Gruntfile.js的一部分:

concat: {
    ie: {
        options: {
            separator: "\n\n"
        },
        src: [
            "bower_components/selectivizr/selectivizr.js",
            "bower_components/respond/dest/respond.min.js",
            "bower_components/REM-unit-polyfill/js/rem.js"
        ],
        dest: "assets/js/build/ie.js"
    },
    dist: {
        options: {
            separator: "\n\n"
        },
        src: [
            // Foundation Vendor
            "bower_components/foundation/js/vendor/fastclick.js",
            "bower_components/foundation/js/vendor/placeholder.js",
            // Foundation Core
            "bower_components/foundation/js/foundation/foundation.js",
            "bower_components/foundation/js/foundation/foundation.abide.js",
            "bower_components/foundation/js/foundation/foundation.accordion.js",
            "bower_components/foundation/js/foundation/foundation.alert.js",
            "bower_components/foundation/js/foundation/foundation.clearing.js",
            "bower_components/foundation/js/foundation/foundation.dropdown.js",
            "bower_components/foundation/js/foundation/foundation.interchange.js",
            "bower_components/foundation/js/foundation/foundation.joyride.js",
            "bower_components/foundation/js/foundation/foundation.magellan.js",
            "bower_components/foundation/js/foundation/foundation.offcanvas.js",
            "bower_components/foundation/js/foundation/foundation.orbit.js",
            "bower_components/foundation/js/foundation/foundation.reveal.js",
            "bower_components/foundation/js/foundation/foundation.tab.js",
            "bower_components/foundation/js/foundation/foundation.tooltip.js",
            "bower_components/foundation/js/foundation/foundation.topbar.js",
            // Custom Vendor

            // Project
            "assets/js/src/_init.js"

            ],
        dest: "assets/js/build/scripts.js"
    }
}

正如你所看到的,我正在指定特定的文件(因为我不想像你通常看到的那样拉入整个目录),这看起来很简单。我为Gulp找到的所有内容似乎都遵循正则表达式格式:

gulp.task('scripts', function() {
  return gulp.src("assets/js/src/_init.js")
    .pipe(jshint('.jshintrc'))
    .pipe(jshint.reporter('default'))
    .pipe(concat('main.js'))
    .pipe(gulp.dest('assets/js/build'))
    .pipe(rename({ suffix: '.min' }))
    .pipe(uglify())
    .pipe(livereload(server))
    .pipe(gulp.dest('assets/js/build'))
    .pipe(notify({ message: 'Scripts task complete' }));
});

但是将逗号分隔的列表放入src部分不起作用 - 我们如何将一组文件传递给该方法?

看起来我可以在一个中使用多个流来分离我的IE特定脚本,如下所示:

gulp.task('test', function(cb) {
    return es.concat(
        gulp.src('bootstrap/js/*.js')
            .pipe(gulp.dest('public/bootstrap')),
        gulp.src('jquery.cookie/jquery.cookie.js')
            .pipe(gulp.dest('public/jquery'))
    );
});

但是,如果这是正确的,那么快速评论也会很棒。谢谢!

1 个答案:

答案 0 :(得分:34)

来自the documentation

  

水珠

     

输入:StringArray

     

要阅读的全球或全球。

换句话说,传入一个字符串数组,如:

gulp.src(['file1.js', 'file2.js']).pipe(...)
//       ^                      ^
//       '-------- Array -------'

请注意,这与Grunt的完全格式相同。这是一系列的globs,而不是以逗号分隔的列表。