Skip to content

dynamicImport

A one-liner helper that iterates a webpack require.context and imports every file it returns. Typically used to side-effect-import all blocks, components, or assets matching a glob — without listing them by hand.

import { dynamicImport } from '@eightshift/frontend-libs-tailwind/scripts';
dynamicImport(require.context('./../../custom', true, /assets\/index.js$/));
dynamicImport(paths);
ArgumentTypeDescription
paths__WebpackModuleApi.RequireContextThe require.context whose keys should be iterated and imported.

Returns undefined. The function exists for the side effect of importing — every matched file is executed when called.

Import every block’s editor entry:

dynamicImport(require.context('./../../custom', true, /assets\/index.js$/));

Import every component’s style entry:

dynamicImport(require.context('./../../components', true, /style\.scss$/));