Created
February 28, 2014 16:13
-
-
Save malixsys/9273840 to your computer and use it in GitHub Desktop.
Express AngularJS Browserify Gulpfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
/** | |
* Module dependencies | |
*/ | |
var gulp = require('gulp'); | |
var gutil = require('gulp-util'); | |
var lr = require('tiny-lr'); | |
var server = lr(); | |
var browserify = require('gulp-browserify'); | |
var spawn = require('child_process').spawn; | |
var concat = require('gulp-concat'); | |
var plumber = require('gulp-plumber'); | |
var refresh = require('gulp-livereload'); | |
var sections = ['anonymous','admin','user']; | |
sections.forEach(function(section){ | |
gulp.task(section, function(cb) { | |
//single entry point to browserify | |
return gulp.src(['./client/' + section + '/' + section + '.js']) | |
.pipe(plumber(true)) | |
.pipe(browserify({ | |
insertGlobals: true, | |
debug: true | |
}).on('error', function(){ | |
gutil.log(gutil.colors.red('**************** ERROR ****************'), arguments); | |
cb(); | |
})) | |
.pipe(concat(section + '.js')) | |
.pipe(gulp.dest('./www/js')) | |
.pipe(refresh(server)); | |
; | |
}); | |
}); | |
// lr-server | |
gulp.task('lr-server', function() { | |
server.listen(35729, function(err) { | |
if (err) { | |
gutil.log(gutil.colors.red('ERROR'), err); | |
return; | |
} | |
}); | |
}); | |
gulp.task('html', function() { | |
gulp.src(["www/*.html"]) | |
.pipe(refresh(server)); | |
}); | |
gulp.task('nodemon', function(cb) { | |
spawn('./node_modules/.bin/nodemon', ['--watch', 'server', 'server/server.js', '--ext','js,coffee'], { | |
stdio: 'inherit' | |
}) | |
.on('close', function() { | |
cb(); | |
}); | |
}); | |
gulp.task('default', function() { | |
gulp.run.apply(gulp, ['lr-server', 'nodemon'].concat(sections)); | |
gulp.watch('client/common/**/*.js', function(evt) { | |
gutil.log(gutil.colors.cyan('common'), 'changed'); | |
gulp.run.apply(gulp, sections); | |
}); | |
sections.forEach(function(section){ | |
gulp.watch('client/' + | |
section + | |
'/**/*.js', function(evt) { | |
gutil.log(gutil.colors.cyan(section), 'changed'); | |
gulp.run(section); | |
}); | |
}); | |
gulp.watch('www/css/**/*.css', function(evt) { | |
gutil.log(gutil.colors.cyan('css'), 'changed'); | |
server.changed({ | |
body: { | |
files: [evt.path] | |
} | |
}); | |
}); | |
gulp.watch('www/**/*.html', function(evt) { | |
gulp.run('html'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment