Lightning Web Runtime :: Application Initialization
The lwr/init
module provides APIs which are responsible for:
- importing static application dependencies
- defining the root application component into the
CustomElementRegistry
This results in the root application component being renderable by the DOM on first page load.
Definition
interface InitAPI {
init(rootAppSpecifier: string, rootApp: LightningElement): void;
}
Usage
import { init } from 'lwr/init';
import xAppRoot from 'x/appRoot';
init('x/appRoot', xAppRoot);
Configuration
The default lwr/init
module used by an LWR application can be overridden with these steps:
- Create a module exporting an
init
function which implements the InitAPI
interface:
export function init(rootAppSpecifier, rootApp) {
const elementName = rootAppSpecifier.replace(/\//, '-');
customElements.define(elementName, rootApp.CustomElementConstructor);
}
- Configure the module specifier in lwr.config.json:
{
"modules": [],
"application": {
"root": "example/app",
"init": "example/init"
}
}