Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Close GH-3: Grunt 0.4 compatible implementation.
- Loading branch information
1 parent
fb81744
commit b5cbe65
Showing
11 changed files
with
363 additions
and
75 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,27 @@ | ||
{ | ||
"globals": { | ||
"before": false, | ||
"describe": false, | ||
"it": false | ||
}, | ||
"node": true, | ||
"browser": true, | ||
"es5": true, | ||
"esnext": true, | ||
"bitwise": true, | ||
"camelcase": true, | ||
"curly": true, | ||
"eqeqeq": true, | ||
"immed": true, | ||
"indent": 2, | ||
"latedef": true, | ||
"newcap": true, | ||
"noarg": true, | ||
"sub": true, | ||
"quotmark": "single", | ||
"regexp": true, | ||
"undef": true, | ||
"boss": true, | ||
"eqnull": true, | ||
"node": true, | ||
"es5": true | ||
} | ||
"unused": true, | ||
"strict": true, | ||
"trailing": true, | ||
"smarttabs": true | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Frederick Ros (https://github.com/sleeper) |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,42 @@ | ||
## Example config | ||
|
||
```javascript | ||
grunt.initConfig({ | ||
livereload: { // Task | ||
dist: { // Target | ||
options: { // Target options | ||
'use strict'; | ||
var path = require('path'); | ||
var lrSnippet = require('grunt-contrib-livereload/lib/utils').livereloadSnippet; | ||
|
||
}, | ||
files: { // Dictionary of files | ||
'dist/': 'src/' // 'destination': 'source' | ||
'dist/': 'src/' | ||
var folderMount = function folderMount(connect, point) { | ||
return connect.static(path.resolve(point)); | ||
}; | ||
|
||
module.exports = function (grunt) { | ||
// Project configuration. | ||
grunt.initConfig({ | ||
connect: { | ||
livereload: { | ||
options: { | ||
port: 9001, | ||
middleware: function(connect, options) { | ||
return [lrSnippet, folderMount(connect, '.')] | ||
} | ||
} | ||
} | ||
}, | ||
dev: { // Another target | ||
files: { | ||
'dist/': 'src/' | ||
'dist/': 'src/' | ||
// Configuration to be run (and then tested). | ||
regarde: { | ||
fred: { | ||
files: '*.txt', | ||
tasks: ['livereload'] | ||
} | ||
} | ||
} | ||
}); | ||
|
||
grunt.registerTask('default', ['livereload']); | ||
}); | ||
|
||
grunt.loadNpmTasks('grunt-regarde'); | ||
grunt.loadNpmTasks('grunt-contrib-connect'); | ||
grunt.loadNpmTasks('grunt-contrib-livereload'); | ||
|
||
grunt.registerTask('default', ['livereload-start', 'connect', 'regarde']); | ||
}; | ||
``` | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
# Options | ||
|
||
## optsion | ||
## port | ||
|
||
Type: `Boolean` | ||
Default: `false` | ||
Type: `integer` | ||
Default: `35729` | ||
|
||
Description. | ||
The port the tiny-lr server should listen on. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,49 @@ | ||
# grunt-contrib-livereload [![Build Status](https://secure.travis-ci.org/gruntjs/grunt-contrib-livereload.png?branch=master)](http://travis-ci.org/gruntjs/grunt-contrib-livereload) | ||
|
||
_This plugin is a placeholder for the upcoming live reload task._ | ||
> Reload assets live in the browser | ||
## Getting Started | ||
If you haven't used [grunt][] before, be sure to check out the [Getting Started][] guide, as it explains how to create a [gruntfile][Getting Started] as well as install and use grunt plugins. Once you're familiar with that process, install this plugin with this command: | ||
|
||
```shell | ||
npm install grunt-contrib-livereload --save-dev | ||
``` | ||
|
||
[grunt]: http://gruntjs.com/ | ||
[Getting Started]: https://github.com/gruntjs/grunt/blob/devel/docs/getting_started.md | ||
|
||
## Introduction | ||
|
||
`grunt-contrib-livereload` is composed of 2 tasks: | ||
* one to setup a local server that will serve the needed js file and the wesocket that will control your browser (`livereload-start`) | ||
* one to trigger the reload of the browser(s) (`livereload`) | ||
|
||
Additionally a connect middleware is available to insert on the fly in your HTML page the snippet of javascript that will start he connect to the livereload server. | ||
|
||
This task support multi-browser: all the browsers listening on the tiny-lr port will be reloaded at the same time. | ||
|
||
Note that `grunt-contrib-livereload` is designed to use [grunt-regarde](https://github.com/yeoman/grunt-regarde) instead `grunt-contrib-watch` (mainly due to shortcomings in the `watch` task which doesn't give access to changed files because it spawns tasks in subprocesses.) | ||
|
||
## The livereload-start task | ||
|
||
This task starts a server in the background. This server (implemented thanks to [mklabs/tiny-lr](https://github.com/mklabs/tiny-lr)) will mainly in our case: | ||
* serve the `livereload.js` | ||
* act as a websocket server: each browser that opens a websocket to this server will be refreshed | ||
|
||
By default thsi server listens on port 35729, but this can be changed through the `port` options. | ||
|
||
## The livereload task | ||
This task needs to be called to trigger a reload. It must be passed the list of files that have changed (i.e. `livereload:foo.txt:bar.txt`) | ||
|
||
## The middleware | ||
A connect middleware (`livereloadSnippet`) is delivered as an helper (located in `grunt-contrib-livereload/lib/utils`). This middleware must be the first one inserted. | ||
|
||
It will insert on the fly, in your HTML, the needed snippet of javascript that will setup the connection to the `tiny-lr` server. | ||
|
||
```html | ||
<!-- livereload snippet --> | ||
<script>document.write('<script src=\"http://' | ||
+ (location.host || 'localhost').split(':')[0] | ||
+ ':" + port + "/livereload.js?snipver=1\"><\\/script>') | ||
</script> | ||
``` |
Oops, something went wrong.