Skip to content

Instantly share code, notes, and snippets.

@romaricpascal
Last active December 20, 2015 04:59
Show Gist options
  • Save romaricpascal/6075230 to your computer and use it in GitHub Desktop.
Save romaricpascal/6075230 to your computer and use it in GitHub Desktop.
Gruntfile configuring grunt-express, grunt-contrib-watch and grunt-open with livereload as explained in my Grunt & livereload article: http://rhumaric.com/2013/07/renewing-the-g…vereload-magic/
// Gruntfile with the configuration of grunt-express and grunt-open. No livereload yet!
module.exports = function(grunt) {
// Load Grunt tasks declared in the package.json file
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
// Configure Grunt
grunt.initConfig({
// grunt-express will serve the files from the folders listed in `bases`
// on specified `port` and `hostname`
express: {
all: {
options: {
port: 9000,
hostname: "0.0.0.0",
bases: [__dirname], // Replace with the directory you want the files served from
// Make sure you don't use `.` or `..` in the path as Express
// is likely to return 403 Forbidden responses if you do
// http://stackoverflow.com/questions/14594121/express-res-sendfile-throwing-forbidden-error
livereload: true
}
}
},
// grunt-watch will monitor the projects files
watch: {
all: {
// Replace with whatever file you want to trigger the update from
// Either as a String for a single entry
// or an Array of String for multiple entries
// You can use globing patterns like `css/**/*.css`
// See https://github.com/gruntjs/grunt-contrib-watch#files
files: 'index.html',
options: {
livereload: true
}
}
},
// grunt-open will open your browser at the project's URL
open: {
all: {
// Gets the port from the connect configuration
path: 'http://localhost:<%= express.all.options.port%>'
}
}
});
// Creates the `server` task
grunt.registerTask('server', [
'express',
'open',
'watch'
]);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment