Skip to content

Instantly share code, notes, and snippets.

@anistark
Created May 29, 2017 11:47
Show Gist options
  • Save anistark/e646d2fcb74f707faf8274bd72e0efb3 to your computer and use it in GitHub Desktop.
Save anistark/e646d2fcb74f707faf8274bd72e0efb3 to your computer and use it in GitHub Desktop.
Using external config file

Using external config file

Beneficial because it's keeping tasks DRY and config.json can be used by another task runner, like grunt.

config.json
{
  "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"
  }
}
gulpfile.js
// 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);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment