Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

auto-reload-brunch

brunch10.1kdeprecated3.0.1

Deprecated

Adds automatic browser reloading support to brunch.

brunchplugin, auto-reload, websocket, auto reload

readme

auto-reload-brunch

Adds automatic browser reloading support to Brunch when using the brunch watch command.

The plugin uses WebSocket technology to pass compile events to browser.

Usage

Install the plugin via npm with

npm install -S auto-reload-brunch

In most cases, auto-reload-brunch works out of the box without any further configuration. Stylesheet changes will be applied seamlessly, and any other changes will trigger a page refresh. To prevent a stylesheet from being reloaded automatically, set the data-autoreload="false" attribute on the stylesheet's link tag.

Brunch plugin settings

If customization is needed or desired, settings can be modified in your brunch config file (such as brunch-config.coffee):

  • enabled: (Boolean or Object) Defaults to true
    • As a boolean, turn on Auto-Reloading for any change in your project, or off entirely.
    • As an object, enable Auto-Reloading for specific types of changes. Keys are the file extensions of compiled files (js or css) or assets to cover any other watched files that do not get compiled. When an object is used, only the types explicitly set to true will trigger an Auto-Reload.
  • port: (Integer or Array of Integers) Defaults to [9485..9495]
    • The port to run the WebSocket server on. It will be applied automatically on the server and the client.
    • If an array, it will use the first value, but automatically fail over to the next value in the array if the attempted port is already in use on the system. This allows multiple instances to run without conflict.
  • delay: (Integer, in milliseconds) Optional, no default
    • If your system is having race-condition type problems when the browser tries to reload immediately after a compile, use this to set a delay before the reload signal is sent.
  • host: (Default: '0.0.0.0') Server's host address.
  • forceRepaint: (Default: false) forcefully repaint the page after stylesheets refresh. Enabled in Chrome by default to mitigate the issue when it doesn't always update styles.
  • keyPath: Optional, no default.
    • Path to private key used for SSL.
  • certPath: Optional, no default.
    • Path to public x509 certificate.
  • forcewss: Optional, no default.
    • make the client always use wss:// instead of ws://.

Example:

module.exports = {
  // ...
  // All settings are optional
  plugins: {
    autoReload: {
      enabled: {
        css: true,
        js: true,
        assets: false
      },
      port: [1234, 2345, 3456],
      delay: require('os').platform() === 'win32' && 200,
      keyPath: 'path/to/ssl.key',
      certPath: 'path/to/ssl.crt',
      forcewss: true
    }
  }
};

Client-side settings

If your brunch watch is running on a different machine than your preview screen, you can set server config variable to connect to a brunch/websocket server running at another ip address.

<script>
  window.brunch = window.brunch || {};
  window.brunch.server = '192.168.1.2';
</script>

You can also set the port (single integer only) and/or disable auto-reload via client-side scripting, although generally it's a better idea to use brunch config for this:

window.brunch['auto-reload'] = window.brunch['auto-reload'] || {};
window.brunch['auto-reload'].port = 1234
window.brunch['auto-reload'].disabled = true;

Custom file extensions

You can configure what extensions count as stylesheet and javascript reloads. By default, any compile file with an extension other than .css or .js will do a full page reload. The match option allows you to issue efficient stylesheet-only reloads for other file extensions as well.

The value of match.stylesheets and match.javascripts is an anymatch set, and so can be a wildcard, regexp, function, or an array thereof.

module.exports = {
  // ...
  plugins: {
    autoReload: {
      match: {
        stylesheets: ['*.css', '*.jpg', '*.png'],
        javascripts: ['*.js']
      }
    }
  }
};

License

The MIT License (MIT)

Copyright (c) 2012-2017 Paul Miller (http://paulmillr.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

changelog

auto-reload-brunch 2.1.0 (Mar 7, 2016)

  • Introduce experimental live JS reload functionality. See README for more details and caveats.

auto-reload-brunch 2.0.0 (Jan 29, 2016)

  • Updated source code & API. The plugin would now only work with Brunch 2.2 and higher.

auto-reload-brunch 1.8.1 (15 October 2015)

  • Updated ws dependency to 0.8.0

auto-reload-brunch 1.8.0 (5 June 2015)

  • Fixed invalid CSS selector.

auto-reload-brunch 1.7.8 (5 March 2015)

  • Added support for wss. Specify your SSL cert like this: keyPath and certPath
  • Added support for data-autoreload=false on <link> stylesheets.

auto-reload-brunch 1.7.7 (4 March 2015)

  • Updated ws to 0.7.
  • Added host option.
  • Added forceRepaint option.
  • Fixed repaints for the latest chrome

auto-reload-brunch 1.7.6 (26 January 2015)

  • Automatically use localhost as the host if not specified by the user and window.location.hostname does not resolve to anything.
    • Makes it work with NW.js (fka node-webkit) out of the box

auto-reload-brunch 1.7.5 (18 October 2014)

  • Fix bug with custom port arrays and recent 0.11.x versions of node.js

auto-reload-brunch 1.7.4 (26 September 2014)

  • Fix automatic port collision resolution
  • Explicitly trigger browser repaint on style updates

auto-reload-brunch 1.7.3 (27 February 2014)

  • Fix include script regression bug

auto-reload-brunch 1.7.2 (26 February 2014)

  • Updated ws module.

auto-reload-brunch 1.7.1 (2 November 2013)

  • Added delay option

auto-reload-brunch 1.7.0 (28 September 2013)

  • Automatically change port setting on client-side to match server's
  • Client auto-reconnect, so manual refresh is not needed after a brunch restart
  • Fine-grained enable settings to customize what types of changes trigger an auto-reload.
  • Port setting can be an array for automatic recovery from port conflicts

auto-reload-brunch 1.6.5 (28 August 2013)

  • Added enabled option.

auto-reload-brunch 1.6.4 (24 July 2013)

  • Handled more WebSocketServer errors.

auto-reload-brunch 1.6.3 (11 May 2013)

  • Added teardown API support.

auto-reload-brunch 1.6.2 (6 May 2013)

  • Fixed styles reloading in brunch 1.6.4+.

auto-reload-brunch 1.6.1 (18 April 2013)

  • Moved configuration to config.plugins.autoReload from config.autoReload.

auto-reload-brunch 1.6.0 (7 April 2013)

  • Enabled plugin by default.

auto-reload-brunch 1.5.2 (19 March 2013)

  • Added node 0.10 support, removed coffee-script dependency.

auto-reload-brunch 1.5.1 (30 January 2013)

  • Plugin is now disabled in production environment (w / --optimize).

auto-reload-brunch 1.5.0 (13 January 2013)

  • Improved installation process.

auto-reload-brunch 1.4.0 (26 November 2012)

  • Added ability to customize websocket server ip & port and remote server ip.

auto-reload-brunch 1.3.2 (15 July 2012)

  • Updated ws dependency to 0.4.20.

auto-reload-brunch 1.3.1 (29 June 2012)

  • Fixed config.persistent bug.

auto-reload-brunch 1.3.0 (29 June 2012)

  • Reloading became smarter. If you change stylesheet, the page itself won't be reloaded etc.
  • Added node.js 0.8 and 0.9 support.
  • Package is now precompiled before every publishing to npm.

auto-reload-brunch 1.2.0 (18 May 2012)

  • Initial release.