Skip to content

Instantly share code, notes, and snippets.

@romaricpascal
Created May 14, 2013 16:18
Show Gist options
  • Save romaricpascal/5577257 to your computer and use it in GitHub Desktop.
Save romaricpascal/5577257 to your computer and use it in GitHub Desktop.
Sample configuration of grunt-contrib-connect and grunt-open to serve your project and open a browser tab to the appropriate URL
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-contrib-connect will serve the files of the project
// on specified port and hostname
connect: {
all: {
options:{
port: 9000,
hostname: "0.0.0.0",
// Prevents Grunt to close just after the task (starting the server) completes
// This will be removed later as `watch` will take care of that
keepalive: true
}
}
},
// grunt-open will open your browser at the project's URL
open: {
all: {
// Gets the port from the connect configuration
path: 'http://localhost:<%= connect.all.options.port%>'
}
}
});
// Creates the `server` task
grunt.registerTask('server',[
// Open before connect because connect uses keepalive at the moment
// so anything after connect wouldn't run
'open',
'connect'
]);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment