在线文档教程

使用外部配置文件

使用外部配置文件

这有很多好处,因为它能让任务更加符合 DRY 原则,并且 config.json 可以被其他的任务运行器使用,比如 grunt

{"blocks":[{"key":"6ahfp","text":"config.json","type":"header-six","depth":0,"inlineStyleRanges":[{"offset":0,"length":11,"style":"CODE"}],"entityRanges":[],"data":[]}],"entityMap":[]}

{ "desktop" : { "src" : [ "dev/desktop/js/**/*.js", "!dev/desktop/js/vendor/**" ], "dest" : "build/desktop/js" }, "mobile" : { "src" : [ "dev/mobile/js/**/*.js", "!dev/mobile/js/vendor/**" ], "dest" : "build/mobile/js" } }

{"blocks":[{"key":"38gbb","text":"gulpfile.js","type":"header-six","depth":0,"inlineStyleRanges":[{"offset":0,"length":11,"style":"CODE"}],"entityRanges":[],"data":[]}],"entityMap":[]}

// npm install --save-dev gulp gulp-uglify 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 }