好处:
- DRY
- 可以用在其他地方
config.json:
{
"desktop": {
"src": [
"dev/desktop/js/**/*.js",
"!dev/desktop/js/venfor/**"
],
"dest": "build/scripts/desktop"
},
"mobile": {
"src": [
"dev/mobile/js/**/*.js",
"!dev/mobile/js/vendor/**"
],
"dest": "build/scripts/mobile"
}
}
gulpfile.js
var gulp = require('gulp');
var uglify = require('gulp-uglify');
// 引入外部配置文件
var config = require('./config.json');
function doStuff(cfg) {
return gulp.src(cfg.src)
.pipe(uglify())
.pipe(gulp.dest(cfg.dest));
}
gulp.task('dry', function () {
// 使用外部文件
doStuff(config.desktop);
doStuff(config.mobile);
});