Skip to content

Instantly share code, notes, and snippets.

@weralwolf
Created September 16, 2015 08:14
Show Gist options
  • Save weralwolf/d845198769d7a2b22a22 to your computer and use it in GitHub Desktop.
Save weralwolf/d845198769d7a2b22a22 to your computer and use it in GitHub Desktop.
Simple example of server with live reload for Grunt.
module.exports = function(grunt) {
require("load-grunt-tasks")(grunt); // npm install --save-dev load-grunt-tasks
grunt.initConfig({
watch: {
statics: {
files: ['index.html'],
options: {
livereload: true,
},
},
},
connect: {
server: {
options: {
useAvailablePort: true,
hostname: '*',
open: true,
livereload: true,
},
},
},
});
grunt.registerTask('serve', ['connect:server', 'watch']);
grunt.registerTask('default', ['serve']);
};
<!DOCTYPE html>
<html>
<head>
<title>Simplest example of grunt server with reload</title>
</head>
<body>
<p>
Here's nothing, but with <code>grunt serve</code> you'll create a small server with live reload.
To add more files affecting reload extend <code>watch</code> section of <code>Gruntfile.json</code>
as exampled.
</p>
</body>
</html>
{
"name": "simple-server",
"version": "1.0.0",
"description": "Simplest grunt server example with live-reload.",
"main": "index.html",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": ["grunt", "live-reload"],
"author": "Anatolii Koval",
"license": "ISC",
"dependencies": {},
"devDependencies": {
"grunt": "^0.4.5",
"grunt-contrib-connect": "^0.11.2",
"grunt-contrib-watch": "^0.6.1",
"load-grunt-tasks": "^3.2.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment