Docs for livereload.

Purposely omitting docs for use with connect as it is extremely verbose.
Need to discuss if its worth creating a lib for a livereload connect middleware.
This commit is contained in:
Kyle Robinson Young 2013-05-01 13:14:13 -07:00
parent 5a4ba98254
commit 044f6a7704
2 changed files with 81 additions and 0 deletions

View File

@ -88,6 +88,66 @@ grunt.event.on('watch', function(action, filepath) {
});
```
## Live Reloading
Live reloading is built into the watch task. Set the option `livereload` to `true` to enable on the default port `35729` or set to a custom port: `livereload: 1337`.
The simplest way to add live reloading to all your watch targets is by setting `livereload` to `true` at the task level. This will run a single live reload server and trigger the live reload for all your watch targets:
```js
grunt.initConfig({
watch: {
options: {
livereload: true,
},
css: {
files: ['public/scss/*.scss'],
tasks: ['compass'],
},
},
});
```
You can also configure live reload for individual watch targets or run multiple live reload servers. Just be sure if you're starting multiple servers they operate on different ports:
```js
grunt.initConfig({
watch: {
css: {
files: ['public/scss/*.scss'],
tasks: ['compass'],
options: {
// Start a live reload server on the default port 35729
livereload: true,
},
},
another: {
files: ['lib/*.js'],
tasks: ['anothertask'],
options: {
// Start another live reload server on port 1337
livereload: 1337,
},
},
dont: {
files: ['other/stuff/*'],
tasks: ['dostuff'],
},
},
});
```
### Enabling Live Reload in Your HTML
Once you've started a live reload server you'll be able to access the live reload script. To enable live reload on your page, add a script tag before your closing `</body>` tag pointing to the `livereload.js` script:
```html
<script src="http://localhost:35729/livereload.js"></script>
```
### Using Live Reload with the Browser Extension
Instead of adding a script tag to your page, you can live reload your page by installing a browser extension. Please visit [how do I install and use the browser extensions](http://feedback.livereload.com/knowledgebase/articles/86242-how-do-i-install-and-use-the-browser-extensions-) for help installing an extension for your browser.
Once installed please use the default live reload port `35729` and the browser extension will automatically reload your page without needing the `<script>` tag.
# FAQs
## How do I fix the error `EMFILE: Too many opened files.`?

View File

@ -99,3 +99,24 @@ Type: `Boolean`
Default: true
This is *only a task level option* and cannot be configured per target. By default the watch task will duck punch `grunt.fatal` and `grunt.warn` to try and prevent them from exiting the watch process. If you don't want `grunt.fatal` and `grunt.warn` to be overridden set the `forever` option to `false`.
## options.livereload
Type: `Boolean|Number|Object`
Default: false
Set to `true` or set `livereload: 1337` to a port number to enable live reloading. Default and recommended port is `35729`.
If enabled a live reload server will be started with the watch task per target. Then after the indicated tasks have ran, the live reload server will be triggered with the modified files.
Example:
```js
watch: {
css: {
files: '**/*.sass',
tasks: ['sass'],
options: {
livereload: true,
},
},
},
```