Created
September 16, 2014 15:04
-
-
Save kbshl/7b44e51f83deee1dd86d to your computer and use it in GitHub Desktop.
Gulp Receipe: Pass arguments from the command line
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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