Last active
February 16, 2019 12:12
-
-
Save adion/7580522 to your computer and use it in GitHub Desktop.
Example Gruntfile for grunt-contrib-watch with livereload.
This file contains hidden or 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
'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' ]); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.