Last active
December 18, 2015 17:48
-
-
Save kamiyam/5820651 to your computer and use it in GitHub Desktop.
grunt Live Reload grunt-contrib-watch version
This file contains 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" | |
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"] |
This file contains 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; | |
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"]); | |
}; |
This file contains 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
<!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> |
This file contains 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
{ | |
"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