Share JavaScript Code Between LWC and Aura
To share JavaScript code between Lightning web components and Aura components, put the code in an ES6 module in a service component.
To share an ES6 module:
- Create a service component (library) using the Lightning Web Components programming model.
- To use the code in a Lightning web component, import and reference it in the component’s JavaScript file.
- To use the code in an Aura component, use the same syntax that you use to import an Aura component and call its methods. For example code, see the Aura
lightning:navigationItemAPI
component docs. Note thatlightning:navigationItemAPI
is an Aura component, not an ES6 module, but to import an ES6 module, you use the same Aura syntax.
The lwc-recipes repo has an lmsPublisherWebComponent
module that enables communication between Lightning web components and Aura components. The pubsub
module has been retired but can be used in containers such as Experience Cloud, which doesn’t support Lightning Message Service.
See Also