Skip to content

Instantly share code, notes, and snippets.

@adion
Last active February 16, 2019 12:12
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save adion/7580522 to your computer and use it in GitHub Desktop.
Save adion/7580522 to your computer and use it in GitHub Desktop.
Example Gruntfile for grunt-contrib-watch with livereload.
'use strict';
var
LIVERELOAD_PORT = 35729,
lrSnippet = require('connect-livereload')({ port: LIVERELOAD_PORT }),
mountFolder = function( connect, dir ) {
return connect.static(require('path').resolve(dir));
};
module.exports = function( grunt ) {
// load all grunt tasks
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-open');
grunt.initConfig({
watch: {
livereload: {
files: [
'{,*/}*.html',
'static/{,*/}*.{css,js,png,jpg,gif,svg}'
],
tasks: ['jshint'],
options: {
livereload: LIVERELOAD_PORT
}
}
},
connect: {
options: {
port: 9000,
hostname: '0.0.0.0'
},
livereload: {
options: {
middleware: function( connect ) {
return [
lrSnippet,
mountFolder(connect, './')
];
}
}
}
},
open: {
server: {
url: 'http://localhost:<%= connect.options.port %>'
}
}
});
grunt.registerTask('server', function() {
grunt.task.run([
'connect:livereload',
'open',
'watch'
]);
});
grunt.registerTask('default', [ 'server' ]);
};
@F1LT3R
Copy link

F1LT3R commented Feb 24, 2015

I was reading your Stack Overflow answer and couldn't get your Gist working. Any ideas why your sample wouldn't work out of the box? I get the Cannot GET / message when trying that this Gist.

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