If you're using StealJS, live-reload is included by default. Skip to the Use section.
If you're using SystemJS install with NPM:
npm install system-live-reload --save-dev
live-reload requires the
system-trace extension so install that as well:
npm install system-trace --save-dev
Add the extension as a config dependency. Either via
Or your own config file:
steal.js script tag you can specify a port, otherwise
8012 will be used by default:
Using with SystemJS takes a little extra configuration. Probably you want to do this in the script tag following your use of SystemJS:
Note that a script tag for system-trace is included as well, this is because live-reload depends on that extension.
live-reload can be imported into your application. The export is a function that can be called to tap into the reload process:
;// Called after every reload cycle, re-renders the app.;// Called when this module is being unloaded, used to do cleanup.reload;
This function can be called to observe the reloading cycle:
Provide a single callback to
reload to have the callback called after the cycle is complete. In the following example we are re-rendering the main application after reloads:
Provide a moduleName to observe a specific module being reloaded. Use this when you need to reinit some behavior only when a specific module reloads:
This is a special form that calls the callback for each module that is reloaded. The first parameter is the
moduleName and the second is the
reload.dispose(callback) can be used to do cleanup when the module being defined is unloaded. If the module creates side effects, this is where you can remove those. In this example we are removing the footer because it will be re-appended when the module gets executed.
You can specify which port to use for the WebSocket connection. By default
8012 will be used.
If live-reload is unable to connect to a server it can attempt to retry on a delay. liveReloadAttempts specifies the number of times to try connecting. By default liveReloadAttempts is 1, meaning no retries will occur.
When live-reload retries to connect to a server, liveReloadRetryTimeout configures the timeout, in milliseconds, before a retry will occur.