From 80cfa8dc0ea1592d94d8e7d6572979c9a06a9145 Mon Sep 17 00:00:00 2001 From: Hyunje Alex Jun Date: Sun, 25 Jan 2015 18:52:18 +0000 Subject: [PATCH] Add a live reload task in Gulp. --- gulpfile.js | 22 ++++++++++++++++++++-- package.json | 1 + 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index ff466da..3c85ca5 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -3,6 +3,7 @@ var gulp = require('gulp') , browserify = require('browserify') , bump = require('gulp-bump') + , connect = require('gulp-connect') , jshint = require('gulp-jshint') , rename = require('gulp-rename') , rimraf = require('gulp-rimraf') @@ -37,7 +38,8 @@ gulp.task('js', ['clean:js'], function () { return gulp.src('./src/js/main.js') .pipe(browserified()) .pipe(rename('perfect-scrollbar.js')) - .pipe(gulp.dest('./out/js')); + .pipe(gulp.dest('./out/js')) + .pipe(connect.reload()); }); gulp.task('js:min', ['clean:js:min'], function () { @@ -62,7 +64,8 @@ gulp.task('sass', ['clean:css'], function () { return gulp.src('./src/css/main.scss') .pipe(sass()) .pipe(rename('perfect-scrollbar.css')) - .pipe(gulp.dest('./out/css')); + .pipe(gulp.dest('./out/css')) + .pipe(connect.reload()); }); gulp.task('sass:min', ['clean:css:min'], function () { @@ -91,4 +94,19 @@ gulp.task('bump', function () { gulp.task('release', ['bump', 'build']); gulp.task('build', ['js', 'js:min', 'sass', 'sass:min']); + +gulp.task('connect', ['build'], function () { + connect.server({ + root: __dirname, + livereload: true + }); +}); + +gulp.task('watch', function () { + gulp.watch(['src/js/**/*'], ['js']); + gulp.watch(['src/css/**/*'], ['css']); +}); + +gulp.task('serve', ['connect', 'watch']); + gulp.task('default', ['lint', 'build']); diff --git a/package.json b/package.json index 3cc8f42..e8fc920 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "browserify": "^8.1.1", "gulp": "^3.8.10", "gulp-bump": "^0.1.11", + "gulp-connect": "^2.2.0", "gulp-jshint": "^1.9.0", "gulp-rename": "^1.2.0", "gulp-rimraf": "^0.1.1",