From 760469fc5f7fec0869f8746dff9a2db9c7018ed5 Mon Sep 17 00:00:00 2001 From: Keivan Beigi Date: Tue, 21 Jul 2015 19:38:46 -0700 Subject: [PATCH] Added support for live reload --- gulp/copy.js | 30 +++++++++++++++++------------- gulp/handlebars.js | 5 +++-- gulp/less.js | 4 +++- gulp/watch.js | 33 ++++++++++----------------------- gulp/webpack.js | 15 +++++---------- package.json | 6 ++++-- 6 files changed, 42 insertions(+), 51 deletions(-) diff --git a/gulp/copy.js b/gulp/copy.js index 49f60e168..ab380855d 100644 --- a/gulp/copy.js +++ b/gulp/copy.js @@ -1,27 +1,31 @@ var gulp = require('gulp'); var print = require('gulp-print'); var cache = require('gulp-cached'); +var livereload = require('gulp-livereload'); var paths = require('./paths.js'); gulp.task('copyJs', function () { - return gulp.src( - [ - paths.src.root + "polyfills.js", - paths.src.root + "JsLibraries/handlebars.runtime.js", - ]) - .pipe(cache('copyJs')) - .pipe(print()) - .pipe(gulp.dest(paths.dest.root)); + return gulp.src( + [ + paths.src.root + 'polyfills.js', + paths.src.root + 'JsLibraries/handlebars.runtime.js' + ]) + .pipe(cache('copyJs')) + .pipe(print()) + .pipe(gulp.dest(paths.dest.root)) + .pipe(livereload()); }); gulp.task('copyHtml', function () { - return gulp.src(paths.src.html) - .pipe(cache('copyHtml')) - .pipe(gulp.dest(paths.dest.root)); + return gulp.src(paths.src.html) + .pipe(cache('copyHtml')) + .pipe(gulp.dest(paths.dest.root)) + .pipe(livereload()); }); gulp.task('copyContent', function () { - return gulp.src([paths.src.content + '**/*.*', '!**/*.less']) - .pipe(gulp.dest(paths.dest.content)); + return gulp.src([paths.src.content + '**/*.*', '!**/*.less']) + .pipe(gulp.dest(paths.dest.content)) + .pipe(livereload()); }); diff --git a/gulp/handlebars.js b/gulp/handlebars.js index 482ba68f5..cd3e5b18b 100644 --- a/gulp/handlebars.js +++ b/gulp/handlebars.js @@ -3,6 +3,7 @@ var handlebars = require('gulp-handlebars'); var declare = require('gulp-declare'); var concat = require('gulp-concat'); var wrap = require("gulp-wrap"); +var livereload = require('gulp-livereload'); var path = require('path'); var streamqueue = require('streamqueue'); var stripbom = require('gulp-stripbom'); @@ -47,6 +48,6 @@ gulp.task('handlebars', function () { partialStream, coreStream ).pipe(concat('templates.js')) - - .pipe(gulp.dest(paths.dest.root)); + .pipe(gulp.dest(paths.dest.root)) + .pipe(livereload()); }); diff --git a/gulp/less.js b/gulp/less.js index a4272b425..a573f5812 100644 --- a/gulp/less.js +++ b/gulp/less.js @@ -1,6 +1,7 @@ var gulp = require('gulp'); var less = require('gulp-less'); var print = require('gulp-print'); +var livereload = require('gulp-livereload'); var paths = require('./paths'); var errorHandler = require('./errorHandler'); @@ -30,5 +31,6 @@ gulp.task('less', function () { strictImports: true })) .on('error', errorHandler.onError) - .pipe(gulp.dest(paths.dest.content)); + .pipe(gulp.dest(paths.dest.content)) + .pipe(livereload()); }); diff --git a/gulp/watch.js b/gulp/watch.js index 61d83c866..f9145a464 100644 --- a/gulp/watch.js +++ b/gulp/watch.js @@ -1,6 +1,5 @@ var gulp = require('gulp'); -//var livereload = require('gulp-livereload'); - +var livereload = require('gulp-livereload'); var paths = require('./paths.js'); @@ -10,24 +9,12 @@ require('./less.js'); require('./copy.js'); require('./webpack.js'); - -gulp.task('watch', ['jshint', 'handlebars', 'less','copyHtml', 'copyContent','copyJs'], function () { - gulp.start('webpackWatch'); - gulp.watch([paths.src.scripts, paths.src.exclude.libs], ['jshint','copyJs']); - gulp.watch(paths.src.templates, ['handlebars']); - gulp.watch([paths.src.less, paths.src.exclude.libs], ['less']); - gulp.watch([paths.src.html], ['copyHtml']); - gulp.watch([paths.src.content + '**/*.*', '!**/*.less'], ['copyContent']); -}); - -gulp.task('liveReload', ['jshint', 'handlebars', 'less', 'webPack'], function () { - var server = livereload(); - gulp.watch([ - 'app/**/*.js', - 'app/**/*.css', - 'app/index.html', - 'app/login.html' - ]).on('change', function (file) { - server.changed(file.path); - }); -}); +gulp.task('watch', ['jshint', 'handlebars', 'less', 'copyHtml', 'copyContent', 'copyJs'], function () { + livereload.listen(); + gulp.start('webpackWatch'); + gulp.watch([paths.src.scripts, paths.src.exclude.libs], ['jshint', 'copyJs']); + gulp.watch(paths.src.templates, ['handlebars']); + gulp.watch([paths.src.less, paths.src.exclude.libs], ['less']); + gulp.watch([paths.src.html], ['copyHtml']); + gulp.watch([paths.src.content + '**/*.*', '!**/*.less'], ['copyContent']); +}); \ No newline at end of file diff --git a/gulp/webpack.js b/gulp/webpack.js index a262d0e0c..22a335949 100644 --- a/gulp/webpack.js +++ b/gulp/webpack.js @@ -1,20 +1,15 @@ var gulp = require('gulp'); +var gulpWebpack = require('webpack-stream'); +var livereload = require('gulp-livereload'); -var gulpWebpack = require('gulp-webpack'); -var webpack = require('webpack'); var webpackConfig = require('../webpack.config'); - webpackConfig.devtool = "#source-map"; gulp.task('webpack', function() { - return gulp.src('main.js') - .pipe(gulpWebpack(webpackConfig, webpack)) - .pipe(gulp.dest('')); + return gulp.src('main.js').pipe(gulpWebpack(webpackConfig)).pipe(gulp.dest('')); }); gulp.task('webpackWatch', function() { - webpackConfig.watch = true; - return gulp.src('main.js') - .pipe(gulpWebpack(webpackConfig, webpack)) - .pipe(gulp.dest('')); + webpackConfig.watch = true; + return gulp.src('main.js').pipe(gulpWebpack(webpackConfig)).pipe(gulp.dest('')).pipe(livereload()); }); diff --git a/package.json b/package.json index fe9f4a4a4..474697631 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "gulp-handlebars": "3.0.1", "gulp-jshint": "1.11.2", "gulp-less": "3.0.3", + "gulp-livereload": "3.8.0", "gulp-print": "1.1.0", "gulp-replace": "0.5.3", "gulp-run": "1.6.8", @@ -34,7 +35,8 @@ "jshint-stylish": "2.0.1", "run-sequence": "1.1.1", "streamqueue": "1.1.0", - "tar.gz": "^0.1.1", - "webpack": "1.10.1" + "tar.gz": "0.1.1", + "webpack": "1.10.1", + "webpack-stream": "2.0.0" } }