我一直在修补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 找到的所有 tuts 似乎都遵循该正则表达式格式:
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'))
);
});
但是,快速评论一下这是否正确也会很棒。谢谢!