Improved the logic flow of the gulp process for speed

This commit is contained in:
Alicia Sykes
2015-09-20 14:14:56 +01:00
parent 04321924f0
commit 80e168090c
5 changed files with 40 additions and 24 deletions

View File

@@ -4,7 +4,9 @@
* My super amazing gulp setup, does EVERYTHING cool
* possible to do to turns already awesome code into
* even more awesomely efficient code
* View very commented version at https://goo.gl/3K2sFb
*
* The Gulp tasks are divided into the files in the './tasks/' directory
* Read the build documentation at './docs/building.md'
*/
// Include gulp and require directory module
@@ -13,4 +15,4 @@ var reqdir = require('require-dir');
reqdir('./tasks'); // Include the folders containing ALL gulp tasks
gulp.task('default', ['clean', 'browser-sync']); // Default task
gulp.task('default', ['start']); // Default task

View File

@@ -1,7 +0,0 @@
express = require('express')
router = express.Router()
router.get '/', (req, res, next) ->
res.render 'page_about',
title: 'About'
pageNum: 5
module.exports = router

View File

@@ -1,9 +1,16 @@
/* Include the necessary modules */
var gulp = require('gulp');
var bSync = require('browser-sync');
var CONFIG = require('../tasks/config').CONFIG;
var runSequence = require('run-sequence');
gulp.task('browser-sync', ['nodemon', 'browserify', 'scripts', 'styles', 'test'], function () {
var CONFIG = require('../tasks/config').CONFIG;
//todo build before nodemon
gulp.task('start', function () {
runSequence('build', 'test', 'nodemon', 'browser-sync');
});
gulp.task('browser-sync', function () {
bSync.init({
files: [CONFIG.SOURCE_ROOT+'/**/*.*'],
proxy: 'http://localhost:3000',
@@ -11,13 +18,20 @@ gulp.task('browser-sync', ['nodemon', 'browserify', 'scripts', 'styles', 'test']
browser: ['google chrome'],
open: false // Don't open browser automatically - it's annoying
});
gulp.watch([
CONFIG.SOURCE_ROOT+'/**/*.{js,coffee}',
'!'+CONFIG.SOURCE_ROOT+'/**/*-{main,module}.{js,coffee}',
'models/src/**/*.{js,coffee}'],
['scripts', 'test']);
gulp.watch(CONFIG.SOURCE_ROOT+'/**/*-{main,module}.{js,coffee}', ['browserify']);
gulp.watch(CONFIG.SOURCE_ROOT+'/**/*.{css,less}', ['styles']);
gulp.watch(CONFIG.SOURCE_ROOT+"/**/*.js").on('change', bSync.reload);
/* For each CoffeeScript directory, watch, compile and reload */
CONFIG.SCRIPT_PATHS.forEach(function(path) {
gulp.watch(path.src, ['scripts']).on('change', bSync.reload);
});
/* Watch build and re-bundle browserify files */
gulp.watch(CONFIG.SOURCE_ROOT+'/**/*-{main,module}.{js,coffee}', ['browserify'])
.on('change', bSync.reload);
/* Watch compile and reload LESS, SASS and CSS */
gulp.watch(CONFIG.SOURCE_ROOT+'/**/*.{css,less}', ['styles']).on('change', bSync.reload);
/* And reload browsers when the views change too */
gulp.watch("views/**/*.jade").on('change', bSync.reload);
});

View File

@@ -5,12 +5,9 @@ var scriptPaths = require('../tasks/config').CONFIG.SCRIPT_PATHS;
/* Delete built files */
gulp.task('clean', function (cb) {
var paths = ['public/'];
scriptPaths.map(function(sp){
paths.push(sp.dest+'/*.js');
});
del(paths, cb);
});

View File

@@ -3,8 +3,18 @@ var gulp = require('gulp');
var CONFIG = require('../tasks/config').CONFIG;
/* Configure files to watch for changes - NOT USED AS BY DEFAULT */
/* Configure files to watch for changes - NOT USED BY DEFAULT TASK */
gulp.task('watch', function() {
gulp.watch(CONFIG.SOURCE_ROOT+'/**/*.{js,coffee}', ['scripts', 'browserify']);
/* For each CoffeeScript directory, watch, compile and reload */
CONFIG.SCRIPT_PATHS.forEach(function(path) {
gulp.watch(path.src, ['scripts']);
});
/* Watch build and re-bundle browserify files */
gulp.watch(CONFIG.SOURCE_ROOT+'/**/*-{main,module}.{js,coffee}', ['browserify']);
/* Watch compile and reload LESS, SASS and CSS */
gulp.watch(CONFIG.SOURCE_ROOT+'/**/*.{css,less}', ['styles']);
});