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
importStringstringA 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
...itemsanyStatic import declaration(s)

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

Returns: Parameters

NameTypeDescription
...importStringstringStatic import declaration(s)

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

Returns: Parameters

NameTypeDescription
...importStringstringStatic 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
1// Create a TargetableESModuleArray linked to the richContentRenderers.js file
2const renderers = targetable.esModuleArray(
3 "@magento/venia-ui/lib/components/RichContent/richContentRenderers.js"
4);
5
6// Push PageBuilder and PlainHtmlRenderer to the end of the array
7renderers.push('import * as PageBuilder from "@magento/pagebuilder"');
8renderers.push(
9 'import * as PlainHtmlRenderer from "@magento/venia-ui/lib/components/RichContent/plainHtmlRenderer"'
10);

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
1import * as PageBuilder from "@magento/pagebuilder";
2import * as PlainHtmlRenderer from "@magento/venia-ui/lib/components/RichContent/plainHtmlRenderer";
3
4export default [PageBuilder, PlainHtmlRenderer];
  • Privacy
  • Terms of Use
  • Do not sell my personal information
  • AdChoices
Copyright © 2022 Adobe. All rights reserved.