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

Name Type Description
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

Name Type Description
…items any Static import declaration(s)

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

Returns: ** **Parameters

Name Type Description
…importString string Static import declaration(s)

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

Returns: ** **Parameters

Name Type Description
…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.

// 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:

import * as PageBuilder from '@magento/pagebuilder';
import * as PlainHtmlRenderer from '@magento/venia-ui/lib/components/RichContent/plainHtmlRenderer';

export default [
  PageBuilder,
  PlainHtmlRenderer
];