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.

To share an ES6 module:

  1. Create a API module component using the Lightning Web Components programming model.
  2. To use the code in a Lightning web component, import and reference it in the component’s JavaScript file.
  3. 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 that lightning: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.

See Also