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$/));
Signature
dynamicImport(paths);
| Argument | Type | Description |
|---|---|---|
paths | __WebpackModuleApi.RequireContext | The 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.
Note
require.context is a webpack-specific API. If you're on Vite or another bundler, use that bundler's equivalent (e.g., import.meta.glob) instead — dynamicImport won't help there.
Common patterns
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$/));