vite-plugin-dynamic-importmap
Version:
A Vite plugin that enables dynamic importmap loading by ensuring the importmap is fetched at runtime and gets applied before any other JavaScript runs
43 lines (39 loc) • 2.09 kB
TypeScript
import { Plugin } from 'vite';
type Importmap = {
imports?: Record<string, string>;
scopes?: Record<string, Record<string, string>>;
integrity?: Record<string, string>;
};
type Options = {
/**
* Configure how the importmap should be resolved during runtime.
*
* You can provide one of the following types:
*
* - `string`: A URL pointing to the importmap. The importmap will be fetched from that URL at runtime.
* - `function`: A function that returns an {@link Importmap} or Promise<{@link Importmap}>.
* This function will be serialized and inlined to be called during runtime.
* Keep this function small and self-contained, as the outside scope will not be available after serialization.
* Also note that due to how the function is being serialized, it must refer to a regular function (function expression or arrow function).
* A method defined using the shorthand syntax is not supported.
* - `Importmap`: A static importmap that is already known at buildtime.
*/
importmap: string | (() => Importmap | Promise<Importmap>) | Importmap;
/**
* Enables the possibility to apply an importmap override at runtime.
*
* When this option is enabled, `localStorage.getItem("importmap")` is checked to see whether an importmap override is present.
* If an importmap is found in `localStorage`, it will take precedence over dynamically loading the importmap.
* This allows for dynamic overrides of the importmap on client side and can easily be integrated into your development / debugging setup.
*
* Set to `false` to always dynamically load the importmap, regardless of any override in `localStorage`.
*
* **default**: `true`
*/
respectOverride?: boolean;
};
/**
* A Vite plugin that enables dynamic importmap loading by ensuring the importmap is fetched at runtime and gets applied before any other JavaScript runs.
*/
declare function dynamicImportmap(options: Options): Plugin;
export { type Options, dynamicImportmap as default, dynamicImportmap };