Vizel API / core/src / createLazyLoader
Function: createLazyLoader()
ts
function createLazyLoader<T>(moduleName, importFn): () => Promise<T>;Defined in: packages/core/src/utils/lazy-import.ts:29
Creates a lazy loader for an optional dependency. Caches the loaded module to avoid repeated dynamic imports.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type | Description |
|---|---|---|
moduleName | string | The npm package name (used in error messages) |
importFn | () => Promise<T> | A function that performs the dynamic import |
Returns
A function that returns a Promise of the loaded module
() => Promise<T>
Example
ts
const loadMermaid = createLazyLoader("mermaid", async () => {
const mod = await import("mermaid");
return mod.default;
});
// Later, when needed:
const mermaid = await loadMermaid();