Skip to content

Instantly share code, notes, and snippets.

@pixelgrid
Created October 20, 2015 09:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pixelgrid/37b6cb842479689263c8 to your computer and use it in GitHub Desktop.
Save pixelgrid/37b6cb842479689263c8 to your computer and use it in GitHub Desktop.
Gulp task for a express, nodemon, livereload, angularjs application
// watches all js and css files
// if a file is in the public folder
// runs a task based on the file extension and the file path
gulp.task("nodemon", function(){
// start livereload
livereload.listen();
nodemon({
// node app entry point
script: './index.js',
// extensions to watch changes for
ext: "js scss",
// watch folders
watch: [
'./lib/*',
'./public/js/app/*',
'./public/scss/*'
],
// pass enviromental variable to node app
env: {
'NODE_ENV': 'development'
},
// when a change is detected this function runs and returns an array of tasks
// based on file extension and file path
tasks: function(changedFiles){
var tasks = [];
changedFiles.forEach(function(file){
if(file.match(/public/)){
if (path.extname(file) === '.js' && tasks.indexOf('webpack') == -1) {
tasks.push('webpack');
}
if (path.extname(file) === '.scss' && tasks.indexOf('sass') == -1){
tasks.push('sass')
}
}
});
// push livereload to the tasks to be performed
tasks.push('livereload');
return tasks;
}
}).on('restart', function(){
console.log('Server restarted');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment