UNPKG

1.28 kBTypeScriptView Raw
1import type { Plugin, PluginHooks } from 'rollup';
2
3type MapToFunction<T> = T extends Function ? T : never;
4
5export type ResolverFunction = MapToFunction<PluginHooks['resolveId']>;
6
7export interface ResolverObject {
8 buildStart?: PluginHooks['buildStart'];
9 resolveId: ResolverFunction;
10}
11
12export interface Alias {
13 find: string | RegExp;
14 replacement: string;
15 customResolver?: ResolverFunction | ResolverObject | null;
16}
17
18export interface ResolvedAlias {
19 find: string | RegExp;
20 replacement: string;
21 resolverFunction: ResolverFunction | null;
22}
23
24export interface RollupAliasOptions {
25 /**
26 * Instructs the plugin to use an alternative resolving algorithm,
27 * rather than the Rollup's resolver.
28 * @default null
29 */
30 customResolver?: ResolverFunction | ResolverObject | null;
31
32 /**
33 * Specifies an `Object`, or an `Array` of `Object`,
34 * which defines aliases used to replace values in `import` or `require` statements.
35 * With either format, the order of the entries is important,
36 * in that the first defined rules are applied first.
37 */
38 entries?: readonly Alias[] | { [find: string]: string };
39}
40
41/**
42 * 🍣 A Rollup plugin for defining aliases when bundling packages.
43 */
44export default function alias(options?: RollupAliasOptions): Plugin;