美文网首页每天五分钟之IT技能包
gulp进阶(2) - 使用外部配置文件

gulp进阶(2) - 使用外部配置文件

作者: 学好该死的程序 | 来源:发表于2017-10-25 17:05 被阅读0次

动静态分离,将变化的部分提取成配置文件,而任务执行流程则静态化处理,针对不同的项目只需要设置配置文件即可套用。


config.json

{
    "desktop": {
        "src"  : "desktop/src/**/*.js",
        "dist" : "desktop/build"
    },
    "mobile": {
        "src"  : "mobile/src/**/*.js",
        "dist" : "mobile/build"
    }
}

gulpfile.js

var gulp   = require('gulp'),
    uglify = require('gulp-uglify');
    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);
});

相关文章

网友评论

    本文标题:gulp进阶(2) - 使用外部配置文件

    本文链接:https://www.haomeiwen.com/subject/odtcpxtx.html