@eik/esbuild-plugin
Version:
esbuild plugin for loading import maps from a Eik server and applying the mapping to ECMAScript modules in preparation for upload to the same server.
74 lines (73 loc) • 1.86 kB
TypeScript
/**
* @typedef {object} ImportMap
* @property {Record<string, string>} imports
*/
/**
* @typedef {object} LoadOptions
* @property {string} [path=process.cwd()]
* @property {string[]} [urls=[]] URLs to import maps hosted on an Eik server. Takes precedence over `eik.json`.
* @property {ImportMap[]} [maps=[]] Inline import maps that should be used. Takes precedence over `urls` and `eik.json`.
*/
/**
* Loads an Eik configuration or import maps directly for the plugn to use.
* Call before building.
*
* @param {LoadOptions} options
* @returns {Promise<void>}
* @example
* ```js
* import * as eik from "@eik/esbuild-plugin";
* import esbuild from "esbuild";
*
* await eik.load();
* await esbuild.build({
* plugins: [eik.plugin()],
* });
* ```
*/
export function load({ path, maps, urls, }?: LoadOptions): Promise<void>;
/**
* Clear the loaded import maps from the plugins internal cache.
*
* @returns {void}
*/
export function clear(): void;
/**
* @typedef {object} Plugin
* @property {string} name
* @property {(build: any) => void} setup
*/
/**
* Returns the plugin which will apply the loaded import maps during build.
*
* @returns {Plugin}
* @example
* ```js
* import * as eik from "@eik/esbuild-plugin";
* import esbuild from "esbuild";
*
* await eik.load();
* await esbuild.build({
* plugins: [eik.plugin()],
* });
* ```
*/
export function plugin(): Plugin;
export type ImportMap = {
imports: Record<string, string>;
};
export type LoadOptions = {
path?: string;
/**
* URLs to import maps hosted on an Eik server. Takes precedence over `eik.json`.
*/
urls?: string[];
/**
* Inline import maps that should be used. Takes precedence over `urls` and `eik.json`.
*/
maps?: ImportMap[];
};
export type Plugin = {
name: string;
setup: (build: any) => void;
};