Created
October 20, 2015 09:21
-
-
Save pixelgrid/37b6cb842479689263c8 to your computer and use it in GitHub Desktop.
Gulp task for a express, nodemon, livereload, angularjs application
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
// 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