commit 90f3b60f63a449c7f64e03856e1ce05d5b30577d
parent 13a20327179ac4f2f2513dc9106dfc3cb2bebfce
Author: Konstantin Tarkus <hello@tarkus.me>
Date: Sun, 6 Jul 2014 15:31:52 +0400
Update gulpfile.js
Diffstat:
3 files changed, 24 insertions(+), 31 deletions(-)
diff --git a/README.md b/README.md
@@ -54,7 +54,7 @@ To get started you can simply clone the repo and install the dependencies:
To compile the application and start a dev server just run:
```shell
-> gulp # or, `gulp --release`
+> gulp --watch # or, `gulp --watch --release`
```
To build the project, without starting a web server run:
diff --git a/gulpfile.js b/gulpfile.js
@@ -13,6 +13,7 @@ var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var es = require('event-stream');
var path = require('path');
+var runSequence = require('run-sequence');
var webpack = require('webpack');
var argv = require('minimist')(process.argv.slice(2));
@@ -20,14 +21,13 @@ var argv = require('minimist')(process.argv.slice(2));
var DEBUG = !argv.release;
var WATCH = Boolean(argv.watch);
+// Node.js runtime dependencies and their version numbers
var pkgs = require('./package.json').dependencies;
Object.keys(pkgs).forEach(function (key) { return pkgs[key] = pkgs[key].substring(1); });
-var bundler = webpack(require('./config/webpack.config.js')(DEBUG));
+// Configure Webpack bundler
+var bundler = webpack(require('./config/webpack.config.js')(DEBUG));
-// A cache for Gulp tasks. It is used as a workaround for Gulp's dependency resolution
-// limitations. It won't be needed anymore starting with Gulp 4.
-var task = {};
// Clean up
// -----------------------------------------------------------------------------
@@ -38,7 +38,7 @@ gulp.task('clean', function (cb) {
// Copy vendor files
// -----------------------------------------------------------------------------
-gulp.task('vendor', task.vendor = function () {
+gulp.task('vendor', function () {
return es.merge(
gulp.src('./node_modules/jquery/dist/**')
.pipe(gulp.dest('./build/vendor/jquery-' + pkgs.jquery)),
@@ -46,11 +46,10 @@ gulp.task('vendor', task.vendor = function () {
.pipe(gulp.dest('./build/fonts'))
);
});
-gulp.task('vendor:clean', ['clean'], task.vendor);
// Copy static files / assets
// -----------------------------------------------------------------------------
-gulp.task('assets', task.assets = function () {
+gulp.task('assets', function () {
return es.merge(
gulp.src('./src/assets/**')
.pipe(gulp.dest('./build')),
@@ -66,11 +65,10 @@ gulp.task('assets', task.assets = function () {
.pipe(gulp.dest('./build'))
);
});
-gulp.task('assets:clean', ['clean'], task.assets);
// CSS stylesheets
// -----------------------------------------------------------------------------
-gulp.task('styles', task.styles = function () {
+gulp.task('styles', function () {
return gulp.src('./src/styles/bootstrap.less')
.pipe($.plumber())
.pipe($.less({sourceMap: DEBUG, sourceMapBasepath: __dirname}))
@@ -78,40 +76,34 @@ gulp.task('styles', task.styles = function () {
.pipe(DEBUG ? $.util.noop() : $.minifyCss())
.pipe(gulp.dest('./build/css'));
});
-gulp.task('styles:clean', ['clean'], task.styles);
// Create JavaScript bundle
// -----------------------------------------------------------------------------
-gulp.task('bundle', ['clean'], function (cb) {
- bundler.run(function (err, stats) {
- if (err) {
- throw new $.util.PluginError('webpack', err);
- }
- $.util.log('[webpack]', stats.toString({colors: true}));
- cb();
- });
-});
-gulp.task('bundle:watch', ['clean'], function (cb) {
- bundler.watch(200, function (err, stats) {
+gulp.task('bundle', function (cb) {
+ function bundle (err, stats) {
if (err) {
throw new $.util.PluginError('webpack', err);
}
$.util.log('[webpack]', stats.toString({colors: true}));
- if (cb) {
- cb();
- cb = null;
- }
- });
+ return cb();
+ }
+
+ if (WATCH) {
+ bundler.watch(200, bundle);
+ } else {
+ bundler.run(bundle);
+ }
});
// Build the app from source code
// -----------------------------------------------------------------------------
-gulp.task('build', ['vendor:clean', 'assets:clean', 'styles:clean', 'bundle']);
-gulp.task('build:watch', ['vendor:clean', 'assets:clean', 'styles:clean', 'bundle:watch']);
+gulp.task('build', ['clean'], function (cb) {
+ runSequence(['vendor', 'assets', 'styles', 'bundle'], cb);
+});
// Launch a lightweight HTTP Server
// -----------------------------------------------------------------------------
-gulp.task('run', ['build:watch'], function (next) {
+gulp.task('serve', ['build'], function (next) {
var url = require('url');
var server = require('ecstatic')({root: './', cache: 'no-cache', showDir: true});
var port = 3000;
@@ -142,7 +134,7 @@ gulp.task('run', ['build:watch'], function (next) {
// Watch for changes in source files
// -----------------------------------------------------------------------------
-gulp.task('watch', ['run'], function () {
+gulp.task('watch', ['serve'], function () {
var path = require('path');
var lr = require('gulp-livereload');
diff --git a/package.json b/package.json
@@ -30,6 +30,7 @@
"minimist": "^0.2.0",
"protractor": "^1.0.0-rc2",
"rimraf": "^2.2.8",
+ "run-sequence": "^0.3.6",
"url-loader": "^0.5.5",
"webpack": "^1.3.1-beta6"
},