Skip to content

Instantly share code, notes, and snippets.

@3dd13
Forked from webdesserts/Gulpfile.js
Last active March 12, 2016 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save 3dd13/8193032 to your computer and use it in GitHub Desktop.
Save 3dd13/8193032 to your computer and use it in GitHub Desktop.
Adapt the gulp hot reload file and apply to partial.js directory structure. (ignored public folder at the moment)
// NOTE: I previously suggested doing this through Grunt, but had plenty of problems with
// my set up. Grunt did some weird things with scope, and I ended up using nodemon. This
// setup is now using Gulp. It works exactly how I expect it to and is WAY more concise.
var gulp = require('gulp'),
spawn = require('child_process').spawn,
node;
/**
* $ gulp server
* description: launch the server. If there's a server already running, kill it.
*/
gulp.task('server', function() {
if (node) node.kill()
node = spawn('node', ['index.js'], {stdio: 'inherit'})
node.on('close', function (code) {
if (code === 8) {
gulp.log('Error detected, waiting for changes...');
}
});
})
/**
* $ gulp
* description: start the development environment
*/
gulp.task('default', function() {
gulp.run('server')
gulp.watch(['./index.js', './controllers/**/*.js', './definitions/**/*.js', './templates/**/*.html', './views/**/*.html'], function() {
gulp.run('server')
})
// Need to watch for sass changes too? Just add another watch call!
// no more messing around with grunt-concurrent or the like. Gulp is
// async by default.
})
// clean up if an error goes unhandled.
process.on('exit', function() {
if (node) node.kill()
})
@julianbei
Copy link

Thanks for sharing this.
I have used it a lot of time, but now as I have switched to the JSCS linter, I have seen a lot of codingstyle issues in this script.
So I have forked it and fixed these issues.
I would love to see if you would update your script from my fork: Gulpfile.js
Sharing is caring. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment