Consider the following two files:
考虑以下两个文件:
config.json
json
{
"vendorFiles": [
"vendor/angular/angular.js",
"vendor/angular-ui-router/release/angular-ui-router.js",
"vendor/angular-ui-utils/modules/utils.js"
]
}
gulpfile.js
gulpfile.js
var gulp = require("gulp"),
concat = require("gulp-concat"),
config = require("./config");
gulp.task("build-vendor", function() {
gulp.src(config.vendorFiles)
.pipe(concat("vendor.js"))
.pipe(gulp.dest("build"));
});
How can I eliminate the need to specify vendor/
for each file in config.json? That file is one that is manually edited by other developers by hand, so I want to make it as hassle-free on them as possible.
如何消除为config.json中的每个文件指定供应商/的需要?这个文件是由其他开发人员手工编辑的,所以我想让它在他们身上尽可能地没有麻烦。
Ideally I'd like my gulpfile.js to take care of adding that prefix (somehow), and for my config.json to look like this:
理想情况下,我想要我的gulpfile。要注意添加前缀(以某种方式)和配置。json看起来是这样的:
{
"vendorFiles": [
"angular/angular.js",
"angular-ui-router/release/angular-ui-router.js",
"angular-ui-utils/modules/utils.js"
]
}
2 个解决方案
#1
4
There may be a better way with a Gulp specific solution, but this should work.
也许有一种更好的解决方案,但这应该是可行的。
var gulp = require("gulp"),
concat = require("gulp-concat"),
config = require("./config");
gulp.task("build-vendor", function() {
gulp.src(config.vendorFiles.map(function(a) {return 'vendor/' + a}))
.pipe(concat("vendor.js"))
.pipe(gulp.dest("build"));
});
Demo: http://jsfiddle.net/AK4tP/
演示:http://jsfiddle.net/AK4tP/
#2
0
Can't you just do
你就不能做
var gulp = require("gulp"),
concat = require("gulp-concat"),
config = require("./config");
gulp.task("build-vendor", function() {
gulp.src(config.vendorFiles, {root: 'vendor/'})
.pipe(concat("vendor.js"))
.pipe(gulp.dest("build"));
});
Gulp should accept root
option in src() although it's not documented.
Gulp应该接受src()中的root选项,尽管它没有文档记录。
#1
4
There may be a better way with a Gulp specific solution, but this should work.
也许有一种更好的解决方案,但这应该是可行的。
var gulp = require("gulp"),
concat = require("gulp-concat"),
config = require("./config");
gulp.task("build-vendor", function() {
gulp.src(config.vendorFiles.map(function(a) {return 'vendor/' + a}))
.pipe(concat("vendor.js"))
.pipe(gulp.dest("build"));
});
Demo: http://jsfiddle.net/AK4tP/
演示:http://jsfiddle.net/AK4tP/
#2
0
Can't you just do
你就不能做
var gulp = require("gulp"),
concat = require("gulp-concat"),
config = require("./config");
gulp.task("build-vendor", function() {
gulp.src(config.vendorFiles, {root: 'vendor/'})
.pipe(concat("vendor.js"))
.pipe(gulp.dest("build"));
});
Gulp should accept root
option in src() although it's not documented.
Gulp应该接受src()中的root选项,尽管它没有文档记录。