UNPKG

histoire

Version:

A fast story book powered by Vite

59 lines • 3.06 kB
import type { DevEnvironment, ViteDevServer, Plugin as VitePlugin } from 'vite'; /** * Whether a module URL carries a version added by {@link createModuleVersioner}. * @param url Browser module URL. */ export declare function isHistoireModuleVersionUrl(url: string): boolean; /** * Creates a function adding a stable `?v=hst-<hash>` query to resolved ids of * modules built into the `dist/` directory of a Histoire package. * * Every sandbox iframe is its own document and imports the same ~200 Histoire * modules. In a monorepo or linked install those files resolve outside * `node_modules`, so Vite serves them `no-cache` and each document revalidates * every one of them. Versioned URLs are served immutable instead, so later * documents read them from the browser cache without a request. * * An existing `v=` query (Vite versions excluded deps in `node_modules` with * the optimizer hash) is replaced: every import of one file must produce the * same URL, or the browser would evaluate two copies of the module. Ids with * any other query (`?inline`, `?url`, ...) and non-script/style files are left * alone. * * The `salt` takes part in the version. A built module's transformed code * embeds the URLs of what it imports, optimized dependencies included, so it * may only stay cached while those URLs hold (see {@link getVersionSalt}). * * Package lookups and directory hashes are memoized for the versioner's * lifetime, so create one per dev server. */ export declare function createModuleVersioner(): (id: string, salt?: string) => string; /** * Salt of {@link createModuleVersioner} for one client environment: its * optimizer cache directory (unique per Histoire run) and browser hash. * * Built modules import optimized dependencies (`vue`, ...) through URLs under * that directory. Without the salt, a browser keeping an immutable module from * an earlier run would import that run's dependency copy next to the current * one — two Vue instances in one document. A dependency re-optimization that * changes the browser hash invalidates the whole module graph and reloads the * page, so every import is resolved again with the new salt. * @param environment Client dev environment. */ export declare function getVersionSalt(environment: DevEnvironment): string; /** * Versions a file path the way module resolution on `server` does, for URLs * written by hand into HTML documents. Identity when the server does not run * {@link createModuleVersionPlugin}. * @param server Dev server serving the URL. * @param file Absolute file path. */ export declare function versionModuleFile(server: ViteDevServer, file: string): string; /** * Dev-only plugin serving Histoire's built browser modules under versioned, * immutable URLs (see {@link createModuleVersioner}). It wraps resolution of * every client import, so static imports, dynamic imports and HTML entries * all agree on one URL per file. */ export declare function createModuleVersionPlugin(): VitePlugin; //# sourceMappingURL=module-version.d.ts.map