Ember CLI Live Reload Injector
raw JSON →ember-cli-inject-live-reload is an essential plugin for Ember CLI applications, responsible for injecting the necessary live-reload script into the HTML output during development. This script facilitates automatic browser refreshes upon changes to JavaScript or styling, significantly enhancing developer productivity. The current stable version is 2.1.0, though the package has seen infrequent updates, largely due to its stable and foundational role within the Ember CLI ecosystem. Its core function is to dynamically generate and serve `ember-cli-live-reload.js`, which then configures and loads `livereload.js` (provided by Ember CLI's `tiny-lr` dependency) to establish a WebSocket connection for change detection. This transparent integration is a key differentiator, as most vanilla Ember CLI apps require no explicit configuration. Users typically interact with it via `ember serve` options or `.ember-cli` configuration for advanced scenarios like reverse proxies.
Common errors
error [LiveReload] failed to connect to ws://localhost:49153/livereload ↓
ember serve is running. Check your browser's console for more specific WebSocket errors. Try specifying a different liveReloadPort (e.g., ember serve --live-reload-port=35730). If behind a proxy, configure liveReloadOptions in .ember-cli. error Refused to connect to 'ws://localhost:49153/livereload' because it violates the following Content Security Policy directive: "connect-src 'self'" ↓
config/environment.js to extend your contentSecurityPolicy settings. Add ws://localhost:49153 (or the specific LiveReload host/port) to the connect-src directive. For HTTPS environments, use wss://. error Live reload not working, no refresh on file changes, no console messages related to LiveReload. ↓
ember serve is running without the --no-live-reload flag. Check the index.html source in your browser's developer tools to confirm that the ember-cli-live-reload.js script tag is present. If it's not, ensure ember-cli-inject-live-reload is installed and liveReload is not explicitly set to false in .ember-cli. Warnings
gotcha When serving Ember CLI applications behind a reverse proxy (e.g., Nginx), the default LiveReload WebSocket connection may fail due to incorrect host or port. This requires explicit configuration. ↓
gotcha Conflicting port usage can prevent LiveReload from connecting. If another process is using the default LiveReload port (often 49153 or 35729), LiveReload will silently fail to connect. ↓
gotcha Live reload will not function if a Content Security Policy (CSP) restricts `ws:` or `wss:` connections to the LiveReload server, or if `script-src` policies prevent the injected script from running. ↓
Install
npm install ember-cli-inject-live-reload yarn add ember-cli-inject-live-reload pnpm add ember-cli-inject-live-reload Imports
- Ember CLI wrong
import { injectLiveReload } from 'ember-cli-inject-live-reload'correctember install ember-cli-inject-live-reload - Configuration wrong
import { setLiveReloadOptions } from 'ember-cli-inject-live-reload'correct// .ember-cli { "liveReloadPort": 4200, "liveReloadOptions": { "https": true } } - Disabling wrong
import { disableLiveReload } from 'ember-cli-inject-live-reload'correctember serve --no-live-reload
Quickstart
import { EmberApp } from '@ember/application';
import { createRoutes } from './router';
// This addon is typically included by default in new Ember CLI projects
// and requires no direct import or explicit setup in app.js or ember-cli-build.js
// for basic functionality.
// To start your Ember application with live reload enabled (default):
// Open your terminal in the project root and run:
// ember serve
// You can verify live reload is active by checking the browser console
// for messages like '[LiveReload] connected to ws://localhost:49153/livereload'
// and observing automatic refreshes on code changes.
// Example: Temporarily disable live reload for a specific serve command:
// ember serve --no-live-reload
// Example: Configure live reload in .ember-cli for advanced scenarios (e.g., custom port):
// // .ember-cli (JSON file in project root)
// {
// "liveReloadPort": 35729,
// "liveReloadOptions": {
// "host": "192.168.1.100",
// "https": true
// }
// }
// The following is boilerplate for an ember-cli-build.js file
// and does not directly interact with ember-cli-inject-live-reload
export default function (defaults) {
let app = new EmberApp(defaults, {
// Add options here
});
// Use `app.toTree()` to generate the final build assets
return app.toTree();
}
// This quickstart focuses on demonstrating the *presence* and *configuration* of the addon
// rather than direct code interaction, as it's an infrastructural tool.