Skip to content

Instantly share code, notes, and snippets.

@kbshl
Created September 16, 2014 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kbshl/7b44e51f83deee1dd86d to your computer and use it in GitHub Desktop.
Save kbshl/7b44e51f83deee1dd86d to your computer and use it in GitHub Desktop.
Gulp Receipe: Pass arguments from the command line
// npm install --save-dev gulp gulp-if gulp-uglify minimist
var gulp = require('gulp');
var gulpif = require('gulp-if');
var uglify = require('gulp-uglify');
var minimist = require('minimist');
var knownOptions = {
string: 'env',
default: { env: process.env.NODE_ENV || 'production' }
};
var options = minimist(process.argv.slice(2), knownOptions);
gulp.task('scripts', function() {
return gulp.src('**/*.js')
.pipe(gulpif(options.env === 'production', uglify())) // only minify in production
.pipe(gulp.dest('dist'));
});
// Then run gulp with:
// $ gulp scripts --env development
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment