Last active
March 11, 2016 14:23
-
-
Save donhenton/d02d564790dddb4097fd to your computer and use it in GitHub Desktop.
gulp file for frontend and backend monitoring of a node app using nodemon for backend
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
var gulp = require('gulp'); | |
var sass = require('gulp-sass'); | |
var concat = require('gulp-concat'); | |
var sass = require('gulp-sass'); | |
var watch = require('gulp-watch'); | |
var livereload = require('gulp-livereload'); | |
var tap = require('gulp-tap'); | |
var nodemon = require('gulp-nodemon'); | |
var path = require('path'); | |
var gutil = require('gulp-util'); | |
var exec = require('child_process').exec; | |
var appDependencies = require('./package.json').dependencies; | |
var buildDir = '.'; | |
var publicDir = buildDir + '/public'; | |
global._publicDir = publicDir; | |
/* livereload loads this page you only get one | |
* | |
* the chrome livereload plugin needs to be installed | |
* | |
*/ | |
var pageURL = 'http://localhost:3000'; | |
/** | |
* | |
* task for pre compiling sass | |
*/ | |
//gulp.task('sass', function () { | |
// gulp.src('./sass/**/*.scss') | |
// .pipe(sass().on('error', sass.logError)) | |
// .pipe(concat('style.css')) | |
// // .pipe(uglifycss()) | |
// .pipe(gulp.dest('./public/stylesheets/')) | |
// .on('finish', function ( ) { | |
// gutil.log("processing change in css"); | |
// // livereload.reload(pageURL); | |
// }); | |
// | |
//}); | |
/** | |
* task for reloading for backend, eg route changes | |
* takes 3-4 seconds, will also pick up public css and js | |
* but is slower for refresh compared to frontend task for css and public js | |
*/ | |
gulp.task('backend', function () { | |
livereload.listen(); | |
nodemon( | |
{ | |
script: 'bin/localdev.js', | |
// watch: ['*.js'], | |
ext: 'js css jade', | |
ignore: ['./gulpfile.js','./bin/*.js'], | |
tasks: function (changedFiles) | |
{ | |
var tasks = []; | |
changedFiles.forEach(function (file) | |
{ | |
gutil.log(path.basename(file)); | |
if (path.extname(file) === '.scss' && !~tasks.indexOf('sass')) | |
{ | |
tasks.push('sass'); | |
} | |
// | |
}); | |
return tasks; | |
} | |
}).on('restart', function () | |
{ | |
gutil.log('restarted!'); | |
livereload.reload(pageURL); | |
}); | |
}); | |
/* end backend task ------------------------------------- */ | |
/* begin frontend task ---------------------------------- */ | |
/* | |
* | |
* this is a monitoring task which watch changes that DON'T | |
* involve server reboot, so will be faster on refresh | |
*/ | |
var watchItems = ['./views/**/*.jade', './public/**/*.js', './public/**/*.css']; | |
/* | |
* start server | |
*/ | |
gulp.task('server-start', function (cb) { | |
exec('node ./bin/localdev.js', function (err, stdout, stderr) { | |
console.log(stdout); | |
console.log(stderr); | |
cb(err); | |
}); | |
}); | |
gulp.task('frontend-watch', function () { | |
livereload.listen(); | |
watch(watchItems, function (events, done) { | |
console.log("processing change in watched items"); | |
livereload.reload(pageURL); | |
}); | |
// watch('./sass/**/*.scss', function (events, done) { | |
// | |
// gulp.src('./sass/**/*.scss') | |
// .pipe(sass().on('error', sass.logError)) | |
// .pipe(concat('style.css')) | |
// // .pipe(uglifycss()) | |
// .pipe(gulp.dest('./public/stylesheets/')) | |
// .on('finish', function ( ) { | |
// console.log("processing change in css"); | |
// livereload.reload(pageURL); | |
// }); | |
// | |
// }); | |
}); | |
gulp.task('frontend', ['server-start', 'frontend-watch']); | |
/* end fronend task ---------------------------------------- */ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Gulp Node Application Monitoring Script
This script will monitor a node js web application.
Backend
Monitors via node mode and will detect js, css, jade, and node js (eg route) changes. Refresh 2-4 seconds, but covers all changes
Front end
Monitors only js,css, and jade changes. very fast
localdev script
This script launches the app