From 33df1a0cfddd1e9d9a9b9512dc91ba51d60c7960 Mon Sep 17 00:00:00 2001 From: William Wung Date: Wed, 1 Apr 2015 15:00:39 -0700 Subject: [PATCH] (update) gulp file - Add tasks for watch, sass, minify-css, build, web server, replacehtml, production --- gulpfile.js | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 2 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 4a455d0..019165f 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -8,12 +8,13 @@ var reactify = require('reactify'); var streamify = require('gulp-streamify'); var server = require('gulp-server-livereload'); var sass = require('gulp-sass'); +var minifyCSS = require('gulp-minify-css'); var path = { HTML: './client/src/*.html', SASS: './client/src/sass/*.scss', CSS_OUT: './client/build/css', - CSS_MIN_OUT: 'styles.min.css', + CSS_MIN_OUT: './client/dist/public/css/styles.min.css', ENTRY_POINT: './client/src/js/App.jsx', DEST: './client/dist/public/', OUT: 'bundle.js', @@ -21,11 +22,72 @@ var path = { DEST_BUILD: './client/dist/build' }; +/* Watcher */ +gulp.task('watch', function() { + gulp.watch(path.HTML, []); + var watcher = watchify(browserify({ + entries: [path.ENTRY_POINT], + transform: [reactify], + debug: true, + cache: {}, + packageCache: {}, + fullPaths: true + })); + return watcher.on('update', function() { + watcher.bundle() + .pipe(source(path.OUT)) + .pipe(gulp.dest(path.DEST_BUILD)); + console.log('updated'); + }) + .bundle + .pipe(source(path.OUT)) + .pipe(gulp.dest(path.DEST_BUILD)); +}); /* Convert SCSS to CSS */ -gulp.task('sass', function({ +gulp.task('sass', function() { gulp.src(path.SASS) .pipe(sass()) .pipe(gulp.dest(path.CSS_OUT)); }); +/* Minify CSS */ +gulp.task('minify-css', function() { + return gulp.src(path.CSS_OUT) + .pipe(minifyCSS({keepBreaks: true})) + .pipe(gulp.dest(path.CSS_MIN_OUT)); +}); + +/* BUILD */ +gulp.task('build', function() { + browserify({ + entries: [path.ENTRY_POINT], + transform: [reactify] + }) + .bundle() + .pipe(source(path.OUT)) + .pipe(streamify(uglify(path.OUT))) + .pipe(gulp.dest(path.DEST_BUILD)); +}); + +/* Creates local web server for testing */ +gulp.task('webserver', function() { + gulp.src(path.DEST) + .pipe(server({ + livereload: true, + directoryListing: false, + defaultFile: '/index.html', + open: true + })); +}); + +/* Replace HTML */ +gulp.task('replaceHTML', function() { + gulp.src(path.HTML) + .pipe(htmlReplace({ + css: [] + })) +}); + +/* Production */ +gulp.task('production', ['sass', 'minify-css', 'replaceHTML', 'build']);