From 434a67a5fb0a27f55e1230cb8b82b61ba9b30b4d Mon Sep 17 00:00:00 2001 From: jos Date: Tue, 8 Jul 2014 14:24:12 +0200 Subject: [PATCH] Some minor improvements to the build script --- gulpfile.js | 28 +++++++++++++++++++--------- package.json | 5 +++-- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 1a0f9e9c..0ead2fd8 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -8,6 +8,7 @@ var webpack = require('webpack'); var uglify = require('uglify-js'); var rimraf = require('rimraf'); var merge = require('merge-stream'); +var argv = require('yargs').argv; var ENTRY = './index.js'; var HEADER = './lib/header.js'; @@ -58,9 +59,9 @@ var uglifyConfig = { // create a single instance of the compiler to allow caching var compiler = webpack(webpackConfig); -// clean the dist directory +// clean the dist/img directory gulp.task('clean', function (cb) { - rimraf(DIST, cb); + rimraf(DIST + '/img', cb); }); gulp.task('bundle-js', ['clean'], function (cb) { @@ -124,15 +125,24 @@ gulp.task('minify', ['bundle-js'], function (cb) { gulp.task('bundle', ['bundle-js', 'bundle-css', 'copy-img']); -// The watch task (to automatically rebuild when the source code changes) -gulp.task('watch', ['bundle', 'minify'], function () { - gulp.watch(['index.js', 'lib/**/*'], ['bundle', 'minify']); -}); +// read command line arguments --bundle and --minify +var bundle = 'bundle' in argv; +var minify = 'minify' in argv; +var watchTasks = []; +if (bundle || minify) { + // do bundling and/or minifying only when specified on the command line + watchTasks = []; + if (bundle) watchTasks.push('bundle'); + if (minify) watchTasks.push('minify'); +} +else { + // by default, do both bundling and minifying + watchTasks = ['bundle', 'minify']; +} // The watch task (to automatically rebuild when the source code changes) -// this watch only rebuilds vis.js, not vis.min.js -gulp.task('watch-dev', ['bundle'], function () { - gulp.watch(['index.js', 'lib/**/*'], ['bundle']); +gulp.task('watch', watchTasks, function () { + gulp.watch(['index.js', 'lib/**/*'], watchTasks); }); // The default task (called when you run `gulp`) diff --git a/package.json b/package.json index d1696281..3a24d9f5 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "test": "mocha", "build": "gulp", "watch": "gulp watch", - "watch-dev": "gulp watch-dev" + "watch-dev": "gulp watch --bundle" }, "dependencies": { "emitter-component": "^1.1.1", @@ -45,6 +45,7 @@ "rimraf": "^2.2.8", "uglify-js": "^2.4.14", "webpack": "^1.3.1-beta7", - "wrench": "latest" + "wrench": "latest", + "yargs": "^1.2.6" } }