UNPKG

4.7 kBMarkdownView Raw
1## auto-reload-brunch
2Adds automatic browser reloading support to
3[brunch](http://brunch.io) when using the `brunch watch` command.
4
5The plugin uses WebSocket technology to pass `compile` events to browser.
6
7## Installation
8Install the plugin via npm with `npm install --save auto-reload-brunch`.
9
10Or, do manual install:
11
12* Add `"auto-reload-brunch": "x.y.z"` to `package.json` of your brunch app.
13 Pick a plugin version that corresponds to your minor (y) brunch version.
14* If you want to use git version of plugin, add
15`"auto-reload-brunch": "git+ssh://git@github.com:brunch/auto-reload-brunch.git"`.
16
17## Usage
18In most cases, auto-reload-brunch works out of the box without any further
19configuration. Stylesheet changes will be applied seamlessly, and any other
20changes will trigger a page refresh. To prevent a stylesheet from being reloaded
21automatically, set the ```data-autoreload="false"``` attribute on the stylesheet's
22link tag.
23
24### Brunch plugin settings
25If customization is needed or desired, settings can be modified in your brunch
26config file (such as `brunch-config.coffee`):
27
28* __enabled__: _(Boolean or Object)_ Defaults to `true`
29 * As a boolean, turn on Auto-Reloading for any change in your project, or
30 off entirely.
31 * As an object, enable Auto-Reloading for specific types of changes. Keys
32 are the file extensions of compiled files (`js` or `css`) or `assets` to
33 cover any other watched files that do not get compiled. When an object is
34 used, only the types explicitly set to `true` will trigger an Auto-Reload.
35* __port__: _(Integer or Array of Integers)_ Defaults to `[9485..9495]`
36 * The port to run the WebSocket server on. It will be applied automatically
37 on the server and the client.
38 * If an array, it will use the first value, but automatically fail over to
39 the next value in the array if the attempted port is already in use on the
40 system. This allows multiple instances to run without conflict.
41* __delay__: _(Integer, in milliseconds)_ Optional, no default
42 * If your system is having race-condition type problems when the browser
43 tries to reload immediately after a compile, use this to set a delay
44 before the reload signal is sent.
45* __host__: (Default: '0.0.0.0') Server's host address.
46* __forceRepaint__: (Default: false) forcefully repaint the page after stylesheets
47 refresh. Enabled in Chrome by default to mitigate the issue when it doesn't
48 always update styles.
49* __keyPath__: Optional, no default.
50 * Path to private key used for SSL.
51* __certPath__: Optional, no default.
52 * Path to public x509 certificate.
53
54**Example:**
55```coffeescript
56exports.config =
57 ...
58 # Every setting is optional.
59 plugins:
60 autoReload:
61 enabled:
62 css: on
63 js: on
64 assets: off
65 port: [1234, 2345, 3456]
66 delay: 200 if require('os').platform() is 'win32'
67 keyPath: 'path/to/ssl.key'
68 certPath: 'path/to/ssl.crt'
69```
70
71### Client-side settings
72If your `brunch watch` is running on a different machine than your
73preview screen, you can set `server` config variable to connect to a
74brunch/websocket server running at another ip address.
75
76```html
77<script>
78 window.brunch = window.brunch || {};
79 window.brunch.server = '192.168.1.2';
80</script>
81```
82
83You can also set the port (single integer only) and/or disable auto-reload
84via client-side scripting, although generally it's a better idea to use
85brunch config for this:
86
87```javascript
88window.brunch['auto-reload'].port = 1234
89window.brunch['auto-reload'].disabled = true;
90```
91
92## License
93
94The MIT License (MIT)
95
96Copyright (c) 2012-2013 Paul Miller (http://paulmillr.com)
97
98Permission is hereby granted, free of charge, to any person obtaining a copy
99of this software and associated documentation files (the "Software"), to deal
100in the Software without restriction, including without limitation the rights
101to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
102copies of the Software, and to permit persons to whom the Software is
103furnished to do so, subject to the following conditions:
104
105The above copyright notice and this permission notice shall be included in
106all copies or substantial portions of the Software.
107
108THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
109IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
110FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
111AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
112LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
113OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
114THE SOFTWARE.