Skip to content

Instantly share code, notes, and snippets.

@kamiyam
Last active December 18, 2015 17:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kamiyam/5820651 to your computer and use it in GitHub Desktop.
Save kamiyam/5820651 to your computer and use it in GitHub Desktop.
grunt Live Reload grunt-contrib-watch version
"use strict"
LIVERELOAD_PORT = 35729
lrSnippet = require("connect-livereload")(port: LIVERELOAD_PORT)
mountFolder = (connect, dir) ->
connect.static require("path").resolve(dir)
module.exports = (grunt) ->
grunt.initConfig
pkg: grunt.file.readJSON("package.json")
connect:
options:
port: 9001
hostname: "localhost"
livereload:
options:
middleware: (connect) ->
[lrSnippet, mountFolder(connect, ".")]
watch:
options:
nospawn: true
livereload: true
livereload:
options:
livereload: LIVERELOAD_PORT
files: ["{,*/}**.html", "styles/{,*/}**.css", "scripts/{,*/}**.js", "images/{,*/}**.{png,jpg,jpeg,gif,webp}"]
open:
server:
path: "http://localhost:<%= connect.livereload.options.port %>"
# load all grunt tasks
require("matchdep").filterDev("grunt-*").forEach grunt.loadNpmTasks
grunt.registerTask "default", ["connect", "open", "watch"]
'use strict';
var LIVERELOAD_PORT = 35729;
var lrSnippet = require('connect-livereload')({port: LIVERELOAD_PORT});
var mountFolder = function (connect, dir) {
return connect.static(require('path').resolve(dir));
};
module.exports = function(grunt){
grunt.initConfig({
pkg: grunt.file.readJSON("package.json"),
watch:{
options: {
nospawn: true,
livereload: true
},
livereload: {
options: {
livereload: LIVERELOAD_PORT
},
files: [
'{,*/}**.html',
'styles/{,*/}**.css',
'scripts/{,*/}**.js',
'images/{,*/}**.{png,jpg,jpeg,gif,webp}'
]
}
},
connect: {
options: {
port: 9001,
hostname: 'localhost'
},
livereload: {
options: {
middleware: function (connect) {
return [
lrSnippet,
mountFolder(connect, '.')
];
}
}
}
},
open: {
server: {
path: 'http://localhost:<%= connect.livereload.options.port %>'
}
}
});
// load all grunt tasks
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
grunt.registerTask("default", ["connect", "open", "watch"]);
};
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Grunt Live Reload</title>
<script src="scripts/main.js"></script>
<link rel="stylesheet" href="styles/site.css">
</head>
<body>
LiveReload!!!!!!!
</body>
</html>
{
"name": "grunt-watch",
"version": "0.0.2",
"description": "grunt watch min",
"main": "Gruntfile.js",
"dependencies": {
},
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-watch": "~0.4.4",
"grunt-contrib-connect": "~0.3.0",
"grunt-open": "~0.2.0",
"matchdep": "~0.1.2",
"connect-livereload": "~0.2.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment