TargetableESModuleArray

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.

Kind: global class

targetableESModuleArray.addImport(importString) ⇒ undefined

Adds a module to the end of the array.

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

Kind: instance method of TargetableESModuleArray

Param Type Description
importString string A static import declaration for a module

targetableESModuleArray.add(…items) ⇒ undefined

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

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

Kind: instance method of TargetableESModuleArray

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

targetableESModuleArray.push(…importString) ⇒ undefined

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

Kind: instance method of TargetableESModuleArray

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

targetableESModuleArray.unshift(…importString) ⇒ undefined

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

Kind: instance method of TargetableESModuleArray

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

For implementation details View Source.

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
];