TargetableESModuleObject
Builds a simple ES module that imports a list of other modules you provide, and then re-exports those modules as an object with properties matching the imported bindings. Useful for building named lists and associative arrays when making extension points.
Uses export-esm-collection-loader to build source code.
Adds a module to the object using the addImport()
method from TargetableESModule.
Since, all imports must be exported, this method performs additional validation.
Chainable
Returns:
Parameters
Name | Type | Description |
---|---|---|
importString | string | A static import declaration |
Adds a module or modules to the object using the addImport()
function.
Chainable
Returns:
Parameters
Name | Type | Description |
---|---|---|
...args | string | Static import declaration(s) |
Source Code: pwa-studio/packages/pwa-buildpack/lib/WebpackTools/targetables/TargetableESModuleObject.js
Examples
Code examples for the TargetableESModuleObject
class.
Export three button styles in a mapping
Pass in import statements to the add()
function to import that module into the target file and add it to the exported object.
Copied to your clipboard// Create a TargetableESModuleObject linked to the `button.js` fileconst buttons = targetable.esModuleArray("path/to/buttons.js");// Add import statementsbuttons.add("import Primary from './path/to/Primary'");buttons.add("import { Button as Simple } from './path/to/simple'");buttons.add("import Secondary from './path/to/Standard'");
The file linked to the TargetableESModuleObject
class must be a module that export an empty object.
Without the module, the loader has nothing to "load" and will not execute.
Code editors and linters may also complain if the module is missing.
After the transforms above, ./path/to/button.js
enters the bundle as:
Copied to your clipboardimport Primary from './path/to/Primary');import { Button as Simple } from './path/to/simple');import { Secondary } from './path/to/Standard');export default { Primary, Simple, Secondary };