Edit in GitHubLog an issue

TargetableESModuleArray

Builds a simple ES module that imports a list of other modules you provide, and then re-exports those modules in order as an array. Useful for building extensible navigation lists, routes, strategies, etc.

This class uses export-esm-collection-loader to build the source code.

Adds a module to the end of the array.

This also acts as an alias for the push() function.

Returns: Parameters

NameTypeDescription
importString
string
A static import declaration for a module

Add a module or modules to the end of the array.

This also acts as an alias for the push() function.

Returns: Parameters

NameTypeDescription
...items
any
Static import declaration(s)

Add a module or modules to the end of the array.

Returns: Parameters

NameTypeDescription
...importString
string
Static import declaration(s)

Add a module or modules to the beginning of the array.

Returns: Parameters

NameTypeDescription
...importString
string
Static import declaration(s)

Source Code: pwa-studio/packages/pwa-buildpack/lib/WebpackTools/targetables/TargetableESModuleArray.js

Examples

Code examples for the TargetableESModuleArray class.

Export PlainHtmlRenderer and PageBuilder in a list

This example uses the TargetableESModuleArray class to add PageBuilder and PlainHtmlRenderer to the array exported by the richContentRenderers.js file.

Copied to your clipboard
// Create a TargetableESModuleArray linked to the richContentRenderers.js file
const renderers = targetable.esModuleArray(
"@magento/venia-ui/lib/components/RichContent/richContentRenderers.js"
);
// Push PageBuilder and PlainHtmlRenderer to the end of the array
renderers.push('import * as PageBuilder from "@magento/pagebuilder"');
renderers.push(
'import * as PlainHtmlRenderer from "@magento/venia-ui/lib/components/RichContent/plainHtmlRenderer"'
);

The file linked to the TargetableESModuleArray class must be a module that export an empty array. 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, richContentRenderers.js enters the bundle as:

Copied to your clipboard
import * as PageBuilder from "@magento/pagebuilder";
import * as PlainHtmlRenderer from "@magento/venia-ui/lib/components/RichContent/plainHtmlRenderer";
export default [PageBuilder, PlainHtmlRenderer];
  • Privacy
  • Terms of Use
  • Do not sell or share my personal information
  • AdChoices
Copyright © 2024 Adobe. All rights reserved.