@rollipop/rolldown 0.0.0 → 1.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +25 -0
- package/README.md +11 -1
- package/bin/cli.mjs +3 -0
- package/dist/cli-setup.d.mts +1 -0
- package/dist/cli-setup.mjs +17 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +1588 -0
- package/dist/config.d.mts +10 -0
- package/dist/config.mjs +14 -0
- package/dist/experimental-index.d.mts +181 -0
- package/dist/experimental-index.mjs +266 -0
- package/dist/experimental-runtime-types.d.ts +103 -0
- package/dist/filter-index.d.mts +197 -0
- package/dist/filter-index.mjs +369 -0
- package/dist/get-log-filter.d.mts +7 -0
- package/dist/get-log-filter.mjs +48 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.mjs +57 -0
- package/dist/parallel-plugin-worker.d.mts +1 -0
- package/dist/parallel-plugin-worker.mjs +32 -0
- package/dist/parallel-plugin.d.mts +14 -0
- package/dist/parallel-plugin.mjs +7 -0
- package/dist/parse-ast-index.d.mts +8 -0
- package/dist/parse-ast-index.mjs +4 -0
- package/dist/plugins-index.d.mts +30 -0
- package/dist/plugins-index.mjs +40 -0
- package/dist/shared/binding-B92Lq__Q.d.mts +1687 -0
- package/dist/shared/binding-tNJoEqAa.mjs +585 -0
- package/dist/shared/bindingify-input-options-CfhrNd_y.mjs +2233 -0
- package/dist/shared/constructors--k1uxZrh.d.mts +28 -0
- package/dist/shared/constructors-414MPkgB.mjs +61 -0
- package/dist/shared/define-config-BVG4QvnP.mjs +7 -0
- package/dist/shared/define-config-D8xP5iyL.d.mts +3463 -0
- package/dist/shared/load-config-Qtd9pHJ5.mjs +114 -0
- package/dist/shared/logging-wIy4zY9I.d.mts +50 -0
- package/dist/shared/logs-NH298mHo.mjs +183 -0
- package/dist/shared/misc-CCZIsXVO.mjs +22 -0
- package/dist/shared/normalize-string-or-regex-DeB7vQ75.mjs +61 -0
- package/dist/shared/parse-ast-index-BcP4Ts_P.mjs +99 -0
- package/dist/shared/prompt-tlfjalEt.mjs +847 -0
- package/dist/shared/rolldown-BMzJcmQ7.mjs +42 -0
- package/dist/shared/rolldown-build-DWeKtJOy.mjs +2371 -0
- package/dist/shared/watch-HmN4U4B9.mjs +379 -0
- package/package.json +128 -2
- package/.editorconfig +0 -10
- package/.gitattributes +0 -4
|
@@ -0,0 +1,3463 @@
|
|
|
1
|
+
import { a as RolldownLog, i as RolldownError, n as LogLevelOption, o as RolldownLogWithString, r as LogOrStringHandler, t as LogLevel } from "./logging-wIy4zY9I.mjs";
|
|
2
|
+
import { L as TransformOptions$1, N as ParserOptions, O as JsxOptions, P as PreRenderedChunk, T as ExternalMemoryStatus, a as BindingHookResolveIdExtraArgs, c as BindingPluginContextResolveOptions, f as BindingTransformHookExtraArgs, k as MinifyOptions$1, s as BindingMagicString, t as BindingBuiltinPluginName, u as BindingRenderedChunk, w as BindingWatcherBundler } from "./binding-B92Lq__Q.mjs";
|
|
3
|
+
import { TopLevelFilterExpression } from "@rollipop/rolldown-pluginutils";
|
|
4
|
+
import { Program } from "@oxc-project/types";
|
|
5
|
+
|
|
6
|
+
//#region src/types/misc.d.ts
|
|
7
|
+
/** @inline */
|
|
8
|
+
type SourcemapPathTransformOption = (relativeSourcePath: string, sourcemapPath: string) => string;
|
|
9
|
+
/** @inline */
|
|
10
|
+
type SourcemapIgnoreListOption = (relativeSourcePath: string, sourcemapPath: string) => boolean;
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/types/module-info.d.ts
|
|
13
|
+
/** @category Plugin APIs */
|
|
14
|
+
interface ModuleInfo extends ModuleOptions {
|
|
15
|
+
/**
|
|
16
|
+
* @hidden Not supported by Rolldown
|
|
17
|
+
*/
|
|
18
|
+
ast: any;
|
|
19
|
+
/**
|
|
20
|
+
* The source code of the module.
|
|
21
|
+
*
|
|
22
|
+
* `null` if external or not yet available.
|
|
23
|
+
*/
|
|
24
|
+
code: string | null;
|
|
25
|
+
/**
|
|
26
|
+
* The id of the module for convenience
|
|
27
|
+
*/
|
|
28
|
+
id: string;
|
|
29
|
+
/**
|
|
30
|
+
* The ids of all modules that statically import this module.
|
|
31
|
+
*/
|
|
32
|
+
importers: string[];
|
|
33
|
+
/**
|
|
34
|
+
* The ids of all modules that dynamically import this module.
|
|
35
|
+
*/
|
|
36
|
+
dynamicImporters: string[];
|
|
37
|
+
/**
|
|
38
|
+
* The module ids statically imported by this module.
|
|
39
|
+
*/
|
|
40
|
+
importedIds: string[];
|
|
41
|
+
/**
|
|
42
|
+
* The module ids dynamically imported by this module.
|
|
43
|
+
*/
|
|
44
|
+
dynamicallyImportedIds: string[];
|
|
45
|
+
/**
|
|
46
|
+
* All exported variables
|
|
47
|
+
*/
|
|
48
|
+
exports: string[];
|
|
49
|
+
/**
|
|
50
|
+
* Whether this module is a user- or plugin-defined entry point.
|
|
51
|
+
*/
|
|
52
|
+
isEntry: boolean;
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region src/utils/asset-source.d.ts
|
|
56
|
+
/** @inline */
|
|
57
|
+
type AssetSource = string | Uint8Array;
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region src/types/external-memory-handle.d.ts
|
|
60
|
+
declare const symbolForExternalMemoryHandle: "__rolldown_external_memory_handle__";
|
|
61
|
+
/**
|
|
62
|
+
* Interface for objects that hold external memory that can be explicitly freed.
|
|
63
|
+
*/
|
|
64
|
+
interface ExternalMemoryHandle {
|
|
65
|
+
/**
|
|
66
|
+
* Frees the external memory held by this object.
|
|
67
|
+
* @param keepDataAlive - If true, evaluates all lazy fields before freeing memory.
|
|
68
|
+
* This will take time but prevents errors when accessing properties after freeing.
|
|
69
|
+
* @returns Status object with `freed` boolean and optional `reason` string.
|
|
70
|
+
* @internal
|
|
71
|
+
*/
|
|
72
|
+
[symbolForExternalMemoryHandle]: (keepDataAlive?: boolean) => ExternalMemoryStatus;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Frees the external memory held by the given handle.
|
|
76
|
+
*
|
|
77
|
+
* This is useful when you want to manually release memory held by Rust objects
|
|
78
|
+
* (like `OutputChunk` or `OutputAsset`) before they are garbage collected.
|
|
79
|
+
*
|
|
80
|
+
* @param handle - The object with external memory to free
|
|
81
|
+
* @param keepDataAlive - If true, evaluates all lazy fields before freeing memory (default: false).
|
|
82
|
+
* This will take time to copy data from Rust to JavaScript, but prevents errors
|
|
83
|
+
* when accessing properties after the memory is freed.
|
|
84
|
+
* @returns Status object with `freed` boolean and optional `reason` string.
|
|
85
|
+
* - `{ freed: true }` if memory was successfully freed
|
|
86
|
+
* - `{ freed: false, reason: "..." }` if memory couldn't be freed (e.g., already freed or other references exist)
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* import { freeExternalMemory } from '@rollipop/rolldown/experimental';
|
|
91
|
+
*
|
|
92
|
+
* const output = await bundle.generate();
|
|
93
|
+
* const chunk = output.output[0];
|
|
94
|
+
*
|
|
95
|
+
* // Use the chunk...
|
|
96
|
+
*
|
|
97
|
+
* // Manually free the memory (fast, but accessing properties after will throw)
|
|
98
|
+
* const status = freeExternalMemory(chunk); // { freed: true }
|
|
99
|
+
* const statusAgain = freeExternalMemory(chunk); // { freed: false, reason: "Memory has already been freed" }
|
|
100
|
+
*
|
|
101
|
+
* // Keep data alive before freeing (slower, but data remains accessible)
|
|
102
|
+
* freeExternalMemory(chunk, true); // Evaluates all lazy fields first
|
|
103
|
+
* console.log(chunk.code); // OK - data was copied to JavaScript before freeing
|
|
104
|
+
*
|
|
105
|
+
* // Without keepDataAlive, accessing chunk properties after freeing will throw an error
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
declare function freeExternalMemory(handle: ExternalMemoryHandle, keepDataAlive?: boolean): ExternalMemoryStatus;
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region src/types/rolldown-output.d.ts
|
|
111
|
+
/**
|
|
112
|
+
* The information about an asset in the generated bundle.
|
|
113
|
+
*
|
|
114
|
+
* @category Plugin APIs
|
|
115
|
+
*/
|
|
116
|
+
interface OutputAsset extends ExternalMemoryHandle {
|
|
117
|
+
type: "asset";
|
|
118
|
+
/** The file name of this asset. */
|
|
119
|
+
fileName: string;
|
|
120
|
+
/** @deprecated Use {@linkcode originalFileNames} instead. */
|
|
121
|
+
originalFileName: string | null;
|
|
122
|
+
/** The list of the absolute paths to the original file of this asset. */
|
|
123
|
+
originalFileNames: string[];
|
|
124
|
+
/** The content of this asset. */
|
|
125
|
+
source: AssetSource;
|
|
126
|
+
/** @deprecated Use {@linkcode names} instead. */
|
|
127
|
+
name: string | undefined;
|
|
128
|
+
names: string[];
|
|
129
|
+
}
|
|
130
|
+
/** @category Plugin APIs */
|
|
131
|
+
interface SourceMap {
|
|
132
|
+
file: string;
|
|
133
|
+
mappings: string;
|
|
134
|
+
names: string[];
|
|
135
|
+
sources: string[];
|
|
136
|
+
sourcesContent: string[];
|
|
137
|
+
version: number;
|
|
138
|
+
debugId?: string;
|
|
139
|
+
x_google_ignoreList?: number[];
|
|
140
|
+
toString(): string;
|
|
141
|
+
toUrl(): string;
|
|
142
|
+
}
|
|
143
|
+
/** @category Plugin APIs */
|
|
144
|
+
interface RenderedModule {
|
|
145
|
+
readonly code: string | null;
|
|
146
|
+
renderedLength: number;
|
|
147
|
+
renderedExports: string[];
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* The information about the chunk being rendered.
|
|
151
|
+
*
|
|
152
|
+
* Unlike {@link OutputChunk}, `code` and `map` are not set as the chunk has not been rendered yet.
|
|
153
|
+
* All referenced chunk file names in each property that would contain hashes will contain hash placeholders instead.
|
|
154
|
+
*
|
|
155
|
+
* @category Plugin APIs
|
|
156
|
+
*/
|
|
157
|
+
interface RenderedChunk extends Omit<BindingRenderedChunk, "modules"> {
|
|
158
|
+
type: "chunk";
|
|
159
|
+
/** Information about the modules included in this chunk. */
|
|
160
|
+
modules: {
|
|
161
|
+
[id: string]: RenderedModule;
|
|
162
|
+
};
|
|
163
|
+
/** The name of this chunk, which is used in naming patterns. */
|
|
164
|
+
name: string;
|
|
165
|
+
/** Whether this chunk is a static entry point. */
|
|
166
|
+
isEntry: boolean;
|
|
167
|
+
/** Whether this chunk is a dynamic entry point. */
|
|
168
|
+
isDynamicEntry: boolean;
|
|
169
|
+
/** The id of a module that this chunk corresponds to. */
|
|
170
|
+
facadeModuleId: string | null;
|
|
171
|
+
/** The list of ids of modules included in this chunk. */
|
|
172
|
+
moduleIds: Array<string>;
|
|
173
|
+
/** Exported variable names from this chunk. */
|
|
174
|
+
exports: Array<string>;
|
|
175
|
+
/** The preliminary file name of this chunk with hash placeholders. */
|
|
176
|
+
fileName: string;
|
|
177
|
+
/** External modules imported statically by this chunk. */
|
|
178
|
+
imports: Array<string>;
|
|
179
|
+
/** External modules imported dynamically by this chunk. */
|
|
180
|
+
dynamicImports: Array<string>;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* The information about a chunk in the generated bundle.
|
|
184
|
+
*
|
|
185
|
+
* @category Plugin APIs
|
|
186
|
+
*/
|
|
187
|
+
interface OutputChunk extends ExternalMemoryHandle {
|
|
188
|
+
type: "chunk";
|
|
189
|
+
/** The generated code of this chunk. */
|
|
190
|
+
code: string;
|
|
191
|
+
/** The name of this chunk, which is used in naming patterns. */
|
|
192
|
+
name: string;
|
|
193
|
+
/** Whether this chunk is a static entry point. */
|
|
194
|
+
isEntry: boolean;
|
|
195
|
+
/** Exported variable names from this chunk. */
|
|
196
|
+
exports: string[];
|
|
197
|
+
/** The file name of this chunk. */
|
|
198
|
+
fileName: string;
|
|
199
|
+
/** Information about the modules included in this chunk. */
|
|
200
|
+
modules: {
|
|
201
|
+
[id: string]: RenderedModule;
|
|
202
|
+
};
|
|
203
|
+
/** External modules imported statically by this chunk. */
|
|
204
|
+
imports: string[];
|
|
205
|
+
/** External modules imported dynamically by this chunk. */
|
|
206
|
+
dynamicImports: string[];
|
|
207
|
+
/** The id of a module that this chunk corresponds to. */
|
|
208
|
+
facadeModuleId: string | null;
|
|
209
|
+
/** Whether this chunk is a dynamic entry point. */
|
|
210
|
+
isDynamicEntry: boolean;
|
|
211
|
+
moduleIds: string[];
|
|
212
|
+
/** The source map of this chunk if present. */
|
|
213
|
+
map: SourceMap | null;
|
|
214
|
+
sourcemapFileName: string | null;
|
|
215
|
+
/** The preliminary file name of this chunk with hash placeholders. */
|
|
216
|
+
preliminaryFileName: string;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* The generated bundle output.
|
|
220
|
+
*
|
|
221
|
+
* @category Programmatic APIs
|
|
222
|
+
*/
|
|
223
|
+
interface RolldownOutput extends ExternalMemoryHandle {
|
|
224
|
+
/**
|
|
225
|
+
* The list of chunks and assets in the generated bundle.
|
|
226
|
+
*
|
|
227
|
+
* This includes at least one {@linkcode OutputChunk}. It may also include more
|
|
228
|
+
* {@linkcode OutputChunk} and/or {@linkcode OutputAsset}s.
|
|
229
|
+
*/
|
|
230
|
+
output: [OutputChunk, ...(OutputChunk | OutputAsset)[]];
|
|
231
|
+
}
|
|
232
|
+
//#endregion
|
|
233
|
+
//#region src/types/utils.d.ts
|
|
234
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
235
|
+
/** @inline */
|
|
236
|
+
type NullValue<T = void> = T | undefined | null | void;
|
|
237
|
+
type PartialNull<T> = { [P in keyof T]: T[P] | null };
|
|
238
|
+
type MakeAsync<Function_> = Function_ extends ((this: infer This, ...parameters: infer Arguments) => infer Return) ? (this: This, ...parameters: Arguments) => Return | Promise<Return> : never;
|
|
239
|
+
type MaybeArray<T> = T | T[];
|
|
240
|
+
/** @inline */
|
|
241
|
+
type StringOrRegExp = string | RegExp;
|
|
242
|
+
//#endregion
|
|
243
|
+
//#region src/options/output-options.d.ts
|
|
244
|
+
type GeneratedCodePreset = "es5" | "es2015";
|
|
245
|
+
interface GeneratedCodeOptions {
|
|
246
|
+
/**
|
|
247
|
+
* Whether to use Symbol.toStringTag for namespace objects.
|
|
248
|
+
* @default false
|
|
249
|
+
*/
|
|
250
|
+
symbols?: boolean;
|
|
251
|
+
/**
|
|
252
|
+
* Allows choosing one of the presets listed above while overriding some options.
|
|
253
|
+
*
|
|
254
|
+
* ```js
|
|
255
|
+
* export default {
|
|
256
|
+
* output: {
|
|
257
|
+
* generatedCode: {
|
|
258
|
+
* preset: 'es2015',
|
|
259
|
+
* symbols: false
|
|
260
|
+
* }
|
|
261
|
+
* }
|
|
262
|
+
* };
|
|
263
|
+
* ```
|
|
264
|
+
*
|
|
265
|
+
* @default 'es2015'
|
|
266
|
+
*/
|
|
267
|
+
preset?: GeneratedCodePreset;
|
|
268
|
+
/**
|
|
269
|
+
* Whether to add readable names to internal variables for profiling purposes.
|
|
270
|
+
*
|
|
271
|
+
* When enabled, generated code will use descriptive variable names that correspond
|
|
272
|
+
* to the original module names, making it easier to profile and debug the bundled code.
|
|
273
|
+
*
|
|
274
|
+
* @default false
|
|
275
|
+
*
|
|
276
|
+
* {@include ./docs/output-generated-code-profiler-names.md}
|
|
277
|
+
*/
|
|
278
|
+
profilerNames?: boolean;
|
|
279
|
+
}
|
|
280
|
+
/** @inline */
|
|
281
|
+
type ModuleFormat = "es" | "cjs" | "esm" | "module" | "commonjs" | "iife" | "umd";
|
|
282
|
+
/** @inline */
|
|
283
|
+
type AddonFunction = (chunk: RenderedChunk) => string | Promise<string>;
|
|
284
|
+
/** @inline */
|
|
285
|
+
type ChunkFileNamesFunction = (chunkInfo: PreRenderedChunk) => string;
|
|
286
|
+
/** @inline */
|
|
287
|
+
type SanitizeFileNameFunction = (name: string) => string;
|
|
288
|
+
/** @category Plugin APIs */
|
|
289
|
+
interface PreRenderedAsset {
|
|
290
|
+
type: "asset";
|
|
291
|
+
/** @deprecated Use {@linkcode names} instead. */
|
|
292
|
+
name?: string;
|
|
293
|
+
names: string[];
|
|
294
|
+
/** @deprecated Use {@linkcode originalFileNames} instead. */
|
|
295
|
+
originalFileName?: string;
|
|
296
|
+
/** The list of the absolute paths to the original file of this asset. */
|
|
297
|
+
originalFileNames: string[];
|
|
298
|
+
/** The content of this asset. */
|
|
299
|
+
source: AssetSource;
|
|
300
|
+
}
|
|
301
|
+
/** @inline */
|
|
302
|
+
type AssetFileNamesFunction = (chunkInfo: PreRenderedAsset) => string;
|
|
303
|
+
/** @inline */
|
|
304
|
+
type PathsFunction$1 = (id: string) => string;
|
|
305
|
+
/** @inline */
|
|
306
|
+
type ManualChunksFunction = (moduleId: string, meta: {
|
|
307
|
+
getModuleInfo: (moduleId: string) => ModuleInfo | null;
|
|
308
|
+
}) => string | NullValue;
|
|
309
|
+
/** @inline */
|
|
310
|
+
type GlobalsFunction = (name: string) => string;
|
|
311
|
+
/** @category Plugin APIs */
|
|
312
|
+
type CodeSplittingNameFunction = (moduleId: string, ctx: ChunkingContext) => string | NullValue;
|
|
313
|
+
/** @inline */
|
|
314
|
+
type CodeSplittingTestFunction = (id: string) => boolean | undefined | void;
|
|
315
|
+
type MinifyOptions = Omit<MinifyOptions$1, "module" | "sourcemap">;
|
|
316
|
+
/** @inline */
|
|
317
|
+
interface ChunkingContext {
|
|
318
|
+
getModuleInfo(moduleId: string): ModuleInfo | null;
|
|
319
|
+
}
|
|
320
|
+
interface OutputOptions {
|
|
321
|
+
/**
|
|
322
|
+
* The directory in which all generated chunks are placed.
|
|
323
|
+
*
|
|
324
|
+
* The {@linkcode file | output.file} option should be used instead if only a single chunk is generated.
|
|
325
|
+
*
|
|
326
|
+
* @default 'dist'
|
|
327
|
+
*/
|
|
328
|
+
dir?: string;
|
|
329
|
+
/**
|
|
330
|
+
* The file path for the single generated chunk.
|
|
331
|
+
*
|
|
332
|
+
* The {@linkcode dir | output.dir} option should be used instead if multiple chunks are generated.
|
|
333
|
+
*/
|
|
334
|
+
file?: string;
|
|
335
|
+
/**
|
|
336
|
+
* Which exports mode to use.
|
|
337
|
+
*
|
|
338
|
+
* {@include ./docs/output-exports.md}
|
|
339
|
+
*
|
|
340
|
+
* @default 'auto'
|
|
341
|
+
*/
|
|
342
|
+
exports?: "auto" | "named" | "default" | "none";
|
|
343
|
+
/**
|
|
344
|
+
* Specify the character set that Rolldown is allowed to use in file hashes.
|
|
345
|
+
*
|
|
346
|
+
* - `'base64'`: Uses url-safe base64 characters (0-9, a-z, A-Z, -, _). This will produce the shortest hashes.
|
|
347
|
+
* - `'base36'`: Uses alphanumeric characters (0-9, a-z)
|
|
348
|
+
* - `'hex'`: Uses hexadecimal characters (0-9, a-f)
|
|
349
|
+
*
|
|
350
|
+
* @default 'base64'
|
|
351
|
+
*/
|
|
352
|
+
hashCharacters?: "base64" | "base36" | "hex";
|
|
353
|
+
/**
|
|
354
|
+
* Expected format of generated code.
|
|
355
|
+
*
|
|
356
|
+
* - `'es'`, `'esm'` and `'module'` are the same format, all stand for ES module.
|
|
357
|
+
* - `'cjs'` and `'commonjs'` are the same format, all stand for CommonJS module.
|
|
358
|
+
* - `'iife'` stands for [Immediately Invoked Function Expression](https://developer.mozilla.org/en-US/docs/Glossary/IIFE).
|
|
359
|
+
* - `'umd'` stands for [Universal Module Definition](https://github.com/umdjs/umd).
|
|
360
|
+
*
|
|
361
|
+
* @default 'esm'
|
|
362
|
+
*/
|
|
363
|
+
format?: ModuleFormat;
|
|
364
|
+
/**
|
|
365
|
+
* Whether to generate sourcemaps.
|
|
366
|
+
*
|
|
367
|
+
* - `false`: No sourcemap will be generated.
|
|
368
|
+
* - `true`: A separate sourcemap file will be generated.
|
|
369
|
+
* - `'inline'`: The sourcemap will be appended to the output file as a data URL.
|
|
370
|
+
* - `'hidden'`: A separate sourcemap file will be generated, but the link to the sourcemap (`//# sourceMappingURL` comment) will not be included in the output file.
|
|
371
|
+
*
|
|
372
|
+
* @default false
|
|
373
|
+
*/
|
|
374
|
+
sourcemap?: boolean | "inline" | "hidden";
|
|
375
|
+
/**
|
|
376
|
+
* The base URL for the links to the sourcemap file in the output file.
|
|
377
|
+
*
|
|
378
|
+
* By default, relative URLs are generated. If this option is set, an absolute URL with that base URL will be generated. This is useful when deploying source maps to a different location than your code, such as a CDN or separate debugging server.
|
|
379
|
+
*/
|
|
380
|
+
sourcemapBaseUrl?: string;
|
|
381
|
+
/**
|
|
382
|
+
* Whether to include [debug IDs](https://github.com/tc39/ecma426/blob/main/proposals/debug-id.md) in the sourcemap.
|
|
383
|
+
*
|
|
384
|
+
* When `true`, a unique debug ID will be emitted in source and sourcemaps which streamlines identifying sourcemaps across different builds.
|
|
385
|
+
*
|
|
386
|
+
* @default false
|
|
387
|
+
*/
|
|
388
|
+
sourcemapDebugIds?: boolean;
|
|
389
|
+
/**
|
|
390
|
+
* Control which source files are included in the sourcemap ignore list.
|
|
391
|
+
*
|
|
392
|
+
* Files in the ignore list are excluded from debugger stepping and error stack traces.
|
|
393
|
+
*
|
|
394
|
+
* - `false`: Include no source files in the ignore list
|
|
395
|
+
* - `true`: Include all source files in the ignore list
|
|
396
|
+
* - `string`: Files containing this string in their path will be included in the ignore list
|
|
397
|
+
* - `RegExp`: Files matching this regular expression will be included in the ignore list
|
|
398
|
+
* - `function`: Custom function to determine if a source should be ignored
|
|
399
|
+
*
|
|
400
|
+
* :::tip Performance
|
|
401
|
+
* Using static values (`boolean`, `string`, or `RegExp`) is significantly more performant than functions.
|
|
402
|
+
* Calling JavaScript functions from Rust has extremely high overhead, so prefer static patterns when possible.
|
|
403
|
+
* :::
|
|
404
|
+
*
|
|
405
|
+
* @example
|
|
406
|
+
* ```js
|
|
407
|
+
* // ✅ Preferred: Use RegExp for better performance
|
|
408
|
+
* sourcemapIgnoreList: /node_modules/
|
|
409
|
+
*
|
|
410
|
+
* // ✅ Preferred: Use string pattern for better performance
|
|
411
|
+
* sourcemapIgnoreList: "vendor"
|
|
412
|
+
*
|
|
413
|
+
* // ! Use sparingly: Function calls have high overhead
|
|
414
|
+
* sourcemapIgnoreList: (source, sourcemapPath) => {
|
|
415
|
+
* return source.includes('node_modules') || source.includes('.min.');
|
|
416
|
+
* }
|
|
417
|
+
* ```
|
|
418
|
+
*
|
|
419
|
+
* @default /node_modules/
|
|
420
|
+
*/
|
|
421
|
+
sourcemapIgnoreList?: boolean | SourcemapIgnoreListOption | StringOrRegExp;
|
|
422
|
+
/**
|
|
423
|
+
* A transformation to apply to each path in a sourcemap.
|
|
424
|
+
*
|
|
425
|
+
* @example
|
|
426
|
+
* ```js
|
|
427
|
+
* export default defineConfig({
|
|
428
|
+
* output: {
|
|
429
|
+
* sourcemap: true,
|
|
430
|
+
* sourcemapPathTransform: (source, sourcemapPath) => {
|
|
431
|
+
* // Remove 'src/' prefix from all source paths
|
|
432
|
+
* return source.replace(/^src\//, '');
|
|
433
|
+
* },
|
|
434
|
+
* },
|
|
435
|
+
* });
|
|
436
|
+
* ```
|
|
437
|
+
*/
|
|
438
|
+
sourcemapPathTransform?: SourcemapPathTransformOption;
|
|
439
|
+
/**
|
|
440
|
+
* A string to prepend to the bundle before `renderChunk` hook.
|
|
441
|
+
*
|
|
442
|
+
* See {@linkcode intro | output.intro}, {@linkcode postBanner | output.postBanner} as well.
|
|
443
|
+
*
|
|
444
|
+
* {@include ./docs/output-banner.md}
|
|
445
|
+
*/
|
|
446
|
+
banner?: string | AddonFunction;
|
|
447
|
+
/**
|
|
448
|
+
* A string to append to the bundle before `renderChunk` hook.
|
|
449
|
+
*
|
|
450
|
+
* See {@linkcode outro | output.outro}, {@linkcode postFooter | output.postFooter} as well.
|
|
451
|
+
*
|
|
452
|
+
* {@include ./docs/output-footer.md}
|
|
453
|
+
*/
|
|
454
|
+
footer?: string | AddonFunction;
|
|
455
|
+
/**
|
|
456
|
+
* A string to prepend to the bundle after `renderChunk` hook and minification.
|
|
457
|
+
*
|
|
458
|
+
* See {@linkcode banner | output.banner}, {@linkcode intro | output.intro} as well.
|
|
459
|
+
*/
|
|
460
|
+
postBanner?: string | AddonFunction;
|
|
461
|
+
/**
|
|
462
|
+
* A string to append to the bundle after `renderChunk` hook and minification.
|
|
463
|
+
*
|
|
464
|
+
* See {@linkcode footer | output.footer}, {@linkcode outro | output.outro} as well.
|
|
465
|
+
*/
|
|
466
|
+
postFooter?: string | AddonFunction;
|
|
467
|
+
/**
|
|
468
|
+
* A string to prepend inside any format-specific wrapper.
|
|
469
|
+
*
|
|
470
|
+
* See {@linkcode banner | output.banner}, {@linkcode postBanner | output.postBanner} as well.
|
|
471
|
+
*/
|
|
472
|
+
intro?: string | AddonFunction;
|
|
473
|
+
/**
|
|
474
|
+
* A string to append inside any format-specific wrapper.
|
|
475
|
+
*
|
|
476
|
+
* See {@linkcode footer | output.footer}, {@linkcode postFooter | output.postFooter} as well.
|
|
477
|
+
*/
|
|
478
|
+
outro?: string | AddonFunction;
|
|
479
|
+
/**
|
|
480
|
+
* Whether to extend the global variable defined by the {@linkcode OutputOptions.name | name} option in `umd` or `iife` formats.
|
|
481
|
+
*
|
|
482
|
+
* When `true`, the global variable will be defined as `global.name = global.name || {}`.
|
|
483
|
+
* When `false`, the global defined by name will be overwritten like `global.name = {}`.
|
|
484
|
+
*
|
|
485
|
+
* @default false
|
|
486
|
+
*/
|
|
487
|
+
extend?: boolean;
|
|
488
|
+
/**
|
|
489
|
+
* Whether to add a `__esModule: true` property when generating exports for non-ES formats.
|
|
490
|
+
*
|
|
491
|
+
* This property signifies that the exported value is the namespace of an ES module and that the default export of this module corresponds to the `.default` property of the exported object.
|
|
492
|
+
*
|
|
493
|
+
* - `true`: Always add the property when using named exports mode, which is similar to what other tools do.
|
|
494
|
+
* - `"if-default-prop"`: Only add the property when using named exports mode and there also is a default export. The subtle difference is that if there is no default export, consumers of the CommonJS version of your library will get all named exports as default export instead of an error or `undefined`.
|
|
495
|
+
* - `false`: Never add the property even if the default export would become a property `.default`.
|
|
496
|
+
*
|
|
497
|
+
* @default 'if-default-prop'
|
|
498
|
+
*/
|
|
499
|
+
esModule?: boolean | "if-default-prop";
|
|
500
|
+
/**
|
|
501
|
+
* The pattern to use for naming custom emitted assets to include in the build output, or a function that is called per asset with {@linkcode PreRenderedAsset} to return such a pattern.
|
|
502
|
+
*
|
|
503
|
+
* Patterns support the following placeholders:
|
|
504
|
+
* - `[extname]`: The file extension of the asset including a leading dot, e.g. `.css`.
|
|
505
|
+
* - `[ext]`: The file extension without a leading dot, e.g. css.
|
|
506
|
+
* - `[hash]`: A hash based on the content of the asset. You can also set a specific hash length via e.g. `[hash:10]`. By default, it will create a base-64 hash. If you need a reduced character set, see {@linkcode hashCharacters | output.hashCharacters}.
|
|
507
|
+
* - `[name]`: The file name of the asset excluding any extension.
|
|
508
|
+
*
|
|
509
|
+
* Forward slashes (`/`) can be used to place files in sub-directories.
|
|
510
|
+
*
|
|
511
|
+
* See also {@linkcode chunkFileNames | output.chunkFileNames}, {@linkcode entryFileNames | output.entryFileNames}.
|
|
512
|
+
*
|
|
513
|
+
* @default 'assets/[name]-[hash][extname]'
|
|
514
|
+
*/
|
|
515
|
+
assetFileNames?: string | AssetFileNamesFunction;
|
|
516
|
+
/**
|
|
517
|
+
* The pattern to use for chunks created from entry points, or a function that is called per entry chunk with {@linkcode PreRenderedChunk} to return such a pattern.
|
|
518
|
+
*
|
|
519
|
+
* Patterns support the following placeholders:
|
|
520
|
+
* - `[format]`: The rendering format defined in the output options, e.g. `es` or `cjs`.
|
|
521
|
+
* - `[hash]`: A hash based only on the content of the final generated chunk, including transformations in `renderChunk` and any referenced file hashes. You can also set a specific hash length via e.g. `[hash:10]`. By default, it will create a base-64 hash. If you need a reduced character set, see {@linkcode hashCharacters | output.hashCharacters}.
|
|
522
|
+
* - `[name]`: The file name (without extension) of the entry point, unless the object form of input was used to define a different name.
|
|
523
|
+
*
|
|
524
|
+
* Forward slashes (`/`) can be used to place files in sub-directories. This pattern will also be used for every file when setting the {@linkcode preserveModules | output.preserveModules} option.
|
|
525
|
+
*
|
|
526
|
+
* See also {@linkcode assetFileNames | output.assetFileNames}, {@linkcode chunkFileNames | output.chunkFileNames}.
|
|
527
|
+
*
|
|
528
|
+
* @default '[name].js'
|
|
529
|
+
*/
|
|
530
|
+
entryFileNames?: string | ChunkFileNamesFunction;
|
|
531
|
+
/**
|
|
532
|
+
* The pattern to use for naming shared chunks created when code-splitting, or a function that is called per chunk with {@linkcode PreRenderedChunk} to return such a pattern.
|
|
533
|
+
*
|
|
534
|
+
* Patterns support the following placeholders:
|
|
535
|
+
* - `[format]`: The rendering format defined in the output options, e.g. `es` or `cjs`.
|
|
536
|
+
* - `[hash]`: A hash based only on the content of the final generated chunk, including transformations in `renderChunk` and any referenced file hashes. You can also set a specific hash length via e.g. `[hash:10]`. By default, it will create a base-64 hash. If you need a reduced character set, see {@linkcode hashCharacters | output.hashCharacters}.
|
|
537
|
+
* - `[name]`: The name of the chunk. This can be explicitly set via the {@linkcode codeSplitting | output.codeSplitting} option or when the chunk is created by a plugin via `this.emitFile`. Otherwise, it will be derived from the chunk contents.
|
|
538
|
+
*
|
|
539
|
+
* Forward slashes (`/`) can be used to place files in sub-directories.
|
|
540
|
+
*
|
|
541
|
+
* See also {@linkcode assetFileNames | output.assetFileNames}, {@linkcode entryFileNames | output.entryFileNames}.
|
|
542
|
+
*
|
|
543
|
+
* @default '[name]-[hash].js'
|
|
544
|
+
*/
|
|
545
|
+
chunkFileNames?: string | ChunkFileNamesFunction;
|
|
546
|
+
/**
|
|
547
|
+
* @default '[name].css'
|
|
548
|
+
* @experimental
|
|
549
|
+
* @hidden not ready for public usage yet
|
|
550
|
+
*/
|
|
551
|
+
cssEntryFileNames?: string | ChunkFileNamesFunction;
|
|
552
|
+
/**
|
|
553
|
+
* @default '[name]-[hash].css'
|
|
554
|
+
* @experimental
|
|
555
|
+
* @hidden not ready for public usage yet
|
|
556
|
+
*/
|
|
557
|
+
cssChunkFileNames?: string | ChunkFileNamesFunction;
|
|
558
|
+
/**
|
|
559
|
+
* Whether to enable chunk name sanitization (removal of non-URL-safe characters like `\0`, `?` and `*`).
|
|
560
|
+
*
|
|
561
|
+
* Set `false` to disable the sanitization. You can also provide a custom sanitization function.
|
|
562
|
+
*
|
|
563
|
+
* @default true
|
|
564
|
+
*/
|
|
565
|
+
sanitizeFileName?: boolean | SanitizeFileNameFunction;
|
|
566
|
+
/**
|
|
567
|
+
* Control code minification.
|
|
568
|
+
*
|
|
569
|
+
* - `true`: Enable full minification including code compression and dead code elimination
|
|
570
|
+
* - `false`: Disable minification (default)
|
|
571
|
+
* - `'dce-only'`: Only perform dead code elimination without code compression
|
|
572
|
+
* - `MinifyOptions`: Fine-grained control over minification settings
|
|
573
|
+
*
|
|
574
|
+
* @default false
|
|
575
|
+
*/
|
|
576
|
+
minify?: boolean | "dce-only" | MinifyOptions;
|
|
577
|
+
/**
|
|
578
|
+
* Specifies the global variable name that contains the exports of `umd` / `iife` bundles.
|
|
579
|
+
*
|
|
580
|
+
* @example
|
|
581
|
+
* ```js
|
|
582
|
+
* export default defineConfig({
|
|
583
|
+
* output: {
|
|
584
|
+
* format: 'iife',
|
|
585
|
+
* name: 'MyBundle',
|
|
586
|
+
* }
|
|
587
|
+
* });
|
|
588
|
+
* ```
|
|
589
|
+
* ```js
|
|
590
|
+
* // output
|
|
591
|
+
* var MyBundle = (function () {
|
|
592
|
+
* // ...
|
|
593
|
+
* })();
|
|
594
|
+
* ```
|
|
595
|
+
*
|
|
596
|
+
* {@include ./docs/output-name.md}
|
|
597
|
+
*/
|
|
598
|
+
name?: string;
|
|
599
|
+
/**
|
|
600
|
+
* Specifies `id: variableName` pairs necessary for external imports in `umd` / `iife` bundles.
|
|
601
|
+
*
|
|
602
|
+
* @example
|
|
603
|
+
* ```js
|
|
604
|
+
* export default defineConfig({
|
|
605
|
+
* external: ['jquery'],
|
|
606
|
+
* output: {
|
|
607
|
+
* format: 'iife',
|
|
608
|
+
* name: 'MyBundle',
|
|
609
|
+
* globals: {
|
|
610
|
+
* jquery: '$',
|
|
611
|
+
* }
|
|
612
|
+
* }
|
|
613
|
+
* });
|
|
614
|
+
* ```
|
|
615
|
+
* ```js
|
|
616
|
+
* // input
|
|
617
|
+
* import $ from 'jquery';
|
|
618
|
+
* ```
|
|
619
|
+
* ```js
|
|
620
|
+
* // output
|
|
621
|
+
* var MyBundle = (function ($) {
|
|
622
|
+
* // ...
|
|
623
|
+
* })($);
|
|
624
|
+
* ```
|
|
625
|
+
*/
|
|
626
|
+
globals?: Record<string, string> | GlobalsFunction;
|
|
627
|
+
/**
|
|
628
|
+
* Maps external module IDs to paths.
|
|
629
|
+
*
|
|
630
|
+
* Allows customizing the path used when importing external dependencies.
|
|
631
|
+
* This is particularly useful for loading dependencies from CDNs or custom locations.
|
|
632
|
+
*
|
|
633
|
+
* - Object form: Maps module IDs to their replacement paths
|
|
634
|
+
* - Function form: Takes a module ID and returns its replacement path
|
|
635
|
+
*
|
|
636
|
+
* @example
|
|
637
|
+
* ```js
|
|
638
|
+
* {
|
|
639
|
+
* paths: {
|
|
640
|
+
* 'd3': 'https://cdn.jsdelivr.net/npm/d3@7'
|
|
641
|
+
* }
|
|
642
|
+
* }
|
|
643
|
+
* ```
|
|
644
|
+
*
|
|
645
|
+
* @example
|
|
646
|
+
* ```js
|
|
647
|
+
* {
|
|
648
|
+
* paths: (id) => {
|
|
649
|
+
* if (id.startsWith('lodash')) {
|
|
650
|
+
* return `https://cdn.jsdelivr.net/npm/${id}`
|
|
651
|
+
* }
|
|
652
|
+
* return id
|
|
653
|
+
* }
|
|
654
|
+
* }
|
|
655
|
+
* ```
|
|
656
|
+
*/
|
|
657
|
+
paths?: Record<string, string> | PathsFunction$1;
|
|
658
|
+
/**
|
|
659
|
+
* Which language features Rolldown can safely use in generated code.
|
|
660
|
+
*
|
|
661
|
+
* This will not transpile any user code but only change the code Rolldown uses in wrappers and helpers.
|
|
662
|
+
*/
|
|
663
|
+
generatedCode?: Partial<GeneratedCodeOptions>;
|
|
664
|
+
/**
|
|
665
|
+
* Whether to generate code to support live bindings for external imports.
|
|
666
|
+
*
|
|
667
|
+
* With the default value of `true`, Rolldown will generate code to support live bindings for external imports.
|
|
668
|
+
*
|
|
669
|
+
* When set to `false`, Rolldown will assume that exports from external modules do not change. This will allow Rolldown to generate smaller code. Note that this can cause issues when there are circular dependencies involving an external dependency.
|
|
670
|
+
*
|
|
671
|
+
* @default true
|
|
672
|
+
*
|
|
673
|
+
* {@include ./docs/output-external-live-bindings.md}
|
|
674
|
+
*/
|
|
675
|
+
externalLiveBindings?: boolean;
|
|
676
|
+
/**
|
|
677
|
+
* @deprecated Please use `codeSplitting: false` instead.
|
|
678
|
+
*
|
|
679
|
+
* Whether to inline dynamic imports instead of creating new chunks to create a single bundle.
|
|
680
|
+
*
|
|
681
|
+
* This option can be used only when a single input is provided.
|
|
682
|
+
*
|
|
683
|
+
* @default false
|
|
684
|
+
*/
|
|
685
|
+
inlineDynamicImports?: boolean;
|
|
686
|
+
/**
|
|
687
|
+
* Whether to keep external dynamic imports as `import(...)` expressions in CommonJS output.
|
|
688
|
+
*
|
|
689
|
+
* If set to `false`, external dynamic imports will be rewritten to use `require(...)` calls.
|
|
690
|
+
* This may be necessary to support environments that do not support dynamic `import()` in CommonJS modules like old Node.js versions.
|
|
691
|
+
*
|
|
692
|
+
* @default true
|
|
693
|
+
*/
|
|
694
|
+
dynamicImportInCjs?: boolean;
|
|
695
|
+
/**
|
|
696
|
+
* Allows you to do manual chunking. Provided for Rollup compatibility.
|
|
697
|
+
*
|
|
698
|
+
* You could use this option for migration purpose. Under the hood,
|
|
699
|
+
*
|
|
700
|
+
* ```js
|
|
701
|
+
* {
|
|
702
|
+
* manualChunks: (moduleId, meta) => {
|
|
703
|
+
* if (moduleId.includes('node_modules')) {
|
|
704
|
+
* return 'vendor';
|
|
705
|
+
* }
|
|
706
|
+
* return null;
|
|
707
|
+
* }
|
|
708
|
+
* }
|
|
709
|
+
* ```
|
|
710
|
+
*
|
|
711
|
+
* will be transformed to
|
|
712
|
+
*
|
|
713
|
+
* ```js
|
|
714
|
+
* {
|
|
715
|
+
* codeSplitting: {
|
|
716
|
+
* groups: [
|
|
717
|
+
* {
|
|
718
|
+
* name(moduleId) {
|
|
719
|
+
* if (moduleId.includes('node_modules')) {
|
|
720
|
+
* return 'vendor';
|
|
721
|
+
* }
|
|
722
|
+
* return null;
|
|
723
|
+
* },
|
|
724
|
+
* },
|
|
725
|
+
* ],
|
|
726
|
+
* }
|
|
727
|
+
* }
|
|
728
|
+
*
|
|
729
|
+
* ```
|
|
730
|
+
*
|
|
731
|
+
* Note that unlike Rollup, object form is not supported.
|
|
732
|
+
*
|
|
733
|
+
* @deprecated
|
|
734
|
+
* Please use {@linkcode codeSplitting | output.codeSplitting} instead.
|
|
735
|
+
*
|
|
736
|
+
* :::warning
|
|
737
|
+
* If `manualChunks` and `codeSplitting` are both specified, `manualChunks` option will be ignored.
|
|
738
|
+
* :::
|
|
739
|
+
*/
|
|
740
|
+
manualChunks?: ManualChunksFunction;
|
|
741
|
+
/**
|
|
742
|
+
* Controls how code splitting is performed.
|
|
743
|
+
*
|
|
744
|
+
* - `true`: Default behavior, automatic code splitting. **(default)**
|
|
745
|
+
* - `false`: Inline all dynamic imports into a single bundle (equivalent to deprecated `inlineDynamicImports: true`).
|
|
746
|
+
* - `object`: Advanced manual code splitting configuration.
|
|
747
|
+
*
|
|
748
|
+
* For deeper understanding, please refer to the in-depth [documentation](https://rolldown.rs/in-depth/manual-code-splitting).
|
|
749
|
+
*
|
|
750
|
+
* @example
|
|
751
|
+
* **Basic vendor chunk**
|
|
752
|
+
* ```js
|
|
753
|
+
* export default defineConfig({
|
|
754
|
+
* output: {
|
|
755
|
+
* codeSplitting: {
|
|
756
|
+
* minSize: 20000,
|
|
757
|
+
* groups: [
|
|
758
|
+
* {
|
|
759
|
+
* name: 'vendor',
|
|
760
|
+
* test: /node_modules/,
|
|
761
|
+
* },
|
|
762
|
+
* ],
|
|
763
|
+
* },
|
|
764
|
+
* },
|
|
765
|
+
* });
|
|
766
|
+
* ```
|
|
767
|
+
* {@include ./docs/output-code-splitting.md}
|
|
768
|
+
*
|
|
769
|
+
* @default true
|
|
770
|
+
*/
|
|
771
|
+
codeSplitting?: boolean | CodeSplittingOptions;
|
|
772
|
+
/**
|
|
773
|
+
* @deprecated Please use {@linkcode codeSplitting | output.codeSplitting} instead.
|
|
774
|
+
*
|
|
775
|
+
* Allows you to do manual chunking.
|
|
776
|
+
*
|
|
777
|
+
* :::warning
|
|
778
|
+
* If `advancedChunks` and `codeSplitting` are both specified, `advancedChunks` option will be ignored.
|
|
779
|
+
* :::
|
|
780
|
+
*/
|
|
781
|
+
advancedChunks?: {
|
|
782
|
+
includeDependenciesRecursively?: boolean;
|
|
783
|
+
minSize?: number;
|
|
784
|
+
maxSize?: number;
|
|
785
|
+
maxModuleSize?: number;
|
|
786
|
+
minModuleSize?: number;
|
|
787
|
+
minShareCount?: number;
|
|
788
|
+
groups?: CodeSplittingGroup[];
|
|
789
|
+
};
|
|
790
|
+
/**
|
|
791
|
+
* Control comments in the output.
|
|
792
|
+
*
|
|
793
|
+
* - `none`: no comments
|
|
794
|
+
* - `inline`: preserve comments that contain `@license`, `@preserve` or starts with `//!` `/*!`
|
|
795
|
+
*/
|
|
796
|
+
legalComments?: "none" | "inline";
|
|
797
|
+
/**
|
|
798
|
+
* The list of plugins to use only for this output.
|
|
799
|
+
*/
|
|
800
|
+
plugins?: RolldownOutputPluginOption;
|
|
801
|
+
/**
|
|
802
|
+
* Whether to add a polyfill for `require()` function in non-CommonJS formats.
|
|
803
|
+
*
|
|
804
|
+
* This option is useful when you want to inject your own `require` implementation.
|
|
805
|
+
*
|
|
806
|
+
* @default true
|
|
807
|
+
*/
|
|
808
|
+
polyfillRequire?: boolean;
|
|
809
|
+
/**
|
|
810
|
+
* This option is not implemented yet.
|
|
811
|
+
* @hidden
|
|
812
|
+
*/
|
|
813
|
+
hoistTransitiveImports?: false;
|
|
814
|
+
/**
|
|
815
|
+
* Whether to use preserve modules mode.
|
|
816
|
+
*
|
|
817
|
+
* {@include ./docs/output-preserve-modules.md}
|
|
818
|
+
*
|
|
819
|
+
* @default false
|
|
820
|
+
*/
|
|
821
|
+
preserveModules?: boolean;
|
|
822
|
+
/**
|
|
823
|
+
* Specifies the directory name for "virtual" files that might be emitted by plugins when using preserve modules mode.
|
|
824
|
+
*
|
|
825
|
+
* @default '_virtual'
|
|
826
|
+
*/
|
|
827
|
+
virtualDirname?: string;
|
|
828
|
+
/**
|
|
829
|
+
* A directory path to input modules that should be stripped away from {@linkcode dir | output.dir} when using preserve modules mode.
|
|
830
|
+
*
|
|
831
|
+
* {@include ./docs/output-preserve-modules-root.md}
|
|
832
|
+
*/
|
|
833
|
+
preserveModulesRoot?: string;
|
|
834
|
+
/**
|
|
835
|
+
* Whether to use `var` declarations at the top level scope instead of function / class / let / const expressions.
|
|
836
|
+
*
|
|
837
|
+
* Enabling this option can improve runtime performance of the generated code in certain environments.
|
|
838
|
+
*
|
|
839
|
+
* @default false
|
|
840
|
+
*
|
|
841
|
+
* {@include ./docs/output-top-level-var.md}
|
|
842
|
+
*/
|
|
843
|
+
topLevelVar?: boolean;
|
|
844
|
+
/**
|
|
845
|
+
* Whether to minify internal exports as single letter variables to allow for better minification.
|
|
846
|
+
*
|
|
847
|
+
* @default
|
|
848
|
+
* `true` for format `es` or if `output.minify` is `true` or object, `false` otherwise
|
|
849
|
+
*
|
|
850
|
+
* {@include ./docs/output-minify-internal-exports.md}
|
|
851
|
+
*/
|
|
852
|
+
minifyInternalExports?: boolean;
|
|
853
|
+
/**
|
|
854
|
+
* Clean output directory ({@linkcode dir | output.dir}) before emitting output.
|
|
855
|
+
*
|
|
856
|
+
* @default false
|
|
857
|
+
*
|
|
858
|
+
* {@include ./docs/output-clean-dir.md}
|
|
859
|
+
*/
|
|
860
|
+
cleanDir?: boolean;
|
|
861
|
+
/**
|
|
862
|
+
* Keep `name` property of functions and classes after bundling.
|
|
863
|
+
*
|
|
864
|
+
* When enabled, the bundler will preserve the original `name` property value of functions and
|
|
865
|
+
* classes in the output. This is useful for debugging and some frameworks that rely on it for
|
|
866
|
+
* registration and binding purposes.
|
|
867
|
+
*
|
|
868
|
+
* @default false
|
|
869
|
+
*/
|
|
870
|
+
keepNames?: boolean;
|
|
871
|
+
/**
|
|
872
|
+
* Lets modules be executed in the order they are declared.
|
|
873
|
+
*
|
|
874
|
+
* This is done by injecting runtime helpers to ensure that modules are executed in the order they are imported. External modules won't be affected.
|
|
875
|
+
*
|
|
876
|
+
* > [!WARNING]
|
|
877
|
+
* > Enabling this option may negatively increase bundle size. It is recommended to use this option only when absolutely necessary.
|
|
878
|
+
* @default false
|
|
879
|
+
*/
|
|
880
|
+
strictExecutionOrder?: boolean;
|
|
881
|
+
/**
|
|
882
|
+
* Reserved global identifiers to be avoided when generating export binding names for module chunks.
|
|
883
|
+
*
|
|
884
|
+
* @default []
|
|
885
|
+
*/
|
|
886
|
+
globalIdentifiers?: string[];
|
|
887
|
+
}
|
|
888
|
+
type CodeSplittingGroup = {
|
|
889
|
+
/**
|
|
890
|
+
* Name of the group. It will be also used as the name of the chunk and replace the `[name]` placeholder in the {@linkcode OutputOptions.chunkFileNames | output.chunkFileNames} option.
|
|
891
|
+
*
|
|
892
|
+
* For example,
|
|
893
|
+
*
|
|
894
|
+
* ```js
|
|
895
|
+
* import { defineConfig } from '@rollipop/rolldown';
|
|
896
|
+
*
|
|
897
|
+
* export default defineConfig({
|
|
898
|
+
* output: {
|
|
899
|
+
* codeSplitting: {
|
|
900
|
+
* groups: [
|
|
901
|
+
* {
|
|
902
|
+
* name: 'libs',
|
|
903
|
+
* test: /node_modules/,
|
|
904
|
+
* },
|
|
905
|
+
* ],
|
|
906
|
+
* },
|
|
907
|
+
* },
|
|
908
|
+
* });
|
|
909
|
+
* ```
|
|
910
|
+
* will create a chunk named `libs-[hash].js` in the end.
|
|
911
|
+
*
|
|
912
|
+
* It's ok to have the same name for different groups. Rolldown will deduplicate the chunk names if necessary.
|
|
913
|
+
*
|
|
914
|
+
* #### Dynamic `name()`
|
|
915
|
+
*
|
|
916
|
+
* If `name` is a function, it will be called with the module id as the argument. The function should return a string or `null`. If it returns `null`, the module will be ignored by this group.
|
|
917
|
+
*
|
|
918
|
+
* Notice, each returned new name will be treated as a separate group.
|
|
919
|
+
*
|
|
920
|
+
* For example,
|
|
921
|
+
*
|
|
922
|
+
* ```js
|
|
923
|
+
* import { defineConfig } from '@rollipop/rolldown';
|
|
924
|
+
*
|
|
925
|
+
* export default defineConfig({
|
|
926
|
+
* output: {
|
|
927
|
+
* codeSplitting: {
|
|
928
|
+
* groups: [
|
|
929
|
+
* {
|
|
930
|
+
* name: (moduleId) => moduleId.includes('node_modules') ? 'libs' : 'app',
|
|
931
|
+
* minSize: 100 * 1024,
|
|
932
|
+
* },
|
|
933
|
+
* ],
|
|
934
|
+
* },
|
|
935
|
+
* },
|
|
936
|
+
* });
|
|
937
|
+
* ```
|
|
938
|
+
*
|
|
939
|
+
* :::warning
|
|
940
|
+
* Constraints like `minSize`, `maxSize`, etc. are applied separately for different names returned by the function.
|
|
941
|
+
* :::
|
|
942
|
+
*/
|
|
943
|
+
name: string | CodeSplittingNameFunction;
|
|
944
|
+
/**
|
|
945
|
+
* Controls which modules are captured in this group.
|
|
946
|
+
*
|
|
947
|
+
* - If `test` is a string, the module whose id contains the string will be captured.
|
|
948
|
+
* - If `test` is a regular expression, the module whose id matches the regular expression will be captured.
|
|
949
|
+
* - If `test` is a function, modules for which `test(id)` returns `true` will be captured.
|
|
950
|
+
* - If `test` is empty, any module will be considered as matched.
|
|
951
|
+
*
|
|
952
|
+
* :::warning
|
|
953
|
+
* When using regular expression, it's recommended to use `[\\/]` to match the path separator instead of `/` to avoid potential issues on Windows.
|
|
954
|
+
* - ✅ Recommended: `/node_modules[\\/]react/`
|
|
955
|
+
* - ❌ Not recommended: `/node_modules/react/`
|
|
956
|
+
* :::
|
|
957
|
+
*/
|
|
958
|
+
test?: StringOrRegExp | CodeSplittingTestFunction;
|
|
959
|
+
/**
|
|
960
|
+
* Priority of the group. Group with higher priority will be chosen first to match modules and create chunks. When converting the group to a chunk, modules of that group will be removed from other groups.
|
|
961
|
+
*
|
|
962
|
+
* If two groups have the same priority, the group whose index is smaller will be chosen.
|
|
963
|
+
*
|
|
964
|
+
* @example
|
|
965
|
+
* ```js
|
|
966
|
+
* import { defineConfig } from '@rollipop/rolldown';
|
|
967
|
+
*
|
|
968
|
+
* export default defineConfig({
|
|
969
|
+
* output: {
|
|
970
|
+
* codeSplitting: {
|
|
971
|
+
* groups: [
|
|
972
|
+
* {
|
|
973
|
+
* name: 'react',
|
|
974
|
+
* test: /node_modules[\\/]react/,
|
|
975
|
+
* priority: 2,
|
|
976
|
+
* },
|
|
977
|
+
* {
|
|
978
|
+
* name: 'other-libs',
|
|
979
|
+
* test: /node_modules/,
|
|
980
|
+
* priority: 1,
|
|
981
|
+
* },
|
|
982
|
+
* ],
|
|
983
|
+
* },
|
|
984
|
+
* },
|
|
985
|
+
* });
|
|
986
|
+
* ```
|
|
987
|
+
*
|
|
988
|
+
* @default 0
|
|
989
|
+
*/
|
|
990
|
+
priority?: number;
|
|
991
|
+
/**
|
|
992
|
+
* Minimum size in bytes of the desired chunk. If the accumulated size of the captured modules by this group is smaller than this value, it will be ignored. Modules in this group will fall back to the `automatic chunking` if they are not captured by any other group.
|
|
993
|
+
*
|
|
994
|
+
* @default 0
|
|
995
|
+
*/
|
|
996
|
+
minSize?: number;
|
|
997
|
+
/**
|
|
998
|
+
* Controls if a module should be captured based on how many entry chunks reference it.
|
|
999
|
+
*
|
|
1000
|
+
* @default 1
|
|
1001
|
+
*/
|
|
1002
|
+
minShareCount?: number;
|
|
1003
|
+
/**
|
|
1004
|
+
* If the accumulated size in bytes of the captured modules by this group is larger than this value, this group will be split into multiple groups that each has size close to this value.
|
|
1005
|
+
*
|
|
1006
|
+
* @default Infinity
|
|
1007
|
+
*/
|
|
1008
|
+
maxSize?: number;
|
|
1009
|
+
/**
|
|
1010
|
+
* Controls whether a module can only be captured if its size in bytes is smaller than or equal to this value.
|
|
1011
|
+
*
|
|
1012
|
+
* @default Infinity
|
|
1013
|
+
*/
|
|
1014
|
+
maxModuleSize?: number;
|
|
1015
|
+
/**
|
|
1016
|
+
* Controls whether a module can only be captured if its size in bytes is larger than or equal to this value.
|
|
1017
|
+
*
|
|
1018
|
+
* @default 0
|
|
1019
|
+
*/
|
|
1020
|
+
minModuleSize?: number;
|
|
1021
|
+
};
|
|
1022
|
+
/**
|
|
1023
|
+
* Alias for {@linkcode CodeSplittingGroup}. Use this type for the `codeSplitting.groups` option.
|
|
1024
|
+
*
|
|
1025
|
+
* @deprecated Please use {@linkcode CodeSplittingGroup} instead.
|
|
1026
|
+
*/
|
|
1027
|
+
type AdvancedChunksGroup = CodeSplittingGroup;
|
|
1028
|
+
/**
|
|
1029
|
+
* Configuration options for advanced code splitting.
|
|
1030
|
+
*/
|
|
1031
|
+
type CodeSplittingOptions = {
|
|
1032
|
+
/**
|
|
1033
|
+
* By default, each group will also include captured modules' dependencies. This reduces the chance of generating circular chunks.
|
|
1034
|
+
*
|
|
1035
|
+
* If you want to disable this behavior, it's recommended to both set
|
|
1036
|
+
* - {@linkcode InputOptions.preserveEntrySignatures | preserveEntrySignatures}: `false | 'allow-extension'`
|
|
1037
|
+
* - {@linkcode OutputOptions.strictExecutionOrder | strictExecutionOrder}: `true`
|
|
1038
|
+
*
|
|
1039
|
+
* to avoid generating invalid chunks.
|
|
1040
|
+
*
|
|
1041
|
+
* @default true
|
|
1042
|
+
*/
|
|
1043
|
+
includeDependenciesRecursively?: boolean;
|
|
1044
|
+
/**
|
|
1045
|
+
* Global fallback of {@linkcode CodeSplittingGroup.minSize | group.minSize}, if it's not specified in the group.
|
|
1046
|
+
*/
|
|
1047
|
+
minSize?: number;
|
|
1048
|
+
/**
|
|
1049
|
+
* Global fallback of {@linkcode CodeSplittingGroup.maxSize | group.maxSize}, if it's not specified in the group.
|
|
1050
|
+
*/
|
|
1051
|
+
maxSize?: number;
|
|
1052
|
+
/**
|
|
1053
|
+
* Global fallback of {@linkcode CodeSplittingGroup.maxModuleSize | group.maxModuleSize}, if it's not specified in the group.
|
|
1054
|
+
*/
|
|
1055
|
+
maxModuleSize?: number;
|
|
1056
|
+
/**
|
|
1057
|
+
* Global fallback of {@linkcode CodeSplittingGroup.minModuleSize | group.minModuleSize}, if it's not specified in the group.
|
|
1058
|
+
*/
|
|
1059
|
+
minModuleSize?: number;
|
|
1060
|
+
/**
|
|
1061
|
+
* Global fallback of {@linkcode CodeSplittingGroup.minShareCount | group.minShareCount}, if it's not specified in the group.
|
|
1062
|
+
*/
|
|
1063
|
+
minShareCount?: number;
|
|
1064
|
+
/**
|
|
1065
|
+
* Groups to be used for code splitting.
|
|
1066
|
+
*/
|
|
1067
|
+
groups?: CodeSplittingGroup[];
|
|
1068
|
+
};
|
|
1069
|
+
/**
|
|
1070
|
+
* Alias for {@linkcode CodeSplittingOptions}. Use this type for the `codeSplitting` option.
|
|
1071
|
+
*
|
|
1072
|
+
* @deprecated Please use {@linkcode CodeSplittingOptions} instead.
|
|
1073
|
+
*/
|
|
1074
|
+
type AdvancedChunksOptions = CodeSplittingOptions;
|
|
1075
|
+
//#endregion
|
|
1076
|
+
//#region src/api/build.d.ts
|
|
1077
|
+
/**
|
|
1078
|
+
* The options for {@linkcode build} function.
|
|
1079
|
+
*
|
|
1080
|
+
* @experimental
|
|
1081
|
+
* @category Programmatic APIs
|
|
1082
|
+
*/
|
|
1083
|
+
type BuildOptions = InputOptions & {
|
|
1084
|
+
/**
|
|
1085
|
+
* Write the output to the file system
|
|
1086
|
+
*
|
|
1087
|
+
* @default true
|
|
1088
|
+
*/
|
|
1089
|
+
write?: boolean;
|
|
1090
|
+
output?: OutputOptions;
|
|
1091
|
+
};
|
|
1092
|
+
/**
|
|
1093
|
+
* Build a single output.
|
|
1094
|
+
*
|
|
1095
|
+
* @param options The build options.
|
|
1096
|
+
* @returns A Promise that resolves to the build output.
|
|
1097
|
+
*/
|
|
1098
|
+
declare function build(options: BuildOptions): Promise<RolldownOutput>;
|
|
1099
|
+
/**
|
|
1100
|
+
* Build multiple outputs __sequentially__.
|
|
1101
|
+
*
|
|
1102
|
+
* @param options The build options.
|
|
1103
|
+
* @returns A Promise that resolves to the build outputs for each option.
|
|
1104
|
+
*/
|
|
1105
|
+
declare function build(options: BuildOptions[]): Promise<RolldownOutput[]>;
|
|
1106
|
+
//#endregion
|
|
1107
|
+
//#region src/api/rolldown/rolldown-build.d.ts
|
|
1108
|
+
/**
|
|
1109
|
+
* The bundle object returned by {@linkcode rolldown} function.
|
|
1110
|
+
*
|
|
1111
|
+
* @category Programmatic APIs
|
|
1112
|
+
*/
|
|
1113
|
+
declare class RolldownBuild {
|
|
1114
|
+
#private;
|
|
1115
|
+
/** @internal */
|
|
1116
|
+
static asyncRuntimeShutdown: boolean;
|
|
1117
|
+
/** @hidden should not be used directly */
|
|
1118
|
+
constructor(inputOptions: InputOptions);
|
|
1119
|
+
/**
|
|
1120
|
+
* Whether the bundle has been closed.
|
|
1121
|
+
*
|
|
1122
|
+
* If the bundle is closed, calling other methods will throw an error.
|
|
1123
|
+
*/
|
|
1124
|
+
get closed(): boolean;
|
|
1125
|
+
/**
|
|
1126
|
+
* Generate bundles in-memory.
|
|
1127
|
+
*
|
|
1128
|
+
* If you directly want to write bundles to disk, use the {@linkcode write} method instead.
|
|
1129
|
+
*
|
|
1130
|
+
* @param outputOptions The output options.
|
|
1131
|
+
* @returns The generated bundle.
|
|
1132
|
+
* @throws {@linkcode RolldownError} When an error occurs during the build.
|
|
1133
|
+
*/
|
|
1134
|
+
generate(outputOptions?: OutputOptions): Promise<RolldownOutput>;
|
|
1135
|
+
/**
|
|
1136
|
+
* Generate and write bundles to disk.
|
|
1137
|
+
*
|
|
1138
|
+
* If you want to generate bundles in-memory, use the {@linkcode generate} method instead.
|
|
1139
|
+
*
|
|
1140
|
+
* @param outputOptions The output options.
|
|
1141
|
+
* @returns The generated bundle.
|
|
1142
|
+
* @throws {@linkcode RolldownError} When an error occurs during the build.
|
|
1143
|
+
*/
|
|
1144
|
+
write(outputOptions?: OutputOptions): Promise<RolldownOutput>;
|
|
1145
|
+
/**
|
|
1146
|
+
* Close the bundle and free resources.
|
|
1147
|
+
*
|
|
1148
|
+
* This method is called automatically when using `using` syntax.
|
|
1149
|
+
*
|
|
1150
|
+
* @example
|
|
1151
|
+
* ```js
|
|
1152
|
+
* import { rolldown } from 'rolldown';
|
|
1153
|
+
*
|
|
1154
|
+
* {
|
|
1155
|
+
* using bundle = await rolldown({ input: 'src/main.js' });
|
|
1156
|
+
* const output = await bundle.generate({ format: 'esm' });
|
|
1157
|
+
* console.log(output);
|
|
1158
|
+
* // bundle.close() is called automatically here
|
|
1159
|
+
* }
|
|
1160
|
+
* ```
|
|
1161
|
+
*/
|
|
1162
|
+
close(): Promise<void>;
|
|
1163
|
+
/** @hidden documented in close method */
|
|
1164
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
1165
|
+
/**
|
|
1166
|
+
* @experimental
|
|
1167
|
+
* @hidden not ready for public usage yet
|
|
1168
|
+
*/
|
|
1169
|
+
get watchFiles(): Promise<string[]>;
|
|
1170
|
+
}
|
|
1171
|
+
//#endregion
|
|
1172
|
+
//#region src/api/rolldown/index.d.ts
|
|
1173
|
+
/**
|
|
1174
|
+
* The API compatible with Rollup's `rollup` function.
|
|
1175
|
+
*
|
|
1176
|
+
* Unlike Rollup, the module graph is not built until the methods of the bundle object are called.
|
|
1177
|
+
*
|
|
1178
|
+
* @param input The input options object.
|
|
1179
|
+
* @returns A Promise that resolves to a bundle object.
|
|
1180
|
+
*
|
|
1181
|
+
* @example
|
|
1182
|
+
* ```js
|
|
1183
|
+
* import { rolldown } from 'rolldown';
|
|
1184
|
+
*
|
|
1185
|
+
* let bundle, failed = false;
|
|
1186
|
+
* try {
|
|
1187
|
+
* bundle = await rolldown({
|
|
1188
|
+
* input: 'src/main.js',
|
|
1189
|
+
* });
|
|
1190
|
+
* await bundle.write({
|
|
1191
|
+
* format: 'esm',
|
|
1192
|
+
* });
|
|
1193
|
+
* } catch (e) {
|
|
1194
|
+
* console.error(e);
|
|
1195
|
+
* failed = true;
|
|
1196
|
+
* }
|
|
1197
|
+
* if (bundle) {
|
|
1198
|
+
* await bundle.close();
|
|
1199
|
+
* }
|
|
1200
|
+
* process.exitCode = failed ? 1 : 0;
|
|
1201
|
+
* ```
|
|
1202
|
+
*
|
|
1203
|
+
* @category Programmatic APIs
|
|
1204
|
+
*/
|
|
1205
|
+
declare const rolldown: (input: InputOptions) => Promise<RolldownBuild>;
|
|
1206
|
+
//#endregion
|
|
1207
|
+
//#region src/options/watch-options.d.ts
|
|
1208
|
+
/** @category Programmatic APIs */
|
|
1209
|
+
interface WatchOptions extends InputOptions {
|
|
1210
|
+
output?: OutputOptions | OutputOptions[];
|
|
1211
|
+
}
|
|
1212
|
+
//#endregion
|
|
1213
|
+
//#region src/api/watch/watch-emitter.d.ts
|
|
1214
|
+
type ChangeEvent$1 = "create" | "update" | "delete";
|
|
1215
|
+
type RolldownWatchBuild = BindingWatcherBundler;
|
|
1216
|
+
/**
|
|
1217
|
+
* - `START`: the watcher is (re)starting
|
|
1218
|
+
* - `BUNDLE_START`: building an individual bundle
|
|
1219
|
+
* - `BUNDLE_END`: finished building a bundle
|
|
1220
|
+
* - `duration`: the build duration in milliseconds
|
|
1221
|
+
* - `output`: an array of the {@linkcode OutputOptions.file | file} or {@linkcode OutputOptions.dir | dir} option values of the generated outputs
|
|
1222
|
+
* - `result`: the bundle object that can be used to generate additional outputs. This is especially important when the watch.skipWrite option is used. You should call `event.result.close()` once you are done generating outputs, or if you do not generate outputs. This will allow plugins to clean up resources via the `closeBundle` hook.
|
|
1223
|
+
* - `END`: finished building all bundles
|
|
1224
|
+
* - `ERROR`: encountered an error while bundling
|
|
1225
|
+
* - `error`: the error that was thrown
|
|
1226
|
+
* - `result`: the bundle object
|
|
1227
|
+
*
|
|
1228
|
+
* @category Programmatic APIs
|
|
1229
|
+
*/
|
|
1230
|
+
type RolldownWatcherEvent = {
|
|
1231
|
+
code: "START";
|
|
1232
|
+
} | {
|
|
1233
|
+
code: "BUNDLE_START";
|
|
1234
|
+
} | {
|
|
1235
|
+
code: "BUNDLE_END";
|
|
1236
|
+
duration: number;
|
|
1237
|
+
output: readonly string[];
|
|
1238
|
+
result: RolldownWatchBuild;
|
|
1239
|
+
} | {
|
|
1240
|
+
code: "END";
|
|
1241
|
+
} | {
|
|
1242
|
+
code: "ERROR";
|
|
1243
|
+
error: Error;
|
|
1244
|
+
result: RolldownWatchBuild;
|
|
1245
|
+
};
|
|
1246
|
+
/**
|
|
1247
|
+
*
|
|
1248
|
+
* @category Programmatic APIs
|
|
1249
|
+
*/
|
|
1250
|
+
type RolldownWatcherWatcherEventMap = {
|
|
1251
|
+
event: [data: RolldownWatcherEvent]; /** a file was modified */
|
|
1252
|
+
change: [id: string, change: {
|
|
1253
|
+
event: ChangeEvent$1;
|
|
1254
|
+
}]; /** a new run was triggered */
|
|
1255
|
+
restart: []; /** the watcher was closed */
|
|
1256
|
+
close: [];
|
|
1257
|
+
};
|
|
1258
|
+
/**
|
|
1259
|
+
* @category Programmatic APIs
|
|
1260
|
+
*/
|
|
1261
|
+
interface RolldownWatcher {
|
|
1262
|
+
on<E extends keyof RolldownWatcherWatcherEventMap>(event: E, listener: (...args: RolldownWatcherWatcherEventMap[E]) => MaybePromise<void>): this;
|
|
1263
|
+
off<E extends keyof RolldownWatcherWatcherEventMap>(event: E, listener: (...args: RolldownWatcherWatcherEventMap[E]) => MaybePromise<void>): this;
|
|
1264
|
+
clear<E extends keyof RolldownWatcherWatcherEventMap>(event: E): void;
|
|
1265
|
+
close(): Promise<void>;
|
|
1266
|
+
}
|
|
1267
|
+
//#endregion
|
|
1268
|
+
//#region src/api/watch/index.d.ts
|
|
1269
|
+
/**
|
|
1270
|
+
* The API compatible with Rollup's `watch` function.
|
|
1271
|
+
*
|
|
1272
|
+
* This function will rebuild the bundle when it detects that the individual modules have changed on disk.
|
|
1273
|
+
*
|
|
1274
|
+
* Note that when using this function, it is your responsibility to call `event.result.close()` in response to the `BUNDLE_END` event to avoid resource leaks.
|
|
1275
|
+
*
|
|
1276
|
+
* @param input The watch options object or the list of them.
|
|
1277
|
+
* @returns A watcher object.
|
|
1278
|
+
*
|
|
1279
|
+
* @example
|
|
1280
|
+
* ```js
|
|
1281
|
+
* import { watch } from 'rolldown';
|
|
1282
|
+
*
|
|
1283
|
+
* const watcher = watch({ /* ... *\/ });
|
|
1284
|
+
* watcher.on('event', (event) => {
|
|
1285
|
+
* if (event.code === 'BUNDLE_END') {
|
|
1286
|
+
* console.log(event.duration);
|
|
1287
|
+
* event.result.close();
|
|
1288
|
+
* }
|
|
1289
|
+
* });
|
|
1290
|
+
*
|
|
1291
|
+
* // Stop watching
|
|
1292
|
+
* watcher.close();
|
|
1293
|
+
* ```
|
|
1294
|
+
*
|
|
1295
|
+
* @experimental
|
|
1296
|
+
* @category Programmatic APIs
|
|
1297
|
+
*/
|
|
1298
|
+
declare const watch: (input: WatchOptions | WatchOptions[]) => RolldownWatcher;
|
|
1299
|
+
//#endregion
|
|
1300
|
+
//#region src/log/log-handler.d.ts
|
|
1301
|
+
type LoggingFunction = (log: RolldownLog | string | (() => RolldownLog | string)) => void;
|
|
1302
|
+
type LoggingFunctionWithPosition = (log: RolldownLog | string | (() => RolldownLog | string), pos?: number | {
|
|
1303
|
+
column: number;
|
|
1304
|
+
line: number;
|
|
1305
|
+
}) => void;
|
|
1306
|
+
type WarningHandlerWithDefault = (warning: RolldownLog, defaultHandler: LoggingFunction) => void;
|
|
1307
|
+
//#endregion
|
|
1308
|
+
//#region src/options/generated/checks-options.d.ts
|
|
1309
|
+
interface ChecksOptions {
|
|
1310
|
+
/**
|
|
1311
|
+
* Whether to emit warnings when detecting circular dependency
|
|
1312
|
+
*
|
|
1313
|
+
* Circular dependencies lead to a bigger bundle size and sometimes cause execution order issues and are better to avoid.
|
|
1314
|
+
* @default false
|
|
1315
|
+
* */
|
|
1316
|
+
circularDependency?: boolean;
|
|
1317
|
+
/**
|
|
1318
|
+
* Whether to emit warnings when detecting uses of direct `eval`s
|
|
1319
|
+
*
|
|
1320
|
+
* See [Avoiding Direct `eval` in Troubleshooting page](https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval) for more details.
|
|
1321
|
+
* @default true
|
|
1322
|
+
* */
|
|
1323
|
+
eval?: boolean;
|
|
1324
|
+
/**
|
|
1325
|
+
* Whether to emit warnings when the `output.globals` option is missing when needed
|
|
1326
|
+
*
|
|
1327
|
+
* See [`output.globals`](https://rolldown.rs/reference/OutputOptions.globals).
|
|
1328
|
+
* @default true
|
|
1329
|
+
* */
|
|
1330
|
+
missingGlobalName?: boolean;
|
|
1331
|
+
/**
|
|
1332
|
+
* Whether to emit warnings when the `output.name` option is missing when needed
|
|
1333
|
+
*
|
|
1334
|
+
* See [`output.name`](https://rolldown.rs/reference/OutputOptions.name).
|
|
1335
|
+
* @default true
|
|
1336
|
+
* */
|
|
1337
|
+
missingNameOptionForIifeExport?: boolean;
|
|
1338
|
+
/**
|
|
1339
|
+
* Whether to emit warnings when the way to export values is ambiguous
|
|
1340
|
+
*
|
|
1341
|
+
* See [`output.exports`](https://rolldown.rs/reference/OutputOptions.exports).
|
|
1342
|
+
* @default true
|
|
1343
|
+
* */
|
|
1344
|
+
mixedExports?: boolean;
|
|
1345
|
+
/**
|
|
1346
|
+
* Whether to emit warnings when an entrypoint cannot be resolved
|
|
1347
|
+
* @default true
|
|
1348
|
+
* */
|
|
1349
|
+
unresolvedEntry?: boolean;
|
|
1350
|
+
/**
|
|
1351
|
+
* Whether to emit warnings when an import cannot be resolved
|
|
1352
|
+
* @default true
|
|
1353
|
+
* */
|
|
1354
|
+
unresolvedImport?: boolean;
|
|
1355
|
+
/**
|
|
1356
|
+
* Whether to emit warnings when files generated have the same name with different contents
|
|
1357
|
+
* @default true
|
|
1358
|
+
* */
|
|
1359
|
+
filenameConflict?: boolean;
|
|
1360
|
+
/**
|
|
1361
|
+
* Whether to emit warnings when a CommonJS variable is used in an ES module
|
|
1362
|
+
*
|
|
1363
|
+
* CommonJS variables like `module` and `exports` are treated as global variables in ES modules and may not work as expected.
|
|
1364
|
+
* @default true
|
|
1365
|
+
* */
|
|
1366
|
+
commonJsVariableInEsm?: boolean;
|
|
1367
|
+
/**
|
|
1368
|
+
* Whether to emit warnings when an imported variable is not exported
|
|
1369
|
+
*
|
|
1370
|
+
* If the code is importing a variable that is not exported by the imported module, the value will always be `undefined`. This might be a mistake in the code.
|
|
1371
|
+
* @default true
|
|
1372
|
+
* */
|
|
1373
|
+
importIsUndefined?: boolean;
|
|
1374
|
+
/**
|
|
1375
|
+
* Whether to emit warnings when `import.meta` is not supported with the output format and is replaced with an empty object (`{}`)
|
|
1376
|
+
*
|
|
1377
|
+
* See [`import.meta` in Non-ESM Output Formats page](https://rolldown.rs/in-depth/non-esm-output-formats#import-meta) for more details.
|
|
1378
|
+
* @default true
|
|
1379
|
+
* */
|
|
1380
|
+
emptyImportMeta?: boolean;
|
|
1381
|
+
/**
|
|
1382
|
+
* Whether to emit warnings when detecting tolerated transform
|
|
1383
|
+
* @default true
|
|
1384
|
+
* */
|
|
1385
|
+
toleratedTransform?: boolean;
|
|
1386
|
+
/**
|
|
1387
|
+
* Whether to emit warnings when a namespace is called as a function
|
|
1388
|
+
*
|
|
1389
|
+
* A module namespace object is an object and not a function. Calling it as a function will cause a runtime error.
|
|
1390
|
+
* @default true
|
|
1391
|
+
* */
|
|
1392
|
+
cannotCallNamespace?: boolean;
|
|
1393
|
+
/**
|
|
1394
|
+
* Whether to emit warnings when a config value is overridden by another config value with a higher priority
|
|
1395
|
+
* @default true
|
|
1396
|
+
* */
|
|
1397
|
+
configurationFieldConflict?: boolean;
|
|
1398
|
+
/**
|
|
1399
|
+
* Whether to emit warnings when a plugin that is covered by a built-in feature is used
|
|
1400
|
+
*
|
|
1401
|
+
* Using built-in features is generally more performant than using plugins.
|
|
1402
|
+
* @default true
|
|
1403
|
+
* */
|
|
1404
|
+
preferBuiltinFeature?: boolean;
|
|
1405
|
+
/**
|
|
1406
|
+
* Whether to emit warnings when Rolldown could not clean the output directory
|
|
1407
|
+
*
|
|
1408
|
+
* See [`output.cleanDir`](https://rolldown.rs/reference/OutputOptions.cleanDir).
|
|
1409
|
+
* @default true
|
|
1410
|
+
* */
|
|
1411
|
+
couldNotCleanDirectory?: boolean;
|
|
1412
|
+
/**
|
|
1413
|
+
* Whether to emit warnings when plugins take significant time during the build process
|
|
1414
|
+
*
|
|
1415
|
+
* {@include ../docs/checks-plugin-timings.md}
|
|
1416
|
+
* @default true
|
|
1417
|
+
* */
|
|
1418
|
+
pluginTimings?: boolean;
|
|
1419
|
+
}
|
|
1420
|
+
//#endregion
|
|
1421
|
+
//#region src/options/transform-options.d.ts
|
|
1422
|
+
interface TransformOptions extends Omit<TransformOptions$1, "sourceType" | "lang" | "cwd" | "sourcemap" | "define" | "inject" | "jsx"> {
|
|
1423
|
+
/**
|
|
1424
|
+
* Replace global variables or [property accessors](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors) with the provided values.
|
|
1425
|
+
*
|
|
1426
|
+
* @example
|
|
1427
|
+
* **Replace the global variable `IS_PROD` with `true`**
|
|
1428
|
+
* ```js rolldown.config.js
|
|
1429
|
+
* export default defineConfig({
|
|
1430
|
+
* transform: { define: { IS_PROD: 'true' } }
|
|
1431
|
+
* })
|
|
1432
|
+
* ```
|
|
1433
|
+
* Result:
|
|
1434
|
+
* ```js
|
|
1435
|
+
* // Input
|
|
1436
|
+
* if (IS_PROD) {
|
|
1437
|
+
* console.log('Production mode')
|
|
1438
|
+
* }
|
|
1439
|
+
*
|
|
1440
|
+
* // After bundling
|
|
1441
|
+
* if (true) {
|
|
1442
|
+
* console.log('Production mode')
|
|
1443
|
+
* }
|
|
1444
|
+
* ```
|
|
1445
|
+
*
|
|
1446
|
+
* **Replace the property accessor `process.env.NODE_ENV` with `'production'`**
|
|
1447
|
+
* ```js rolldown.config.js
|
|
1448
|
+
* export default defineConfig({
|
|
1449
|
+
* transform: { define: { 'process.env.NODE_ENV': "'production'" } }
|
|
1450
|
+
* })
|
|
1451
|
+
* ```
|
|
1452
|
+
* Result:
|
|
1453
|
+
* ```js
|
|
1454
|
+
* // Input
|
|
1455
|
+
* if (process.env.NODE_ENV === 'production') {
|
|
1456
|
+
* console.log('Production mode')
|
|
1457
|
+
* }
|
|
1458
|
+
*
|
|
1459
|
+
* // After bundling
|
|
1460
|
+
* if ('production' === 'production') {
|
|
1461
|
+
* console.log('Production mode')
|
|
1462
|
+
* }
|
|
1463
|
+
* ```
|
|
1464
|
+
*/
|
|
1465
|
+
define?: Record<string, string>;
|
|
1466
|
+
/**
|
|
1467
|
+
* Inject import statements on demand.
|
|
1468
|
+
*
|
|
1469
|
+
* The API is aligned with `@rollup/plugin-inject`.
|
|
1470
|
+
*
|
|
1471
|
+
* #### Supported patterns
|
|
1472
|
+
* ```js
|
|
1473
|
+
* {
|
|
1474
|
+
* // import { Promise } from 'es6-promise'
|
|
1475
|
+
* Promise: ['es6-promise', 'Promise'],
|
|
1476
|
+
*
|
|
1477
|
+
* // import { Promise as P } from 'es6-promise'
|
|
1478
|
+
* P: ['es6-promise', 'Promise'],
|
|
1479
|
+
*
|
|
1480
|
+
* // import $ from 'jquery'
|
|
1481
|
+
* $: 'jquery',
|
|
1482
|
+
*
|
|
1483
|
+
* // import * as fs from 'node:fs'
|
|
1484
|
+
* fs: ['node:fs', '*'],
|
|
1485
|
+
*
|
|
1486
|
+
* // Inject shims for property access pattern
|
|
1487
|
+
* 'Object.assign': path.resolve( 'src/helpers/object-assign.js' ),
|
|
1488
|
+
* }
|
|
1489
|
+
* ```
|
|
1490
|
+
*/
|
|
1491
|
+
inject?: Record<string, string | [string, string]>;
|
|
1492
|
+
/**
|
|
1493
|
+
* Remove labeled statements with these label names.
|
|
1494
|
+
*
|
|
1495
|
+
* Labeled statements are JavaScript statements prefixed with a label identifier.
|
|
1496
|
+
* This option allows you to strip specific labeled statements from the output,
|
|
1497
|
+
* which is useful for removing debug-only code in production builds.
|
|
1498
|
+
*
|
|
1499
|
+
* @example
|
|
1500
|
+
* ```js rolldown.config.js
|
|
1501
|
+
* export default defineConfig({
|
|
1502
|
+
* transform: { dropLabels: ['DEBUG', 'DEV'] }
|
|
1503
|
+
* })
|
|
1504
|
+
* ```
|
|
1505
|
+
* Result:
|
|
1506
|
+
* ```js
|
|
1507
|
+
* // Input
|
|
1508
|
+
* DEBUG: console.log('Debug info');
|
|
1509
|
+
* DEV: {
|
|
1510
|
+
* console.log('Development mode');
|
|
1511
|
+
* }
|
|
1512
|
+
* console.log('Production code');
|
|
1513
|
+
*
|
|
1514
|
+
* // After bundling
|
|
1515
|
+
* console.log('Production code');
|
|
1516
|
+
* ```
|
|
1517
|
+
*/
|
|
1518
|
+
dropLabels?: string[];
|
|
1519
|
+
/**
|
|
1520
|
+
* Controls how JSX syntax is transformed.
|
|
1521
|
+
*
|
|
1522
|
+
* - If set to `false`, an error will be thrown if JSX syntax is encountered.
|
|
1523
|
+
* - If set to `'react'`, JSX syntax will be transformed to classic runtime React code.
|
|
1524
|
+
* - If set to `'react-jsx'`, JSX syntax will be transformed to automatic runtime React code.
|
|
1525
|
+
* - If set to `'preserve'`, JSX syntax will be preserved as-is.
|
|
1526
|
+
*/
|
|
1527
|
+
jsx?: false | "react" | "react-jsx" | "preserve" | JsxOptions;
|
|
1528
|
+
}
|
|
1529
|
+
//#endregion
|
|
1530
|
+
//#region src/options/normalized-input-options.d.ts
|
|
1531
|
+
/** @category Plugin APIs */
|
|
1532
|
+
interface NormalizedInputOptions {
|
|
1533
|
+
/** @see {@linkcode InputOptions.input | input} */
|
|
1534
|
+
input: string[] | Record<string, string>;
|
|
1535
|
+
/** @see {@linkcode InputOptions.cwd | cwd} */
|
|
1536
|
+
cwd: string;
|
|
1537
|
+
/** @see {@linkcode InputOptions.platform | platform} */
|
|
1538
|
+
platform: InputOptions["platform"];
|
|
1539
|
+
/** @see {@linkcode InputOptions.shimMissingExports | shimMissingExports} */
|
|
1540
|
+
shimMissingExports: boolean;
|
|
1541
|
+
/** @see {@linkcode InputOptions.context | context} */
|
|
1542
|
+
context: string;
|
|
1543
|
+
}
|
|
1544
|
+
//#endregion
|
|
1545
|
+
//#region src/options/normalized-output-options.d.ts
|
|
1546
|
+
type PathsFunction = (id: string) => string;
|
|
1547
|
+
/** @category Plugin APIs */
|
|
1548
|
+
type InternalModuleFormat = "es" | "cjs" | "iife" | "umd";
|
|
1549
|
+
/** @category Plugin APIs */
|
|
1550
|
+
interface NormalizedOutputOptions {
|
|
1551
|
+
/** @see {@linkcode OutputOptions.name | name} */
|
|
1552
|
+
name: string | undefined;
|
|
1553
|
+
/** @see {@linkcode OutputOptions.file | file} */
|
|
1554
|
+
file: string | undefined;
|
|
1555
|
+
/** @see {@linkcode OutputOptions.dir | dir} */
|
|
1556
|
+
dir: string | undefined;
|
|
1557
|
+
/** @see {@linkcode OutputOptions.entryFileNames | entryFileNames} */
|
|
1558
|
+
entryFileNames: string | ChunkFileNamesFunction;
|
|
1559
|
+
/** @see {@linkcode OutputOptions.chunkFileNames | chunkFileNames} */
|
|
1560
|
+
chunkFileNames: string | ChunkFileNamesFunction;
|
|
1561
|
+
/** @see {@linkcode OutputOptions.assetFileNames | assetFileNames} */
|
|
1562
|
+
assetFileNames: string | AssetFileNamesFunction;
|
|
1563
|
+
/** @see {@linkcode OutputOptions.format | format} */
|
|
1564
|
+
format: InternalModuleFormat;
|
|
1565
|
+
/** @see {@linkcode OutputOptions.exports | exports} */
|
|
1566
|
+
exports: NonNullable<OutputOptions["exports"]>;
|
|
1567
|
+
/** @see {@linkcode OutputOptions.sourcemap | sourcemap} */
|
|
1568
|
+
sourcemap: boolean | "inline" | "hidden";
|
|
1569
|
+
/** @see {@linkcode OutputOptions.sourcemapBaseUrl | sourcemapBaseUrl} */
|
|
1570
|
+
sourcemapBaseUrl: string | undefined;
|
|
1571
|
+
/** @see {@linkcode OutputOptions.cssEntryFileNames | cssEntryFileNames} */
|
|
1572
|
+
cssEntryFileNames: string | ChunkFileNamesFunction;
|
|
1573
|
+
/** @see {@linkcode OutputOptions.cssChunkFileNames | cssChunkFileNames} */
|
|
1574
|
+
cssChunkFileNames: string | ChunkFileNamesFunction;
|
|
1575
|
+
/** @see {@linkcode OutputOptions.codeSplitting | codeSplitting} */
|
|
1576
|
+
codeSplitting: boolean;
|
|
1577
|
+
/** @deprecated Use `codeSplitting` instead. */
|
|
1578
|
+
inlineDynamicImports: boolean;
|
|
1579
|
+
/** @see {@linkcode OutputOptions.dynamicImportInCjs | dynamicImportInCjs} */
|
|
1580
|
+
dynamicImportInCjs: boolean;
|
|
1581
|
+
/** @see {@linkcode OutputOptions.externalLiveBindings | externalLiveBindings} */
|
|
1582
|
+
externalLiveBindings: boolean;
|
|
1583
|
+
/** @see {@linkcode OutputOptions.banner | banner} */
|
|
1584
|
+
banner: AddonFunction;
|
|
1585
|
+
/** @see {@linkcode OutputOptions.footer | footer} */
|
|
1586
|
+
footer: AddonFunction;
|
|
1587
|
+
/** @see {@linkcode OutputOptions.postBanner | postBanner} */
|
|
1588
|
+
postBanner: AddonFunction;
|
|
1589
|
+
/** @see {@linkcode OutputOptions.postFooter | postFooter} */
|
|
1590
|
+
postFooter: AddonFunction;
|
|
1591
|
+
/** @see {@linkcode OutputOptions.intro | intro} */
|
|
1592
|
+
intro: AddonFunction;
|
|
1593
|
+
/** @see {@linkcode OutputOptions.outro | outro} */
|
|
1594
|
+
outro: AddonFunction;
|
|
1595
|
+
/** @see {@linkcode OutputOptions.esModule | esModule} */
|
|
1596
|
+
esModule: boolean | "if-default-prop";
|
|
1597
|
+
/** @see {@linkcode OutputOptions.extend | extend} */
|
|
1598
|
+
extend: boolean;
|
|
1599
|
+
/** @see {@linkcode OutputOptions.globals | globals} */
|
|
1600
|
+
globals: Record<string, string> | GlobalsFunction;
|
|
1601
|
+
/** @see {@linkcode OutputOptions.paths | paths} */
|
|
1602
|
+
paths: Record<string, string> | PathsFunction | undefined;
|
|
1603
|
+
/** @see {@linkcode OutputOptions.hashCharacters | hashCharacters} */
|
|
1604
|
+
hashCharacters: "base64" | "base36" | "hex";
|
|
1605
|
+
/** @see {@linkcode OutputOptions.sourcemapDebugIds | sourcemapDebugIds} */
|
|
1606
|
+
sourcemapDebugIds: boolean;
|
|
1607
|
+
/** @see {@linkcode OutputOptions.sourcemapIgnoreList | sourcemapIgnoreList} */
|
|
1608
|
+
sourcemapIgnoreList: boolean | SourcemapIgnoreListOption | StringOrRegExp | undefined;
|
|
1609
|
+
/** @see {@linkcode OutputOptions.sourcemapPathTransform | sourcemapPathTransform} */
|
|
1610
|
+
sourcemapPathTransform: SourcemapPathTransformOption | undefined;
|
|
1611
|
+
/** @see {@linkcode OutputOptions.minify | minify} */
|
|
1612
|
+
minify: false | MinifyOptions | "dce-only";
|
|
1613
|
+
/** @see {@linkcode OutputOptions.legalComments | legalComments} */
|
|
1614
|
+
legalComments: "none" | "inline";
|
|
1615
|
+
/** @see {@linkcode OutputOptions.polyfillRequire | polyfillRequire} */
|
|
1616
|
+
polyfillRequire: boolean;
|
|
1617
|
+
/** @see {@linkcode OutputOptions.plugins | plugins} */
|
|
1618
|
+
plugins: RolldownPlugin[];
|
|
1619
|
+
/** @see {@linkcode OutputOptions.preserveModules | preserveModules} */
|
|
1620
|
+
preserveModules: boolean;
|
|
1621
|
+
/** @see {@linkcode OutputOptions.virtualDirname | virtualDirname} */
|
|
1622
|
+
virtualDirname: string;
|
|
1623
|
+
/** @see {@linkcode OutputOptions.preserveModulesRoot | preserveModulesRoot} */
|
|
1624
|
+
preserveModulesRoot?: string;
|
|
1625
|
+
/** @see {@linkcode OutputOptions.topLevelVar | topLevelVar} */
|
|
1626
|
+
topLevelVar?: boolean;
|
|
1627
|
+
/** @see {@linkcode OutputOptions.minifyInternalExports | minifyInternalExports} */
|
|
1628
|
+
minifyInternalExports?: boolean;
|
|
1629
|
+
}
|
|
1630
|
+
//#endregion
|
|
1631
|
+
//#region src/plugin/fs.d.ts
|
|
1632
|
+
/** @category Plugin APIs */
|
|
1633
|
+
interface RolldownFsModule {
|
|
1634
|
+
appendFile(path: string, data: string | Uint8Array, options?: {
|
|
1635
|
+
encoding?: BufferEncoding | null;
|
|
1636
|
+
mode?: string | number;
|
|
1637
|
+
flag?: string | number;
|
|
1638
|
+
}): Promise<void>;
|
|
1639
|
+
copyFile(source: string, destination: string, mode?: string | number): Promise<void>;
|
|
1640
|
+
mkdir(path: string, options?: {
|
|
1641
|
+
recursive?: boolean;
|
|
1642
|
+
mode?: string | number;
|
|
1643
|
+
}): Promise<void>;
|
|
1644
|
+
mkdtemp(prefix: string): Promise<string>;
|
|
1645
|
+
readdir(path: string, options?: {
|
|
1646
|
+
withFileTypes?: false;
|
|
1647
|
+
}): Promise<string[]>;
|
|
1648
|
+
readdir(path: string, options?: {
|
|
1649
|
+
withFileTypes: true;
|
|
1650
|
+
}): Promise<RolldownDirectoryEntry[]>;
|
|
1651
|
+
readFile(path: string, options?: {
|
|
1652
|
+
encoding?: null;
|
|
1653
|
+
flag?: string | number;
|
|
1654
|
+
signal?: AbortSignal;
|
|
1655
|
+
}): Promise<Uint8Array>;
|
|
1656
|
+
readFile(path: string, options?: {
|
|
1657
|
+
encoding: BufferEncoding;
|
|
1658
|
+
flag?: string | number;
|
|
1659
|
+
signal?: AbortSignal;
|
|
1660
|
+
}): Promise<string>;
|
|
1661
|
+
realpath(path: string): Promise<string>;
|
|
1662
|
+
rename(oldPath: string, newPath: string): Promise<void>;
|
|
1663
|
+
rmdir(path: string, options?: {
|
|
1664
|
+
recursive?: boolean;
|
|
1665
|
+
}): Promise<void>;
|
|
1666
|
+
stat(path: string): Promise<RolldownFileStats>;
|
|
1667
|
+
lstat(path: string): Promise<RolldownFileStats>;
|
|
1668
|
+
unlink(path: string): Promise<void>;
|
|
1669
|
+
writeFile(path: string, data: string | Uint8Array, options?: {
|
|
1670
|
+
encoding?: BufferEncoding | null;
|
|
1671
|
+
mode?: string | number;
|
|
1672
|
+
flag?: string | number;
|
|
1673
|
+
}): Promise<void>;
|
|
1674
|
+
}
|
|
1675
|
+
/** @category Plugin APIs */
|
|
1676
|
+
type BufferEncoding = "ascii" | "utf8" | "utf16le" | "ucs2" | "base64" | "base64url" | "latin1" | "binary" | "hex";
|
|
1677
|
+
/** @category Plugin APIs */
|
|
1678
|
+
interface RolldownDirectoryEntry {
|
|
1679
|
+
isFile(): boolean;
|
|
1680
|
+
isDirectory(): boolean;
|
|
1681
|
+
isSymbolicLink(): boolean;
|
|
1682
|
+
name: string;
|
|
1683
|
+
}
|
|
1684
|
+
/** @category Plugin APIs */
|
|
1685
|
+
interface RolldownFileStats {
|
|
1686
|
+
isFile(): boolean;
|
|
1687
|
+
isDirectory(): boolean;
|
|
1688
|
+
isSymbolicLink(): boolean;
|
|
1689
|
+
size: number;
|
|
1690
|
+
mtime: Date;
|
|
1691
|
+
ctime: Date;
|
|
1692
|
+
atime: Date;
|
|
1693
|
+
birthtime: Date;
|
|
1694
|
+
}
|
|
1695
|
+
//#endregion
|
|
1696
|
+
//#region src/plugin/hook-filter.d.ts
|
|
1697
|
+
/** @category Plugin APIs */
|
|
1698
|
+
type GeneralHookFilter<Value = StringOrRegExp> = MaybeArray<Value> | {
|
|
1699
|
+
include?: MaybeArray<Value>;
|
|
1700
|
+
exclude?: MaybeArray<Value>;
|
|
1701
|
+
};
|
|
1702
|
+
interface FormalModuleTypeFilter {
|
|
1703
|
+
include?: ModuleType[];
|
|
1704
|
+
}
|
|
1705
|
+
/** @category Plugin APIs */
|
|
1706
|
+
type ModuleTypeFilter = ModuleType[] | FormalModuleTypeFilter;
|
|
1707
|
+
/**
|
|
1708
|
+
* A filter to be used to do a pre-test to determine whether the hook should be called.
|
|
1709
|
+
*
|
|
1710
|
+
* See [Plugin Hook Filters page](https://rolldown.rs/apis/plugin-api/hook-filters) for more details.
|
|
1711
|
+
*
|
|
1712
|
+
* @category Plugin APIs
|
|
1713
|
+
*/
|
|
1714
|
+
interface HookFilter {
|
|
1715
|
+
/**
|
|
1716
|
+
* A filter based on the module `id`.
|
|
1717
|
+
*
|
|
1718
|
+
* If the value is a string, it is treated as a glob pattern.
|
|
1719
|
+
* The string type is not available for {@linkcode Plugin.resolveId | resolveId} hook.
|
|
1720
|
+
*
|
|
1721
|
+
* @example
|
|
1722
|
+
* Include all `id`s that contain `node_modules` in the path.
|
|
1723
|
+
* ```js
|
|
1724
|
+
* { id: '**'+'/node_modules/**' }
|
|
1725
|
+
* ```
|
|
1726
|
+
* @example
|
|
1727
|
+
* Include all `id`s that contain `node_modules` or `src` in the path.
|
|
1728
|
+
* ```js
|
|
1729
|
+
* { id: ['**'+'/node_modules/**', '**'+'/src/**'] }
|
|
1730
|
+
* ```
|
|
1731
|
+
* @example
|
|
1732
|
+
* Include all `id`s that start with `http`
|
|
1733
|
+
* ```js
|
|
1734
|
+
* { id: /^http/ }
|
|
1735
|
+
* ```
|
|
1736
|
+
* @example
|
|
1737
|
+
* Exclude all `id`s that contain `node_modules` in the path.
|
|
1738
|
+
* ```js
|
|
1739
|
+
* { id: { exclude: '**'+'/node_modules/**' } }
|
|
1740
|
+
* ```
|
|
1741
|
+
* @example
|
|
1742
|
+
* Formal pattern to define includes and excludes.
|
|
1743
|
+
* ```js
|
|
1744
|
+
* { id : {
|
|
1745
|
+
* include: ['**'+'/foo/**', /bar/],
|
|
1746
|
+
* exclude: ['**'+'/baz/**', /qux/]
|
|
1747
|
+
* }}
|
|
1748
|
+
* ```
|
|
1749
|
+
*/
|
|
1750
|
+
id?: GeneralHookFilter;
|
|
1751
|
+
/**
|
|
1752
|
+
* A filter based on the module's `moduleType`.
|
|
1753
|
+
*
|
|
1754
|
+
* Only available for {@linkcode Plugin.transform | transform} hook.
|
|
1755
|
+
*/
|
|
1756
|
+
moduleType?: ModuleTypeFilter;
|
|
1757
|
+
/**
|
|
1758
|
+
* A filter based on the module's code.
|
|
1759
|
+
*
|
|
1760
|
+
* Only available for {@linkcode Plugin.transform | transform} hook.
|
|
1761
|
+
*/
|
|
1762
|
+
code?: GeneralHookFilter;
|
|
1763
|
+
}
|
|
1764
|
+
//#endregion
|
|
1765
|
+
//#region src/plugin/minimal-plugin-context.d.ts
|
|
1766
|
+
/** @category Plugin APIs */
|
|
1767
|
+
interface PluginContextMeta {
|
|
1768
|
+
/**
|
|
1769
|
+
* A property for Rollup compatibility. A dummy value is set by Rolldown.
|
|
1770
|
+
* @example `'4.23.0'`
|
|
1771
|
+
*/
|
|
1772
|
+
rollupVersion: string;
|
|
1773
|
+
/**
|
|
1774
|
+
* The currently running version of Rolldown.
|
|
1775
|
+
* @example `'1.0.0'`
|
|
1776
|
+
*/
|
|
1777
|
+
rolldownVersion: string;
|
|
1778
|
+
/**
|
|
1779
|
+
* Whether Rolldown was started via {@linkcode watch | rolldown.watch()} or
|
|
1780
|
+
* from the command line with `--watch`.
|
|
1781
|
+
*/
|
|
1782
|
+
watchMode: boolean;
|
|
1783
|
+
}
|
|
1784
|
+
/** @category Plugin APIs */
|
|
1785
|
+
interface MinimalPluginContext {
|
|
1786
|
+
/** @hidden */
|
|
1787
|
+
readonly pluginName: string;
|
|
1788
|
+
/**
|
|
1789
|
+
* Similar to {@linkcode warn | this.warn}, except that it will also abort
|
|
1790
|
+
* the bundling process with an error.
|
|
1791
|
+
*
|
|
1792
|
+
* If an Error instance is passed, it will be used as-is, otherwise a new Error
|
|
1793
|
+
* instance will be created with the given error message and all additional
|
|
1794
|
+
* provided properties.
|
|
1795
|
+
*
|
|
1796
|
+
* In all hooks except the {@linkcode Plugin.onLog | onLog} hook, the error will
|
|
1797
|
+
* be augmented with {@linkcode RolldownLog.code | code: "PLUGIN_ERROR"} and
|
|
1798
|
+
* {@linkcode RolldownLog.plugin | plugin: plugin.name} properties.
|
|
1799
|
+
* If a `code` property already exists and the code does not start with `PLUGIN_`,
|
|
1800
|
+
* it will be renamed to {@linkcode RolldownLog.pluginCode | pluginCode}.
|
|
1801
|
+
*
|
|
1802
|
+
* @group Logging Methods
|
|
1803
|
+
*/
|
|
1804
|
+
error: (e: RolldownError | string) => never;
|
|
1805
|
+
/**
|
|
1806
|
+
* Generate a `"info"` level log.
|
|
1807
|
+
*
|
|
1808
|
+
* {@linkcode RolldownLog.code | code} will be set to `"PLUGIN_LOG"` by Rolldown.
|
|
1809
|
+
* As these logs are displayed by default, use them for information that is not a warning
|
|
1810
|
+
* but makes sense to display to all users on every build.
|
|
1811
|
+
*
|
|
1812
|
+
* {@include ./docs/plugin-context-info.md}
|
|
1813
|
+
*
|
|
1814
|
+
* @inlineType LoggingFunction
|
|
1815
|
+
* @group Logging Methods
|
|
1816
|
+
*/
|
|
1817
|
+
info: LoggingFunction;
|
|
1818
|
+
/**
|
|
1819
|
+
* Generate a `"warn"` level log.
|
|
1820
|
+
*
|
|
1821
|
+
* Just like internally generated warnings, these logs will be first passed to and
|
|
1822
|
+
* filtered by plugin {@linkcode Plugin.onLog | onLog} hooks before they are forwarded
|
|
1823
|
+
* to custom {@linkcode InputOptions.onLog | onLog} or
|
|
1824
|
+
* {@linkcode InputOptions.onwarn | onwarn} handlers or printed to the console.
|
|
1825
|
+
*
|
|
1826
|
+
* We encourage you to use objects with a {@linkcode RolldownLog.pluginCode | pluginCode}
|
|
1827
|
+
* property as that will allow users to easily filter for those logs in an `onLog` handler.
|
|
1828
|
+
*
|
|
1829
|
+
* {@include ./docs/plugin-context-warn.md}
|
|
1830
|
+
*
|
|
1831
|
+
* @inlineType LoggingFunction
|
|
1832
|
+
* @group Logging Methods
|
|
1833
|
+
*/
|
|
1834
|
+
warn: LoggingFunction;
|
|
1835
|
+
/**
|
|
1836
|
+
* Generate a `"debug"` level log.
|
|
1837
|
+
*
|
|
1838
|
+
* {@linkcode RolldownLog.code | code} will be set to `"PLUGIN_LOG"` by Rolldown.
|
|
1839
|
+
* Make sure to add a distinctive {@linkcode RolldownLog.pluginCode | pluginCode} to
|
|
1840
|
+
* those logs for easy filtering.
|
|
1841
|
+
*
|
|
1842
|
+
* {@include ./docs/plugin-context-debug.md}
|
|
1843
|
+
*
|
|
1844
|
+
* @inlineType LoggingFunction
|
|
1845
|
+
* @group Logging Methods
|
|
1846
|
+
*/
|
|
1847
|
+
debug: LoggingFunction;
|
|
1848
|
+
/** An object containing potentially useful metadata. */
|
|
1849
|
+
meta: PluginContextMeta;
|
|
1850
|
+
}
|
|
1851
|
+
//#endregion
|
|
1852
|
+
//#region src/plugin/parallel-plugin.d.ts
|
|
1853
|
+
type ParallelPlugin = {
|
|
1854
|
+
_parallel: {
|
|
1855
|
+
fileUrl: string;
|
|
1856
|
+
options: unknown;
|
|
1857
|
+
};
|
|
1858
|
+
};
|
|
1859
|
+
/** @internal */
|
|
1860
|
+
type DefineParallelPluginResult<Options> = (options: Options) => ParallelPlugin;
|
|
1861
|
+
declare function defineParallelPlugin<Options>(pluginPath: string): DefineParallelPluginResult<Options>;
|
|
1862
|
+
//#endregion
|
|
1863
|
+
//#region src/plugin/plugin-context.d.ts
|
|
1864
|
+
/**
|
|
1865
|
+
* Either a {@linkcode name} or a {@linkcode fileName} can be supplied.
|
|
1866
|
+
* If a {@linkcode fileName} is provided, it will be used unmodified as the name
|
|
1867
|
+
* of the generated file, throwing an error if this causes a conflict.
|
|
1868
|
+
* Otherwise, if a {@linkcode name} is supplied, this will be used as substitution
|
|
1869
|
+
* for `[name]` in the corresponding
|
|
1870
|
+
* {@linkcode OutputOptions.assetFileNames | output.assetFileNames} pattern, possibly
|
|
1871
|
+
* adding a unique number to the end of the file name to avoid conflicts.
|
|
1872
|
+
* If neither a {@linkcode name} nor {@linkcode fileName} is supplied, a default name will be used.
|
|
1873
|
+
*
|
|
1874
|
+
* @category Plugin APIs
|
|
1875
|
+
*/
|
|
1876
|
+
interface EmittedAsset {
|
|
1877
|
+
type: "asset";
|
|
1878
|
+
name?: string;
|
|
1879
|
+
fileName?: string;
|
|
1880
|
+
/**
|
|
1881
|
+
* An absolute path to the original file if this asset corresponds to a file on disk.
|
|
1882
|
+
*
|
|
1883
|
+
* This property will be passed on to subsequent plugin hooks that receive a
|
|
1884
|
+
* {@linkcode PreRenderedAsset} or an {@linkcode OutputAsset} like
|
|
1885
|
+
* {@linkcode Plugin.generateBundle | generateBundle}.
|
|
1886
|
+
* In watch mode, Rolldown will also automatically watch this file for changes and
|
|
1887
|
+
* trigger a rebuild if it changes. Therefore, it is not necessary to call
|
|
1888
|
+
* {@linkcode PluginContext.addWatchFile | this.addWatchFile} for this file.
|
|
1889
|
+
*/
|
|
1890
|
+
originalFileName?: string;
|
|
1891
|
+
source: AssetSource;
|
|
1892
|
+
}
|
|
1893
|
+
/**
|
|
1894
|
+
* Either a {@linkcode name} or a {@linkcode fileName} can be supplied.
|
|
1895
|
+
* If a {@linkcode fileName} is provided, it will be used unmodified as the name
|
|
1896
|
+
* of the generated file, throwing an error if this causes a conflict.
|
|
1897
|
+
* Otherwise, if a {@linkcode name} is supplied, this will be used as substitution
|
|
1898
|
+
* for `[name]` in the corresponding
|
|
1899
|
+
* {@linkcode OutputOptions.chunkFileNames | output.chunkFileNames} pattern, possibly
|
|
1900
|
+
* adding a unique number to the end of the file name to avoid conflicts.
|
|
1901
|
+
* If neither a {@linkcode name} nor {@linkcode fileName} is supplied, a default name will be used.
|
|
1902
|
+
*
|
|
1903
|
+
* @category Plugin APIs
|
|
1904
|
+
*/
|
|
1905
|
+
interface EmittedChunk {
|
|
1906
|
+
type: "chunk";
|
|
1907
|
+
name?: string;
|
|
1908
|
+
fileName?: string;
|
|
1909
|
+
/**
|
|
1910
|
+
* When provided, this will override
|
|
1911
|
+
* {@linkcode InputOptions.preserveEntrySignatures | preserveEntrySignatures} for this particular
|
|
1912
|
+
* chunk.
|
|
1913
|
+
*/
|
|
1914
|
+
preserveSignature?: "strict" | "allow-extension" | "exports-only" | false;
|
|
1915
|
+
/**
|
|
1916
|
+
* The module id of the entry point of the chunk.
|
|
1917
|
+
*
|
|
1918
|
+
* It will be passed through build hooks just like regular entry points,
|
|
1919
|
+
* starting with {@linkcode Plugin.resolveId | resolveId}.
|
|
1920
|
+
*/
|
|
1921
|
+
id: string;
|
|
1922
|
+
/**
|
|
1923
|
+
* The value to be passed to {@linkcode Plugin.resolveId | resolveId}'s {@linkcode importer} parameter when resolving the entry point.
|
|
1924
|
+
* This is important to properly resolve relative paths. If it is not provided,
|
|
1925
|
+
* paths will be resolved relative to the current working directory.
|
|
1926
|
+
*/
|
|
1927
|
+
importer?: string;
|
|
1928
|
+
}
|
|
1929
|
+
/** @category Plugin APIs */
|
|
1930
|
+
interface EmittedPrebuiltChunk {
|
|
1931
|
+
type: "prebuilt-chunk";
|
|
1932
|
+
fileName: string;
|
|
1933
|
+
/**
|
|
1934
|
+
* The code of this chunk.
|
|
1935
|
+
*/
|
|
1936
|
+
code: string;
|
|
1937
|
+
/**
|
|
1938
|
+
* The list of exported variable names from this chunk.
|
|
1939
|
+
*
|
|
1940
|
+
* This should be provided if the chunk exports any variables.
|
|
1941
|
+
*/
|
|
1942
|
+
exports?: string[];
|
|
1943
|
+
/**
|
|
1944
|
+
* The corresponding source map for this chunk.
|
|
1945
|
+
*/
|
|
1946
|
+
map?: SourceMap;
|
|
1947
|
+
sourcemapFileName?: string;
|
|
1948
|
+
}
|
|
1949
|
+
/** @inline @category Plugin APIs */
|
|
1950
|
+
type EmittedFile = EmittedAsset | EmittedChunk | EmittedPrebuiltChunk;
|
|
1951
|
+
/** @category Plugin APIs */
|
|
1952
|
+
interface PluginContextResolveOptions {
|
|
1953
|
+
/**
|
|
1954
|
+
* The value for {@linkcode ResolveIdExtraOptions.kind | kind} passed to
|
|
1955
|
+
* {@linkcode Plugin.resolveId | resolveId} hooks.
|
|
1956
|
+
*/
|
|
1957
|
+
kind?: BindingPluginContextResolveOptions["importKind"];
|
|
1958
|
+
/**
|
|
1959
|
+
* The value for {@linkcode ResolveIdExtraOptions.isEntry | isEntry} passed to
|
|
1960
|
+
* {@linkcode Plugin.resolveId | resolveId} hooks.
|
|
1961
|
+
*
|
|
1962
|
+
* @default `false` if there's an importer, `true` otherwise.
|
|
1963
|
+
*/
|
|
1964
|
+
isEntry?: boolean;
|
|
1965
|
+
/**
|
|
1966
|
+
* Whether the {@linkcode Plugin.resolveId | resolveId} hook of the plugin from
|
|
1967
|
+
* which {@linkcode PluginContext.resolve | this.resolve} is called will be skipped
|
|
1968
|
+
* when resolving.
|
|
1969
|
+
*
|
|
1970
|
+
* {@include ./docs/plugin-context-resolve-skipself.md}
|
|
1971
|
+
*
|
|
1972
|
+
* @default true
|
|
1973
|
+
*/
|
|
1974
|
+
skipSelf?: boolean;
|
|
1975
|
+
/**
|
|
1976
|
+
* Plugin-specific options.
|
|
1977
|
+
*
|
|
1978
|
+
* See [Custom resolver options section](https://rolldown.rs/apis/plugin-api/inter-plugin-communication#custom-resolver-options) for more details.
|
|
1979
|
+
*/
|
|
1980
|
+
custom?: CustomPluginOptions;
|
|
1981
|
+
}
|
|
1982
|
+
/** @inline */
|
|
1983
|
+
type GetModuleInfo = (moduleId: string) => ModuleInfo | null;
|
|
1984
|
+
/** @category Plugin APIs */
|
|
1985
|
+
interface PluginContext extends MinimalPluginContext {
|
|
1986
|
+
/**
|
|
1987
|
+
* Provides abstract access to the file system.
|
|
1988
|
+
*/
|
|
1989
|
+
fs: RolldownFsModule;
|
|
1990
|
+
/**
|
|
1991
|
+
* Emits a new file that is included in the build output.
|
|
1992
|
+
* You can emit chunks, prebuilt chunks or assets.
|
|
1993
|
+
*
|
|
1994
|
+
* {@include ./docs/plugin-context-emitfile.md}
|
|
1995
|
+
*
|
|
1996
|
+
* @returns A `referenceId` for the emitted file that can be used in various places to reference the emitted file.
|
|
1997
|
+
*/
|
|
1998
|
+
emitFile(file: EmittedFile): string;
|
|
1999
|
+
/**
|
|
2000
|
+
* Get the file name of a chunk or asset that has been emitted via
|
|
2001
|
+
* {@linkcode emitFile | this.emitFile}.
|
|
2002
|
+
*
|
|
2003
|
+
* @returns The file name of the emitted file. Relative to {@linkcode OutputOptions.dir | output.dir}.
|
|
2004
|
+
*/
|
|
2005
|
+
getFileName(referenceId: string): string;
|
|
2006
|
+
/**
|
|
2007
|
+
* Get all module ids in the current module graph.
|
|
2008
|
+
*
|
|
2009
|
+
* @returns
|
|
2010
|
+
* An iterator of module ids. It can be iterated via
|
|
2011
|
+
* ```js
|
|
2012
|
+
* for (const moduleId of this.getModuleIds()) {
|
|
2013
|
+
* // ...
|
|
2014
|
+
* }
|
|
2015
|
+
* ```
|
|
2016
|
+
* or converted into an array via `Array.from(this.getModuleIds())`.
|
|
2017
|
+
*/
|
|
2018
|
+
getModuleIds(): IterableIterator<string>;
|
|
2019
|
+
/**
|
|
2020
|
+
* Get additional information about the module in question.
|
|
2021
|
+
*
|
|
2022
|
+
* {@include ./docs/plugin-context-getmoduleinfo.md}
|
|
2023
|
+
*
|
|
2024
|
+
* @returns Module information for that module. `null` if the module could not be found.
|
|
2025
|
+
* @group Methods
|
|
2026
|
+
*/
|
|
2027
|
+
getModuleInfo: GetModuleInfo;
|
|
2028
|
+
/**
|
|
2029
|
+
* Adds additional files to be monitored in watch mode so that changes to these files will trigger rebuilds.
|
|
2030
|
+
*
|
|
2031
|
+
* {@include ./docs/plugin-context-addwatchfile.md}
|
|
2032
|
+
*/
|
|
2033
|
+
addWatchFile(id: string): void;
|
|
2034
|
+
/**
|
|
2035
|
+
* Loads and parses the module corresponding to the given id, attaching additional
|
|
2036
|
+
* meta information to the module if provided. This will trigger the same
|
|
2037
|
+
* {@linkcode Plugin.load | load}, {@linkcode Plugin.transform | transform} and
|
|
2038
|
+
* {@linkcode Plugin.moduleParsed | moduleParsed} hooks as if the module was imported
|
|
2039
|
+
* by another module.
|
|
2040
|
+
*
|
|
2041
|
+
* {@include ./docs/plugin-context-load.md}
|
|
2042
|
+
*/
|
|
2043
|
+
load(options: {
|
|
2044
|
+
id: string;
|
|
2045
|
+
resolveDependencies?: boolean;
|
|
2046
|
+
} & Partial<PartialNull<ModuleOptions>>): Promise<ModuleInfo>;
|
|
2047
|
+
/**
|
|
2048
|
+
* Use Rolldown's internal parser to parse code to an [ESTree-compatible](https://github.com/estree/estree) AST.
|
|
2049
|
+
*/
|
|
2050
|
+
parse(input: string, options?: ParserOptions | null): Program;
|
|
2051
|
+
/**
|
|
2052
|
+
* Resolve imports to module ids (i.e. file names) using the same plugins that Rolldown uses,
|
|
2053
|
+
* and determine if an import should be external.
|
|
2054
|
+
*
|
|
2055
|
+
* When calling this function from a {@linkcode Plugin.resolveId | resolveId} hook, you should
|
|
2056
|
+
* always check if it makes sense for you to pass along the
|
|
2057
|
+
* {@link PluginContextResolveOptions | options}.
|
|
2058
|
+
*
|
|
2059
|
+
* @returns
|
|
2060
|
+
* If `Promise<null>` is returned, the import could not be resolved by Rolldown or any plugin
|
|
2061
|
+
* but was not explicitly marked as external by the user.
|
|
2062
|
+
* If an absolute external id is returned that should remain absolute in the output either
|
|
2063
|
+
* via the
|
|
2064
|
+
* {@linkcode InputOptions.makeAbsoluteExternalsRelative | makeAbsoluteExternalsRelative}
|
|
2065
|
+
* option or by explicit plugin choice in the {@linkcode Plugin.resolveId | resolveId} hook,
|
|
2066
|
+
* `external` will be `"absolute"` instead of `true`.
|
|
2067
|
+
*/
|
|
2068
|
+
resolve(source: string, importer?: string, options?: PluginContextResolveOptions): Promise<ResolvedId | null>;
|
|
2069
|
+
}
|
|
2070
|
+
//#endregion
|
|
2071
|
+
//#region src/plugin/transform-plugin-context.d.ts
|
|
2072
|
+
/** @category Plugin APIs */
|
|
2073
|
+
interface TransformPluginContext extends PluginContext {
|
|
2074
|
+
/**
|
|
2075
|
+
* Same as {@linkcode PluginContext.debug}, but a `position` param can be supplied.
|
|
2076
|
+
*
|
|
2077
|
+
* @inlineType LoggingFunctionWithPosition
|
|
2078
|
+
* @group Logging Methods
|
|
2079
|
+
*/
|
|
2080
|
+
debug: LoggingFunctionWithPosition;
|
|
2081
|
+
/**
|
|
2082
|
+
* Same as {@linkcode PluginContext.info}, but a `position` param can be supplied.
|
|
2083
|
+
*
|
|
2084
|
+
* @inlineType LoggingFunctionWithPosition
|
|
2085
|
+
* @group Logging Methods
|
|
2086
|
+
*/
|
|
2087
|
+
info: LoggingFunctionWithPosition;
|
|
2088
|
+
/**
|
|
2089
|
+
* Same as {@linkcode PluginContext.warn}, but a `position` param can be supplied.
|
|
2090
|
+
*
|
|
2091
|
+
* @inlineType LoggingFunctionWithPosition
|
|
2092
|
+
* @group Logging Methods
|
|
2093
|
+
*/
|
|
2094
|
+
warn: LoggingFunctionWithPosition;
|
|
2095
|
+
/**
|
|
2096
|
+
* Same as {@linkcode PluginContext.error}, but the `id` of the current module will
|
|
2097
|
+
* also be added and a `position` param can be supplied.
|
|
2098
|
+
*/
|
|
2099
|
+
error(e: RolldownError | string, pos?: number | {
|
|
2100
|
+
column: number;
|
|
2101
|
+
line: number;
|
|
2102
|
+
}): never;
|
|
2103
|
+
/**
|
|
2104
|
+
* Get the combined source maps of all previous plugins.
|
|
2105
|
+
*/
|
|
2106
|
+
getCombinedSourcemap(): SourceMap;
|
|
2107
|
+
}
|
|
2108
|
+
//#endregion
|
|
2109
|
+
//#region src/types/module-side-effects.d.ts
|
|
2110
|
+
interface ModuleSideEffectsRule {
|
|
2111
|
+
test?: RegExp;
|
|
2112
|
+
external?: boolean;
|
|
2113
|
+
sideEffects: boolean;
|
|
2114
|
+
}
|
|
2115
|
+
type ModuleSideEffectsOption = boolean | readonly string[] | ModuleSideEffectsRule[] | ((id: string, external: boolean) => boolean | undefined) | "no-external";
|
|
2116
|
+
/**
|
|
2117
|
+
* When passing an object, you can fine-tune the tree-shaking behavior.
|
|
2118
|
+
*/
|
|
2119
|
+
type TreeshakingOptions = {
|
|
2120
|
+
/**
|
|
2121
|
+
* **Values:**
|
|
2122
|
+
*
|
|
2123
|
+
* - **`true`**: All modules are assumed to have side effects and will be included in the bundle even if none of their exports are used.
|
|
2124
|
+
* - **`false`**: No modules have side effects. This enables aggressive tree-shaking, removing any modules whose exports are not used.
|
|
2125
|
+
* - **`string[]`**: Array of module IDs that have side effects. Only modules in this list will be preserved if unused; all others can be tree-shaken when their exports are unused.
|
|
2126
|
+
* - **`'no-external'`**: Assumes no external modules have side effects while preserving the default behavior for local modules.
|
|
2127
|
+
* - **`ModuleSideEffectsRule[]`**: Array of rules with `test`, `external`, and `sideEffects` properties for fine-grained control.
|
|
2128
|
+
* - **`function`**: Function that receives `(id, external)` and returns whether the module has side effects.
|
|
2129
|
+
*
|
|
2130
|
+
* **Important:** Setting this to `false` or using an array/string assumes that your modules and their dependencies have no side effects other than their exports. Only use this if you're certain that removing unused modules won't break your application.
|
|
2131
|
+
*
|
|
2132
|
+
* > [!NOTE]
|
|
2133
|
+
* > **Performance: Prefer `ModuleSideEffectsRule[]` over functions**
|
|
2134
|
+
* >
|
|
2135
|
+
* > When possible, use rule-based configuration instead of functions. Rules are processed entirely in Rust, while JavaScript functions require runtime calls between Rust and JavaScript, which can hurt CPU utilization during builds.
|
|
2136
|
+
* >
|
|
2137
|
+
* > **Functions should be a last resort**: Only use the function signature when your logic cannot be expressed with patterns or simple string matching.
|
|
2138
|
+
* >
|
|
2139
|
+
* > **Rule advantages**: `ModuleSideEffectsRule[]` provides better performance by avoiding Rust-JavaScript runtime calls, clearer intent, and easier maintenance.
|
|
2140
|
+
*
|
|
2141
|
+
* @example
|
|
2142
|
+
* ```js
|
|
2143
|
+
* // Assume no modules have side effects (aggressive tree-shaking)
|
|
2144
|
+
* treeshake: {
|
|
2145
|
+
* moduleSideEffects: false
|
|
2146
|
+
* }
|
|
2147
|
+
*
|
|
2148
|
+
* // Only specific modules have side effects (string array)
|
|
2149
|
+
* treeshake: {
|
|
2150
|
+
* moduleSideEffects: [
|
|
2151
|
+
* 'lodash',
|
|
2152
|
+
* 'react-dom',
|
|
2153
|
+
* ]
|
|
2154
|
+
* }
|
|
2155
|
+
*
|
|
2156
|
+
* // Use rules for pattern matching and granular control
|
|
2157
|
+
* treeshake: {
|
|
2158
|
+
* moduleSideEffects: [
|
|
2159
|
+
* { test: /^node:/, sideEffects: true },
|
|
2160
|
+
* { test: /\.css$/, sideEffects: true },
|
|
2161
|
+
* { test: /some-package/, sideEffects: false, external: false },
|
|
2162
|
+
* ]
|
|
2163
|
+
* }
|
|
2164
|
+
*
|
|
2165
|
+
* // Custom function to determine side effects
|
|
2166
|
+
* treeshake: {
|
|
2167
|
+
* moduleSideEffects: (id, external) => {
|
|
2168
|
+
* if (external) return false; // external modules have no side effects
|
|
2169
|
+
* return id.includes('/side-effects/') || id.endsWith('.css');
|
|
2170
|
+
* }
|
|
2171
|
+
* }
|
|
2172
|
+
*
|
|
2173
|
+
* // Assume no external modules have side effects
|
|
2174
|
+
* treeshake: {
|
|
2175
|
+
* moduleSideEffects: 'no-external',
|
|
2176
|
+
* }
|
|
2177
|
+
* ```
|
|
2178
|
+
*
|
|
2179
|
+
* **Common Use Cases:**
|
|
2180
|
+
* - **CSS files**: `{ test: /\.css$/, sideEffects: true }` - preserve CSS imports
|
|
2181
|
+
* - **Polyfills**: Add specific polyfill modules to the array
|
|
2182
|
+
* - **Plugins**: Modules that register themselves globally on import
|
|
2183
|
+
* - **Library development**: Set to `false` for libraries where unused exports should be removed
|
|
2184
|
+
*
|
|
2185
|
+
* @default true
|
|
2186
|
+
*/
|
|
2187
|
+
moduleSideEffects?: ModuleSideEffectsOption;
|
|
2188
|
+
/**
|
|
2189
|
+
* Whether to respect `/*@__PURE__*\/` annotations and other tree-shaking hints in the code.
|
|
2190
|
+
*
|
|
2191
|
+
* See [related Oxc documentation](https://oxc.rs/docs/guide/usage/minifier/dead-code-elimination#pure-annotations) for more details.
|
|
2192
|
+
*
|
|
2193
|
+
* @default true
|
|
2194
|
+
*/
|
|
2195
|
+
annotations?: boolean;
|
|
2196
|
+
/**
|
|
2197
|
+
* Array of function names that should be considered pure (no side effects) even if they can't be automatically detected as pure.
|
|
2198
|
+
*
|
|
2199
|
+
* See [related Oxc documentation](https://oxc.rs/docs/guide/usage/minifier/dead-code-elimination#define-pure-functions) for more details.
|
|
2200
|
+
*
|
|
2201
|
+
* @example
|
|
2202
|
+
* ```js
|
|
2203
|
+
* treeshake: {
|
|
2204
|
+
* manualPureFunctions: ['console.log', 'debug.trace']
|
|
2205
|
+
* }
|
|
2206
|
+
* ```
|
|
2207
|
+
* @default []
|
|
2208
|
+
*/
|
|
2209
|
+
manualPureFunctions?: readonly string[];
|
|
2210
|
+
/**
|
|
2211
|
+
* Whether to assume that accessing unknown global properties might have side effects.
|
|
2212
|
+
*
|
|
2213
|
+
* See [related Oxc documentation](https://oxc.rs/docs/guide/usage/minifier/dead-code-elimination#ignoring-global-variable-access-side-effects) for more details.
|
|
2214
|
+
*
|
|
2215
|
+
* @default true
|
|
2216
|
+
*/
|
|
2217
|
+
unknownGlobalSideEffects?: boolean;
|
|
2218
|
+
/**
|
|
2219
|
+
* Whether to assume that invalid import statements might have side effects.
|
|
2220
|
+
*
|
|
2221
|
+
* See [related Oxc documentation](https://oxc.rs/docs/guide/usage/minifier/dead-code-elimination#ignoring-invalid-import-statement-side-effects) for more details.
|
|
2222
|
+
*
|
|
2223
|
+
* @default true
|
|
2224
|
+
*/
|
|
2225
|
+
invalidImportSideEffects?: boolean;
|
|
2226
|
+
/**
|
|
2227
|
+
* Whether to enable tree-shaking for CommonJS modules. When `true`, unused exports from CommonJS modules can be eliminated from the bundle, similar to ES modules. When disabled, CommonJS modules will always be included in their entirety.
|
|
2228
|
+
*
|
|
2229
|
+
* This option allows rolldown to analyze `exports.property` assignments in CommonJS modules and remove unused exports while preserving the module's side effects.
|
|
2230
|
+
*
|
|
2231
|
+
* @example
|
|
2232
|
+
* ```js
|
|
2233
|
+
* // source.js (CommonJS)
|
|
2234
|
+
* exports.used = 'This will be kept';
|
|
2235
|
+
* exports.unused = 'This will be tree-shaken away';
|
|
2236
|
+
*
|
|
2237
|
+
* // main.js
|
|
2238
|
+
* import { used } from './source.js';
|
|
2239
|
+
* // With commonjs: true, only the 'used' export is included in the bundle
|
|
2240
|
+
* // With commonjs: false, both exports are included
|
|
2241
|
+
* ```
|
|
2242
|
+
* @default true
|
|
2243
|
+
*/
|
|
2244
|
+
commonjs?: boolean;
|
|
2245
|
+
/**
|
|
2246
|
+
* Controls whether reading properties from objects is considered to have side effects.
|
|
2247
|
+
*
|
|
2248
|
+
* Set to `false` for more aggressive tree-shaking behavior.
|
|
2249
|
+
*
|
|
2250
|
+
* See [related Oxc documentation](https://oxc.rs/docs/guide/usage/minifier/dead-code-elimination#ignoring-property-read-side-effects) for more details.
|
|
2251
|
+
*
|
|
2252
|
+
* @default 'always'
|
|
2253
|
+
*/
|
|
2254
|
+
propertyReadSideEffects?: false | "always";
|
|
2255
|
+
/**
|
|
2256
|
+
* Controls whether writing properties to objects is considered to have side effects.
|
|
2257
|
+
*
|
|
2258
|
+
* Set to `false` for more aggressive behavior.
|
|
2259
|
+
*
|
|
2260
|
+
* @default 'always'
|
|
2261
|
+
*/
|
|
2262
|
+
propertyWriteSideEffects?: false | "always";
|
|
2263
|
+
};
|
|
2264
|
+
//#endregion
|
|
2265
|
+
//#region src/types/output-bundle.d.ts
|
|
2266
|
+
/** @category Plugin APIs */
|
|
2267
|
+
interface OutputBundle {
|
|
2268
|
+
[fileName: string]: OutputAsset | OutputChunk;
|
|
2269
|
+
}
|
|
2270
|
+
//#endregion
|
|
2271
|
+
//#region src/types/sourcemap.d.ts
|
|
2272
|
+
/** @category Plugin APIs */
|
|
2273
|
+
interface ExistingRawSourceMap {
|
|
2274
|
+
file?: string | null;
|
|
2275
|
+
mappings: string;
|
|
2276
|
+
names?: string[];
|
|
2277
|
+
sources?: (string | null)[];
|
|
2278
|
+
sourcesContent?: (string | null)[];
|
|
2279
|
+
sourceRoot?: string;
|
|
2280
|
+
version?: number;
|
|
2281
|
+
x_google_ignoreList?: number[];
|
|
2282
|
+
}
|
|
2283
|
+
/** @inline @category Plugin APIs */
|
|
2284
|
+
type SourceMapInput = ExistingRawSourceMap | string | null;
|
|
2285
|
+
//#endregion
|
|
2286
|
+
//#region src/version.d.ts
|
|
2287
|
+
/**
|
|
2288
|
+
* The version of Rolldown.
|
|
2289
|
+
* @example `'1.0.0'`
|
|
2290
|
+
*
|
|
2291
|
+
* @category Plugin APIs
|
|
2292
|
+
*/
|
|
2293
|
+
declare const VERSION: string;
|
|
2294
|
+
//#endregion
|
|
2295
|
+
//#region src/builtin-plugin/utils.d.ts
|
|
2296
|
+
declare class BuiltinPlugin {
|
|
2297
|
+
name: BindingBuiltinPluginName;
|
|
2298
|
+
_options?: unknown;
|
|
2299
|
+
/** Vite-specific option to control plugin ordering */
|
|
2300
|
+
enforce?: "pre" | "post";
|
|
2301
|
+
constructor(name: BindingBuiltinPluginName, _options?: unknown);
|
|
2302
|
+
}
|
|
2303
|
+
//#endregion
|
|
2304
|
+
//#region src/constants/plugin.d.ts
|
|
2305
|
+
declare const ENUMERATED_INPUT_PLUGIN_HOOK_NAMES: readonly ["options", "buildStart", "resolveId", "load", "transform", "moduleParsed", "buildEnd", "onLog", "resolveDynamicImport", "closeBundle", "closeWatcher", "watchChange"];
|
|
2306
|
+
declare const ENUMERATED_OUTPUT_PLUGIN_HOOK_NAMES: readonly ["augmentChunkHash", "outputOptions", "renderChunk", "renderStart", "renderError", "writeBundle", "generateBundle"];
|
|
2307
|
+
declare const ENUMERATED_PLUGIN_HOOK_NAMES: [...typeof ENUMERATED_INPUT_PLUGIN_HOOK_NAMES, ...typeof ENUMERATED_OUTPUT_PLUGIN_HOOK_NAMES, "footer", "banner", "intro", "outro"];
|
|
2308
|
+
/**
|
|
2309
|
+
* Names of all defined hooks. It's like
|
|
2310
|
+
* ```ts
|
|
2311
|
+
* type DefinedHookNames = {
|
|
2312
|
+
* options: 'options',
|
|
2313
|
+
* buildStart: 'buildStart',
|
|
2314
|
+
* ...
|
|
2315
|
+
* }
|
|
2316
|
+
* ```
|
|
2317
|
+
*/
|
|
2318
|
+
type DefinedHookNames = { readonly [K in (typeof ENUMERATED_PLUGIN_HOOK_NAMES)[number]]: K };
|
|
2319
|
+
/**
|
|
2320
|
+
* Names of all defined hooks. It's like
|
|
2321
|
+
* ```js
|
|
2322
|
+
* const DEFINED_HOOK_NAMES ={
|
|
2323
|
+
* options: 'options',
|
|
2324
|
+
* buildStart: 'buildStart',
|
|
2325
|
+
* ...
|
|
2326
|
+
* }
|
|
2327
|
+
* ```
|
|
2328
|
+
*/
|
|
2329
|
+
declare const DEFINED_HOOK_NAMES: DefinedHookNames;
|
|
2330
|
+
//#endregion
|
|
2331
|
+
//#region src/plugin/with-filter.d.ts
|
|
2332
|
+
type OverrideFilterObject = {
|
|
2333
|
+
transform?: HookFilterExtension<"transform">["filter"];
|
|
2334
|
+
resolveId?: HookFilterExtension<"resolveId">["filter"];
|
|
2335
|
+
load?: HookFilterExtension<"load">["filter"];
|
|
2336
|
+
pluginNamePattern?: StringOrRegExp[];
|
|
2337
|
+
};
|
|
2338
|
+
declare function withFilter<A, T extends RolldownPluginOption<A>>(pluginOption: T, filterObject: OverrideFilterObject | OverrideFilterObject[]): T;
|
|
2339
|
+
//#endregion
|
|
2340
|
+
//#region src/plugin/index.d.ts
|
|
2341
|
+
type ModuleSideEffects = boolean | "no-treeshake" | null;
|
|
2342
|
+
/** @category Plugin APIs */
|
|
2343
|
+
type ModuleType = "js" | "jsx" | "ts" | "tsx" | "json" | "text" | "base64" | "dataurl" | "binary" | "empty" | (string & {});
|
|
2344
|
+
/** @category Plugin APIs */
|
|
2345
|
+
type ImportKind = BindingHookResolveIdExtraArgs["kind"];
|
|
2346
|
+
/** @category Plugin APIs */
|
|
2347
|
+
interface CustomPluginOptions {
|
|
2348
|
+
[plugin: string]: any;
|
|
2349
|
+
}
|
|
2350
|
+
/** @category Plugin APIs */
|
|
2351
|
+
interface ModuleOptions {
|
|
2352
|
+
moduleSideEffects: ModuleSideEffects;
|
|
2353
|
+
/** See [Custom module meta-data section](https://rolldown.rs/apis/plugin-api/inter-plugin-communication#custom-module-meta-data) for more details. */
|
|
2354
|
+
meta: CustomPluginOptions;
|
|
2355
|
+
invalidate?: boolean;
|
|
2356
|
+
packageJsonPath?: string;
|
|
2357
|
+
}
|
|
2358
|
+
/** @category Plugin APIs */
|
|
2359
|
+
interface ResolvedId extends ModuleOptions {
|
|
2360
|
+
external: boolean | "absolute";
|
|
2361
|
+
id: string;
|
|
2362
|
+
}
|
|
2363
|
+
interface SpecifiedModuleOptions {
|
|
2364
|
+
/**
|
|
2365
|
+
* Indicates whether the module has side effects to Rolldown.
|
|
2366
|
+
*
|
|
2367
|
+
* - If `false` is set and no other module imports anything from this module, then this module will not be included in the bundle even if the module would have side effects.
|
|
2368
|
+
* - If `true` is set, Rolldown will use its default algorithm to include all statements in the module that has side effects.
|
|
2369
|
+
* - If `"no-treeshake"` is set, treeshaking will be disabled for this module, and this module will be included in one of the chunks even if it is empty.
|
|
2370
|
+
*
|
|
2371
|
+
* The precedence of this option is as follows (highest to lowest):
|
|
2372
|
+
* 1. {@linkcode Plugin.transform | transform} hook's returned `moduleSideEffects` option
|
|
2373
|
+
* 2. {@linkcode Plugin.load | load} hook's returned `moduleSideEffects` option
|
|
2374
|
+
* 3. {@linkcode Plugin.resolveId | resolveId} hook's returned `moduleSideEffects` option
|
|
2375
|
+
* 4. {@linkcode TreeshakingOptions.moduleSideEffects | treeshake.moduleSideEffects} option
|
|
2376
|
+
* 5. `sideEffects` field in the `package.json` file
|
|
2377
|
+
* 6. `true` (default)
|
|
2378
|
+
*/
|
|
2379
|
+
moduleSideEffects?: ModuleSideEffects | null;
|
|
2380
|
+
}
|
|
2381
|
+
/** @category Plugin APIs */
|
|
2382
|
+
interface PartialResolvedId extends SpecifiedModuleOptions, Partial<PartialNull<ModuleOptions>> {
|
|
2383
|
+
/**
|
|
2384
|
+
* Whether this id should be treated as external.
|
|
2385
|
+
*
|
|
2386
|
+
* Relative external ids, i.e. ids starting with `./` or `../`, will not be internally
|
|
2387
|
+
* converted to an absolute id and converted back to a relative id in the output,
|
|
2388
|
+
* but are instead included in the output unchanged.
|
|
2389
|
+
* If you want relative ids to be re-normalized and deduplicated instead, return
|
|
2390
|
+
* an absolute file system location as id and choose `external: "relative"`.
|
|
2391
|
+
*
|
|
2392
|
+
* - If `true`, absolute ids will be converted to relative ids based on the user's choice for the {@linkcode InputOptions.makeAbsoluteExternalsRelative | makeAbsoluteExternalsRelative} option.
|
|
2393
|
+
* - If `'relative'`, absolute ids will always be converted to relative ids.
|
|
2394
|
+
* - If `'absolute'`, absolute ids will always be kept as absolute ids.
|
|
2395
|
+
*/
|
|
2396
|
+
external?: boolean | "absolute" | "relative";
|
|
2397
|
+
id: string;
|
|
2398
|
+
}
|
|
2399
|
+
/** @category Plugin APIs */
|
|
2400
|
+
interface SourceDescription extends SpecifiedModuleOptions, Partial<PartialNull<ModuleOptions>> {
|
|
2401
|
+
code: string;
|
|
2402
|
+
/**
|
|
2403
|
+
* The source map for the transformation.
|
|
2404
|
+
*
|
|
2405
|
+
* If the transformation does not move code, you can preserve existing sourcemaps by setting this to `null`.
|
|
2406
|
+
*
|
|
2407
|
+
* See [Source Code Transformations section](https://rolldown.rs/apis/plugin-api/transformations#source-code-transformations) for more details.
|
|
2408
|
+
*/
|
|
2409
|
+
map?: SourceMapInput;
|
|
2410
|
+
moduleType?: ModuleType;
|
|
2411
|
+
}
|
|
2412
|
+
/** @inline */
|
|
2413
|
+
interface ResolveIdExtraOptions {
|
|
2414
|
+
custom?: CustomPluginOptions;
|
|
2415
|
+
/**
|
|
2416
|
+
* Whether this is resolution for an entry point.
|
|
2417
|
+
*
|
|
2418
|
+
* {@include ./docs/plugin-hooks-resolveid-isentry.md}
|
|
2419
|
+
*/
|
|
2420
|
+
isEntry: boolean;
|
|
2421
|
+
kind: BindingHookResolveIdExtraArgs["kind"];
|
|
2422
|
+
}
|
|
2423
|
+
/** @inline @category Plugin APIs */
|
|
2424
|
+
type ResolveIdResult = string | NullValue | false | PartialResolvedId;
|
|
2425
|
+
/** @inline @category Plugin APIs */
|
|
2426
|
+
type LoadResult = NullValue | string | SourceDescription;
|
|
2427
|
+
/** @inline @category Plugin APIs */
|
|
2428
|
+
type TransformResult = NullValue | string | (Omit<SourceDescription, "code"> & {
|
|
2429
|
+
code?: string | BindingMagicString;
|
|
2430
|
+
});
|
|
2431
|
+
type RenderedChunkMeta = {
|
|
2432
|
+
/**
|
|
2433
|
+
* Contains information about all chunks that are being rendered.
|
|
2434
|
+
* This is useful to explore the entire chunk graph.
|
|
2435
|
+
*/
|
|
2436
|
+
chunks: Record<string, RenderedChunk>;
|
|
2437
|
+
/**
|
|
2438
|
+
* A lazily-created MagicString instance for the chunk's code.
|
|
2439
|
+
* Use this to perform string transformations with automatic source map support.
|
|
2440
|
+
* This is only available when `experimental.nativeMagicString` is enabled.
|
|
2441
|
+
*/
|
|
2442
|
+
magicString?: BindingMagicString;
|
|
2443
|
+
};
|
|
2444
|
+
/** @category Plugin APIs */
|
|
2445
|
+
interface FunctionPluginHooks {
|
|
2446
|
+
/**
|
|
2447
|
+
* A function that receives and filters logs and warnings generated by Rolldown and
|
|
2448
|
+
* plugins before they are passed to the {@linkcode InputOptions.onLog | onLog} option
|
|
2449
|
+
* or printed to the console.
|
|
2450
|
+
*
|
|
2451
|
+
* If `false` is returned, the log will be filtered out.
|
|
2452
|
+
* Otherwise, the log will be handed to the `onLog` hook of the next plugin,
|
|
2453
|
+
* the {@linkcode InputOptions.onLog | onLog} option, or printed to the console.
|
|
2454
|
+
* Plugins can also change the log level of a log or turn a log into an error by passing
|
|
2455
|
+
* the `log` object to {@linkcode MinimalPluginContext.error | this.error},
|
|
2456
|
+
* {@linkcode MinimalPluginContext.warn | this.warn},
|
|
2457
|
+
* {@linkcode MinimalPluginContext.info | this.info} or
|
|
2458
|
+
* {@linkcode MinimalPluginContext.debug | this.debug} and returning `false`.
|
|
2459
|
+
*
|
|
2460
|
+
* {@include ./docs/plugin-hooks-onlog.md}
|
|
2461
|
+
*
|
|
2462
|
+
* @group Build Hooks
|
|
2463
|
+
*/
|
|
2464
|
+
[DEFINED_HOOK_NAMES.onLog]: (this: MinimalPluginContext, level: LogLevel, log: RolldownLog) => NullValue | boolean;
|
|
2465
|
+
/**
|
|
2466
|
+
* Replaces or manipulates the options object passed to {@linkcode rolldown | rolldown()}.
|
|
2467
|
+
*
|
|
2468
|
+
* Returning `null` does not replace anything.
|
|
2469
|
+
*
|
|
2470
|
+
* If you just need to read the options, it is recommended to use
|
|
2471
|
+
* the {@linkcode buildStart} hook as that hook has access to the options
|
|
2472
|
+
* after the transformations from all `options` hooks have been taken into account.
|
|
2473
|
+
*
|
|
2474
|
+
* @group Build Hooks
|
|
2475
|
+
*/
|
|
2476
|
+
[DEFINED_HOOK_NAMES.options]: (this: MinimalPluginContext, options: InputOptions) => NullValue | InputOptions;
|
|
2477
|
+
/**
|
|
2478
|
+
* Replaces or manipulates the output options object passed to
|
|
2479
|
+
* {@linkcode RolldownBuild.generate | bundle.generate()} or
|
|
2480
|
+
* {@linkcode RolldownBuild.write | bundle.write()}.
|
|
2481
|
+
*
|
|
2482
|
+
* Returning null does not replace anything.
|
|
2483
|
+
*
|
|
2484
|
+
* If you just need to read the output options, it is recommended to use
|
|
2485
|
+
* the {@linkcode renderStart} hook as this hook has access to the output options
|
|
2486
|
+
* after the transformations from all `outputOptions` hooks have been taken into account.
|
|
2487
|
+
*
|
|
2488
|
+
* @group Build Hooks
|
|
2489
|
+
*/
|
|
2490
|
+
[DEFINED_HOOK_NAMES.outputOptions]: (this: MinimalPluginContext, options: OutputOptions) => NullValue | OutputOptions;
|
|
2491
|
+
/**
|
|
2492
|
+
* Called on each {@linkcode rolldown | rolldown()} build.
|
|
2493
|
+
*
|
|
2494
|
+
* This is the recommended hook to use when you need access to the options passed to {@linkcode rolldown | rolldown()} as it takes the transformations by all options hooks into account and also contains the right default values for unset options.
|
|
2495
|
+
*
|
|
2496
|
+
* @group Build Hooks
|
|
2497
|
+
*/
|
|
2498
|
+
[DEFINED_HOOK_NAMES.buildStart]: (this: PluginContext, options: NormalizedInputOptions) => void;
|
|
2499
|
+
/**
|
|
2500
|
+
* Defines a custom resolver.
|
|
2501
|
+
*
|
|
2502
|
+
* A resolver can be useful for e.g. locating third-party dependencies.
|
|
2503
|
+
*
|
|
2504
|
+
* Returning `null` defers to other `resolveId` hooks and eventually the default resolution behavior.
|
|
2505
|
+
* Returning `false` signals that `source` should be treated as an external module and not included in the bundle. If this happens for a relative import, the id will be renormalized the same way as when the {@linkcode InputOptions.external} option is used.
|
|
2506
|
+
* If you return an object, then it is possible to resolve an import to a different id while excluding it from the bundle at the same time.
|
|
2507
|
+
*
|
|
2508
|
+
* Note that while `resolveId` will be called for each import of a module and can therefore
|
|
2509
|
+
* resolve to the same `id` many times, values for `external`, `meta` or `moduleSideEffects`
|
|
2510
|
+
* can only be set once before the module is loaded. The reason is that after this call,
|
|
2511
|
+
* Rolldown will continue with the {@linkcode load} and {@linkcode transform} hooks for that
|
|
2512
|
+
* module that may override these values and should take precedence if they do so.
|
|
2513
|
+
*
|
|
2514
|
+
* @group Build Hooks
|
|
2515
|
+
*/
|
|
2516
|
+
[DEFINED_HOOK_NAMES.resolveId]: (this: PluginContext, source: string, importer: string | undefined, extraOptions: ResolveIdExtraOptions) => ResolveIdResult;
|
|
2517
|
+
/**
|
|
2518
|
+
* Defines a custom resolver for dynamic imports.
|
|
2519
|
+
*
|
|
2520
|
+
* @deprecated
|
|
2521
|
+
* This hook exists only for Rollup compatibility. Please use {@linkcode resolveId} instead.
|
|
2522
|
+
*
|
|
2523
|
+
* @group Build Hooks
|
|
2524
|
+
*/
|
|
2525
|
+
[DEFINED_HOOK_NAMES.resolveDynamicImport]: (this: PluginContext, source: string, importer: string | undefined) => ResolveIdResult;
|
|
2526
|
+
/**
|
|
2527
|
+
* Defines a custom loader.
|
|
2528
|
+
*
|
|
2529
|
+
* Returning `null` defers to other `load` hooks or the built-in loading mechanism.
|
|
2530
|
+
*
|
|
2531
|
+
* You can use {@linkcode PluginContext.getModuleInfo | this.getModuleInfo()} to find out the previous values of `meta`, `moduleSideEffects` inside this hook.
|
|
2532
|
+
*
|
|
2533
|
+
* @group Build Hooks
|
|
2534
|
+
*/
|
|
2535
|
+
[DEFINED_HOOK_NAMES.load]: (this: PluginContext, id: string) => MaybePromise<LoadResult>;
|
|
2536
|
+
/**
|
|
2537
|
+
* Can be used to transform individual modules.
|
|
2538
|
+
*
|
|
2539
|
+
* Note that it's possible to return only properties and no code transformations.
|
|
2540
|
+
*
|
|
2541
|
+
* You can use {@linkcode PluginContext.getModuleInfo | this.getModuleInfo()} to find out the previous values of `meta`, `moduleSideEffects` inside this hook.
|
|
2542
|
+
*
|
|
2543
|
+
* @group Build Hooks
|
|
2544
|
+
*/
|
|
2545
|
+
[DEFINED_HOOK_NAMES.transform]: (this: TransformPluginContext, code: string, id: string, meta: BindingTransformHookExtraArgs & {
|
|
2546
|
+
moduleType: ModuleType;
|
|
2547
|
+
magicString?: BindingMagicString;
|
|
2548
|
+
ast?: Program;
|
|
2549
|
+
}) => TransformResult;
|
|
2550
|
+
/**
|
|
2551
|
+
* This hook is called each time a module has been fully parsed by Rolldown.
|
|
2552
|
+
*
|
|
2553
|
+
* This hook will wait until all imports are resolved so that the information in
|
|
2554
|
+
* {@linkcode ModuleInfo.importedIds | moduleInfo.importedIds},
|
|
2555
|
+
* {@linkcode ModuleInfo.dynamicallyImportedIds | moduleInfo.dynamicallyImportedIds}
|
|
2556
|
+
* are complete and accurate. Note however that information about importing modules
|
|
2557
|
+
* may be incomplete as additional importers could be discovered later.
|
|
2558
|
+
* If you need this information, use the {@linkcode buildEnd} hook.
|
|
2559
|
+
*
|
|
2560
|
+
* @group Build Hooks
|
|
2561
|
+
*/
|
|
2562
|
+
[DEFINED_HOOK_NAMES.moduleParsed]: (this: PluginContext, moduleInfo: ModuleInfo) => void;
|
|
2563
|
+
/**
|
|
2564
|
+
* Called when Rolldown has finished bundling, but before Output Generation Hooks.
|
|
2565
|
+
* If an error occurred during the build, it is passed on to this hook.
|
|
2566
|
+
*
|
|
2567
|
+
* @group Build Hooks
|
|
2568
|
+
*/
|
|
2569
|
+
[DEFINED_HOOK_NAMES.buildEnd]: (this: PluginContext, err?: Error) => void;
|
|
2570
|
+
/**
|
|
2571
|
+
* Called initially each time {@linkcode RolldownBuild.generate | bundle.generate()} or
|
|
2572
|
+
* {@linkcode RolldownBuild.write | bundle.write()} is called.
|
|
2573
|
+
*
|
|
2574
|
+
* To get notified when generation has completed, use the {@linkcode generateBundle} and
|
|
2575
|
+
* {@linkcode renderError} hooks.
|
|
2576
|
+
*
|
|
2577
|
+
* This is the recommended hook to use when you need access to the output options passed to
|
|
2578
|
+
* {@linkcode RolldownBuild.generate | bundle.generate()} or
|
|
2579
|
+
* {@linkcode RolldownBuild.write | bundle.write()} as it takes the transformations by all outputOptions hooks into account and also contains the right default values for unset options.
|
|
2580
|
+
*
|
|
2581
|
+
* It also receives the input options passed to {@linkcode rolldown | rolldown()} so that
|
|
2582
|
+
* plugins that can be used as output plugins, i.e. plugins that only use generate phase hooks,
|
|
2583
|
+
* can get access to them.
|
|
2584
|
+
*
|
|
2585
|
+
* @group Output Generation Hooks
|
|
2586
|
+
*/
|
|
2587
|
+
[DEFINED_HOOK_NAMES.renderStart]: (this: PluginContext, outputOptions: NormalizedOutputOptions, inputOptions: NormalizedInputOptions) => void;
|
|
2588
|
+
/**
|
|
2589
|
+
* Can be used to transform individual chunks. Called for each Rolldown output chunk file.
|
|
2590
|
+
*
|
|
2591
|
+
* Returning null will apply no transformations. If you change code in this hook and want to support source maps, you need to return a map describing your changes, see [Source Code Transformations section](https://rolldown.rs/apis/plugin-api/transformations#source-code-transformations).
|
|
2592
|
+
*
|
|
2593
|
+
* `chunk` is mutable and changes applied in this hook will propagate to other plugins and
|
|
2594
|
+
* to the generated bundle.
|
|
2595
|
+
* That means if you add or remove imports or exports in this hook, you should update
|
|
2596
|
+
* {@linkcode RenderedChunk.imports | imports}, {@linkcode RenderedChunk.importedBindings | importedBindings} and/or {@linkcode RenderedChunk.exports | exports} accordingly.
|
|
2597
|
+
*
|
|
2598
|
+
* @group Output Generation Hooks
|
|
2599
|
+
*/
|
|
2600
|
+
[DEFINED_HOOK_NAMES.renderChunk]: (this: PluginContext, code: string, chunk: RenderedChunk, outputOptions: NormalizedOutputOptions, meta: RenderedChunkMeta) => NullValue | string | BindingMagicString | {
|
|
2601
|
+
code: string | BindingMagicString;
|
|
2602
|
+
map?: SourceMapInput;
|
|
2603
|
+
};
|
|
2604
|
+
/**
|
|
2605
|
+
* Can be used to augment the hash of individual chunks. Called for each Rolldown output chunk.
|
|
2606
|
+
*
|
|
2607
|
+
* Returning a falsy value will not modify the hash.
|
|
2608
|
+
* Truthy values will be used as an additional source for hash calculation.
|
|
2609
|
+
*
|
|
2610
|
+
* {@include ./docs/plugin-hooks-augmentchunkhash.md}
|
|
2611
|
+
*
|
|
2612
|
+
* @group Output Generation Hooks
|
|
2613
|
+
*/
|
|
2614
|
+
[DEFINED_HOOK_NAMES.augmentChunkHash]: (this: PluginContext, chunk: RenderedChunk) => string | void;
|
|
2615
|
+
/**
|
|
2616
|
+
* Called when Rolldown encounters an error during
|
|
2617
|
+
* {@linkcode RolldownBuild.generate | bundle.generate()} or
|
|
2618
|
+
* {@linkcode RolldownBuild.write | bundle.write()}.
|
|
2619
|
+
*
|
|
2620
|
+
* To get notified when generation completes successfully, use the
|
|
2621
|
+
* {@linkcode generateBundle} hook.
|
|
2622
|
+
*
|
|
2623
|
+
* @group Output Generation Hooks
|
|
2624
|
+
*/
|
|
2625
|
+
[DEFINED_HOOK_NAMES.renderError]: (this: PluginContext, error: Error) => void;
|
|
2626
|
+
/**
|
|
2627
|
+
* Called at the end of {@linkcode RolldownBuild.generate | bundle.generate()} or
|
|
2628
|
+
* immediately before the files are written in
|
|
2629
|
+
* {@linkcode RolldownBuild.write | bundle.write()}.
|
|
2630
|
+
*
|
|
2631
|
+
* To modify the files after they have been written, use the {@linkcode writeBundle} hook.
|
|
2632
|
+
*
|
|
2633
|
+
* {@include ./docs/plugin-hooks-generatebundle.md}
|
|
2634
|
+
*
|
|
2635
|
+
* @group Output Generation Hooks
|
|
2636
|
+
*/
|
|
2637
|
+
[DEFINED_HOOK_NAMES.generateBundle]: (this: PluginContext, outputOptions: NormalizedOutputOptions, bundle: OutputBundle, isWrite: boolean) => void;
|
|
2638
|
+
/**
|
|
2639
|
+
* Called only at the end of {@linkcode RolldownBuild.write | bundle.write()} once
|
|
2640
|
+
* all files have been written.
|
|
2641
|
+
*
|
|
2642
|
+
* @group Output Generation Hooks
|
|
2643
|
+
*/
|
|
2644
|
+
[DEFINED_HOOK_NAMES.writeBundle]: (this: PluginContext, outputOptions: NormalizedOutputOptions, bundle: OutputBundle) => void;
|
|
2645
|
+
/**
|
|
2646
|
+
* Can be used to clean up any external service that may be running.
|
|
2647
|
+
*
|
|
2648
|
+
* Rolldown's CLI will make sure this hook is called after each run, but it is the responsibility
|
|
2649
|
+
* of users of the JavaScript API to manually call
|
|
2650
|
+
* {@linkcode RolldownBuild.close | bundle.close()} once they are done generating bundles.
|
|
2651
|
+
* For that reason, any plugin relying on this feature should carefully mention this in
|
|
2652
|
+
* its documentation.
|
|
2653
|
+
*
|
|
2654
|
+
* If a plugin wants to retain resources across builds in watch mode, they can check for
|
|
2655
|
+
* {@linkcode PluginContextMeta.watchMode | this.meta.watchMode} in this hook and perform
|
|
2656
|
+
* the necessary cleanup for watch mode in closeWatcher.
|
|
2657
|
+
*
|
|
2658
|
+
* @group Output Generation Hooks
|
|
2659
|
+
*/
|
|
2660
|
+
[DEFINED_HOOK_NAMES.closeBundle]: (this: PluginContext, error?: Error) => void;
|
|
2661
|
+
/**
|
|
2662
|
+
* Notifies a plugin whenever Rolldown has detected a change to a monitored file in watch mode.
|
|
2663
|
+
*
|
|
2664
|
+
* If a build is currently running, this hook is called once the build finished.
|
|
2665
|
+
* It will be called once for every file that changed.
|
|
2666
|
+
*
|
|
2667
|
+
* This hook cannot be used by output plugins.
|
|
2668
|
+
*
|
|
2669
|
+
* If you need to be notified immediately when a file changed, you can use the {@linkcode WatcherOptions.onInvalidate | watch.onInvalidate} option.
|
|
2670
|
+
*
|
|
2671
|
+
* @group Build Hooks
|
|
2672
|
+
*/
|
|
2673
|
+
[DEFINED_HOOK_NAMES.watchChange]: (this: PluginContext, id: string, event: {
|
|
2674
|
+
event: ChangeEvent;
|
|
2675
|
+
}) => void;
|
|
2676
|
+
/**
|
|
2677
|
+
* Notifies a plugin when the watcher process will close so that all open resources can be closed too.
|
|
2678
|
+
*
|
|
2679
|
+
* This hook cannot be used by output plugins.
|
|
2680
|
+
*
|
|
2681
|
+
* @group Build Hooks
|
|
2682
|
+
*/
|
|
2683
|
+
[DEFINED_HOOK_NAMES.closeWatcher]: (this: PluginContext) => void;
|
|
2684
|
+
}
|
|
2685
|
+
type ChangeEvent = "create" | "update" | "delete";
|
|
2686
|
+
type PluginOrder = "pre" | "post" | null;
|
|
2687
|
+
/** @inline */
|
|
2688
|
+
type ObjectHookMeta = {
|
|
2689
|
+
order?: PluginOrder;
|
|
2690
|
+
};
|
|
2691
|
+
/**
|
|
2692
|
+
* A hook in a function or an object form with additional properties.
|
|
2693
|
+
*
|
|
2694
|
+
* @typeParam T - The type of the hook function.
|
|
2695
|
+
* @typeParam O - Additional properties that are specific to some hooks.
|
|
2696
|
+
*
|
|
2697
|
+
* {@include ./docs/object-hook.md}
|
|
2698
|
+
*
|
|
2699
|
+
* @category Plugin APIs
|
|
2700
|
+
*/
|
|
2701
|
+
type ObjectHook<T, O = {}> = T | ({
|
|
2702
|
+
handler: T;
|
|
2703
|
+
} & ObjectHookMeta & O);
|
|
2704
|
+
type SyncPluginHooks = DefinedHookNames["augmentChunkHash" | "onLog" | "outputOptions"];
|
|
2705
|
+
/** @category Plugin APIs */
|
|
2706
|
+
type AsyncPluginHooks = Exclude<keyof FunctionPluginHooks, SyncPluginHooks>;
|
|
2707
|
+
type FirstPluginHooks = DefinedHookNames["load" | "resolveDynamicImport" | "resolveId"];
|
|
2708
|
+
type SequentialPluginHooks = DefinedHookNames["augmentChunkHash" | "generateBundle" | "onLog" | "options" | "outputOptions" | "renderChunk" | "transform"];
|
|
2709
|
+
interface AddonHooks {
|
|
2710
|
+
/**
|
|
2711
|
+
* A hook equivalent to {@linkcode OutputOptions.banner | output.banner} option.
|
|
2712
|
+
*
|
|
2713
|
+
* @group Output Generation Hooks
|
|
2714
|
+
*/
|
|
2715
|
+
[DEFINED_HOOK_NAMES.banner]: AddonHook;
|
|
2716
|
+
/**
|
|
2717
|
+
* A hook equivalent to {@linkcode OutputOptions.footer | output.footer} option.
|
|
2718
|
+
*
|
|
2719
|
+
* @group Output Generation Hooks
|
|
2720
|
+
*/
|
|
2721
|
+
[DEFINED_HOOK_NAMES.footer]: AddonHook;
|
|
2722
|
+
/**
|
|
2723
|
+
* A hook equivalent to {@linkcode OutputOptions.intro | output.intro} option.
|
|
2724
|
+
*
|
|
2725
|
+
* @group Output Generation Hooks
|
|
2726
|
+
*/
|
|
2727
|
+
[DEFINED_HOOK_NAMES.intro]: AddonHook;
|
|
2728
|
+
/**
|
|
2729
|
+
* A hook equivalent to {@linkcode OutputOptions.outro | output.outro} option.
|
|
2730
|
+
*
|
|
2731
|
+
* @group Output Generation Hooks
|
|
2732
|
+
*/
|
|
2733
|
+
[DEFINED_HOOK_NAMES.outro]: AddonHook;
|
|
2734
|
+
}
|
|
2735
|
+
type OutputPluginHooks = DefinedHookNames["augmentChunkHash" | "generateBundle" | "outputOptions" | "renderChunk" | "renderError" | "renderStart" | "writeBundle"];
|
|
2736
|
+
/** @internal */
|
|
2737
|
+
type ParallelPluginHooks = Exclude<keyof FunctionPluginHooks | keyof AddonHooks, FirstPluginHooks | SequentialPluginHooks>;
|
|
2738
|
+
/** @category Plugin APIs */
|
|
2739
|
+
type HookFilterExtension<K extends keyof FunctionPluginHooks> = K extends "transform" ? {
|
|
2740
|
+
filter?: HookFilter | TopLevelFilterExpression[];
|
|
2741
|
+
} : K extends "load" ? {
|
|
2742
|
+
filter?: Pick<HookFilter, "id"> | TopLevelFilterExpression[];
|
|
2743
|
+
} : K extends "resolveId" ? {
|
|
2744
|
+
filter?: {
|
|
2745
|
+
id?: GeneralHookFilter<RegExp>;
|
|
2746
|
+
} | TopLevelFilterExpression[];
|
|
2747
|
+
} : K extends "renderChunk" ? {
|
|
2748
|
+
filter?: Pick<HookFilter, "code"> | TopLevelFilterExpression[];
|
|
2749
|
+
} : {};
|
|
2750
|
+
type PluginHooks = { [K in keyof FunctionPluginHooks]: ObjectHook<K extends AsyncPluginHooks ? MakeAsync<FunctionPluginHooks[K]> : FunctionPluginHooks[K], HookFilterExtension<K> & (K extends ParallelPluginHooks ? {
|
|
2751
|
+
/**
|
|
2752
|
+
* @deprecated
|
|
2753
|
+
* this is only for rollup Plugin type compatibility.
|
|
2754
|
+
* hooks always work as `sequential: true`.
|
|
2755
|
+
*/
|
|
2756
|
+
sequential?: boolean;
|
|
2757
|
+
} : {})> };
|
|
2758
|
+
type AddonHookFunction = (this: PluginContext, chunk: RenderedChunk) => string | Promise<string>;
|
|
2759
|
+
type AddonHook = string | AddonHookFunction;
|
|
2760
|
+
interface OutputPlugin extends Partial<{ [K in keyof PluginHooks as K & OutputPluginHooks]: PluginHooks[K] }>, Partial<{ [K in keyof AddonHooks]: ObjectHook<AddonHook> }> {
|
|
2761
|
+
/** The name of the plugin, for use in error messages and logs. */
|
|
2762
|
+
name: string;
|
|
2763
|
+
/** The version of the plugin, for use in inter-plugin communication scenarios. */
|
|
2764
|
+
version?: string;
|
|
2765
|
+
}
|
|
2766
|
+
/**
|
|
2767
|
+
* The Plugin interface.
|
|
2768
|
+
*
|
|
2769
|
+
* See [Plugin API document](https://rolldown.rs/apis/plugin-api) for details.
|
|
2770
|
+
*
|
|
2771
|
+
* @typeParam A - The type of the {@link Plugin.api | api} property.
|
|
2772
|
+
*
|
|
2773
|
+
* @category Plugin APIs
|
|
2774
|
+
*/
|
|
2775
|
+
interface Plugin<A = any> extends OutputPlugin, Partial<PluginHooks> {
|
|
2776
|
+
/**
|
|
2777
|
+
* Used for inter-plugin communication.
|
|
2778
|
+
*/
|
|
2779
|
+
api?: A;
|
|
2780
|
+
}
|
|
2781
|
+
type RolldownPlugin<A = any> = Plugin<A> | BuiltinPlugin | ParallelPlugin;
|
|
2782
|
+
type RolldownPluginOption<A = any> = MaybePromise<NullValue<RolldownPlugin<A>> | {
|
|
2783
|
+
name: string;
|
|
2784
|
+
} | false | RolldownPluginOption[]>;
|
|
2785
|
+
type RolldownOutputPlugin = OutputPlugin | BuiltinPlugin;
|
|
2786
|
+
type RolldownOutputPluginOption = MaybePromise<NullValue<RolldownOutputPlugin> | {
|
|
2787
|
+
name: string;
|
|
2788
|
+
} | false | RolldownOutputPluginOption[]>;
|
|
2789
|
+
//#endregion
|
|
2790
|
+
//#region src/options/input-options.d.ts
|
|
2791
|
+
/**
|
|
2792
|
+
* @inline
|
|
2793
|
+
*/
|
|
2794
|
+
type InputOption = string | string[] | Record<string, string>;
|
|
2795
|
+
/**
|
|
2796
|
+
* @param id The id of the module being checked.
|
|
2797
|
+
* @param parentId The id of the module importing the id being checked.
|
|
2798
|
+
* @param isResolved Whether the id has been resolved.
|
|
2799
|
+
* @returns Whether the module should be treated as external.
|
|
2800
|
+
*/
|
|
2801
|
+
type ExternalOptionFunction = (id: string, parentId: string | undefined, isResolved: boolean) => NullValue<boolean>;
|
|
2802
|
+
/** @inline */
|
|
2803
|
+
type ExternalOption = StringOrRegExp | StringOrRegExp[] | ExternalOptionFunction;
|
|
2804
|
+
type ModuleTypes = Record<string, "js" | "jsx" | "ts" | "tsx" | "json" | "text" | "base64" | "dataurl" | "binary" | "empty" | "css" | "asset">;
|
|
2805
|
+
interface WatcherOptions {
|
|
2806
|
+
/**
|
|
2807
|
+
* Whether to skip the `bundle.write()` step when a rebuild is triggered.
|
|
2808
|
+
* @default false
|
|
2809
|
+
*/
|
|
2810
|
+
skipWrite?: boolean;
|
|
2811
|
+
/**
|
|
2812
|
+
* Configures how long Rolldown will wait for further changes until it triggers
|
|
2813
|
+
* a rebuild in milliseconds.
|
|
2814
|
+
*
|
|
2815
|
+
* Even if this value is set to 0, there's a small debounce timeout configured
|
|
2816
|
+
* in the file system watcher. Setting this to a value greater than 0 will mean
|
|
2817
|
+
* that Rolldown will only trigger a rebuild if there was no change for the
|
|
2818
|
+
* configured number of milliseconds. If several configurations are watched,
|
|
2819
|
+
* Rolldown will use the largest configured build delay.
|
|
2820
|
+
*
|
|
2821
|
+
* @default 0
|
|
2822
|
+
*/
|
|
2823
|
+
buildDelay?: number;
|
|
2824
|
+
/**
|
|
2825
|
+
* An optional object of options that will be passed to the [notify](https://github.com/rolldown/notify) file watcher.
|
|
2826
|
+
*/
|
|
2827
|
+
notify?: {
|
|
2828
|
+
/**
|
|
2829
|
+
* Interval between each re-scan attempt in milliseconds.
|
|
2830
|
+
*
|
|
2831
|
+
* This option is only used when polling backend is used.
|
|
2832
|
+
*
|
|
2833
|
+
* @default 30_000
|
|
2834
|
+
*/
|
|
2835
|
+
pollInterval?: number;
|
|
2836
|
+
/**
|
|
2837
|
+
* Whether to compare file contents when checking for changes.
|
|
2838
|
+
*
|
|
2839
|
+
* This is especially important for pseudo filesystems like those on Linux
|
|
2840
|
+
* under `/sys` and `/proc` which are not obligated to respect any other
|
|
2841
|
+
* filesystem norms such as modification timestamps, file sizes, etc. By
|
|
2842
|
+
* enabling this feature, performance will be significantly impacted as
|
|
2843
|
+
* all files will need to be read and hashed at each interval.
|
|
2844
|
+
*
|
|
2845
|
+
* This option is only used when polling backend is used.
|
|
2846
|
+
*
|
|
2847
|
+
* @default false
|
|
2848
|
+
*/
|
|
2849
|
+
compareContents?: boolean;
|
|
2850
|
+
};
|
|
2851
|
+
/**
|
|
2852
|
+
* Filter to limit the file-watching to certain files.
|
|
2853
|
+
*
|
|
2854
|
+
* Strings are treated as glob patterns.
|
|
2855
|
+
* Note that this only filters the module graph but does not allow adding
|
|
2856
|
+
* additional watch files.
|
|
2857
|
+
*
|
|
2858
|
+
* @example
|
|
2859
|
+
* ```js
|
|
2860
|
+
* export default defineConfig({
|
|
2861
|
+
* watch: {
|
|
2862
|
+
* include: 'src/**',
|
|
2863
|
+
* },
|
|
2864
|
+
* })
|
|
2865
|
+
* ```
|
|
2866
|
+
* @default []
|
|
2867
|
+
*/
|
|
2868
|
+
include?: StringOrRegExp | StringOrRegExp[];
|
|
2869
|
+
/**
|
|
2870
|
+
* Filter to prevent files from being watched.
|
|
2871
|
+
*
|
|
2872
|
+
* Strings are treated as glob patterns.
|
|
2873
|
+
*
|
|
2874
|
+
* @example
|
|
2875
|
+
* ```js
|
|
2876
|
+
* export default defineConfig({
|
|
2877
|
+
* watch: {
|
|
2878
|
+
* exclude: 'node_modules/**',
|
|
2879
|
+
* },
|
|
2880
|
+
* })
|
|
2881
|
+
* ```
|
|
2882
|
+
* @default []
|
|
2883
|
+
*/
|
|
2884
|
+
exclude?: StringOrRegExp | StringOrRegExp[];
|
|
2885
|
+
/**
|
|
2886
|
+
* An optional function that will be called immediately every time
|
|
2887
|
+
* a module changes that is part of the build.
|
|
2888
|
+
*
|
|
2889
|
+
* This is different from the `watchChange` plugin hook, which is
|
|
2890
|
+
* only called once the running build has finished. This may for
|
|
2891
|
+
* instance be used to prevent additional steps from being performed
|
|
2892
|
+
* if we know another build will be started anyway once the current
|
|
2893
|
+
* build finished. This callback may be called multiple times per
|
|
2894
|
+
* build as it tracks every change.
|
|
2895
|
+
*
|
|
2896
|
+
* @param id The id of the changed module.
|
|
2897
|
+
*/
|
|
2898
|
+
onInvalidate?: (id: string) => void;
|
|
2899
|
+
/**
|
|
2900
|
+
* Whether to clear the screen when a rebuild is triggered.
|
|
2901
|
+
* @default true
|
|
2902
|
+
*/
|
|
2903
|
+
clearScreen?: boolean;
|
|
2904
|
+
}
|
|
2905
|
+
/** @inline */
|
|
2906
|
+
type MakeAbsoluteExternalsRelative = boolean | "ifRelativeSource";
|
|
2907
|
+
type DevModeOptions = boolean | {
|
|
2908
|
+
host?: string;
|
|
2909
|
+
port?: number;
|
|
2910
|
+
implement?: string;
|
|
2911
|
+
lazy?: boolean;
|
|
2912
|
+
};
|
|
2913
|
+
type OptimizationOptions = {
|
|
2914
|
+
/**
|
|
2915
|
+
* Inline imported constant values during bundling instead of preserving variable references.
|
|
2916
|
+
*
|
|
2917
|
+
* When enabled, constant values from imported modules will be inlined at their usage sites,
|
|
2918
|
+
* potentially reducing bundle size and improving runtime performance by eliminating variable lookups.
|
|
2919
|
+
*
|
|
2920
|
+
* **Options:**
|
|
2921
|
+
* - `true`: equivalent to `{ mode: 'all', pass: 1 }`, enabling constant inlining for all eligible constants with a single pass.
|
|
2922
|
+
* - `false`: Disable constant inlining
|
|
2923
|
+
* - `{ mode: 'smart' | 'all', pass?: number }`:
|
|
2924
|
+
* - `mode: 'smart'`: Only inline constants in specific scenarios where it is likely to reduce bundle size and improve performance.
|
|
2925
|
+
* Smart mode inlines constants in these specific scenarios:
|
|
2926
|
+
* 1. `if (test) {} else {}` - condition expressions in if statements
|
|
2927
|
+
* 2. `test ? a : b` - condition expressions in ternary operators
|
|
2928
|
+
* 3. `test1 || test2` - logical OR expressions
|
|
2929
|
+
* 4. `test1 && test2` - logical AND expressions
|
|
2930
|
+
* 5. `test1 ?? test2` - nullish coalescing expressions
|
|
2931
|
+
* - `mode: 'all'`: Inline all imported constants wherever they are used.
|
|
2932
|
+
* - `pass`: Number of passes to perform for inlining constants.
|
|
2933
|
+
*
|
|
2934
|
+
* @example
|
|
2935
|
+
* ```js
|
|
2936
|
+
* // Input files:
|
|
2937
|
+
* // constants.js
|
|
2938
|
+
* export const API_URL = 'https://api.example.com';
|
|
2939
|
+
*
|
|
2940
|
+
* // main.js
|
|
2941
|
+
* import { API_URL } from './constants.js';
|
|
2942
|
+
* console.log(API_URL);
|
|
2943
|
+
*
|
|
2944
|
+
* // With inlineConst: true, the bundled output becomes:
|
|
2945
|
+
* console.log('https://api.example.com');
|
|
2946
|
+
*
|
|
2947
|
+
* // Instead of:
|
|
2948
|
+
* const API_URL = 'https://api.example.com';
|
|
2949
|
+
* console.log(API_URL);
|
|
2950
|
+
* ```
|
|
2951
|
+
*
|
|
2952
|
+
* @default false
|
|
2953
|
+
*/
|
|
2954
|
+
inlineConst?: boolean | {
|
|
2955
|
+
mode?: "all" | "smart";
|
|
2956
|
+
pass?: number;
|
|
2957
|
+
};
|
|
2958
|
+
/**
|
|
2959
|
+
* Use PIFE pattern for module wrappers.
|
|
2960
|
+
*
|
|
2961
|
+
* Enabling this option improves the start up performance of the generated bundle with the cost of a slight increase in bundle size.
|
|
2962
|
+
*
|
|
2963
|
+
* {@include ./docs/optimization-pife-for-module-wrappers.md}
|
|
2964
|
+
*
|
|
2965
|
+
* @default true
|
|
2966
|
+
*/
|
|
2967
|
+
pifeForModuleWrappers?: boolean;
|
|
2968
|
+
};
|
|
2969
|
+
/** @inline */
|
|
2970
|
+
type AttachDebugOptions = "none" | "simple" | "full";
|
|
2971
|
+
/** @inline */
|
|
2972
|
+
type ChunkModulesOrder = "exec-order" | "module-id";
|
|
2973
|
+
/** @inline */
|
|
2974
|
+
type OnLogFunction = (level: LogLevel, log: RolldownLog, defaultHandler: LogOrStringHandler) => void;
|
|
2975
|
+
/** @inline */
|
|
2976
|
+
type OnwarnFunction = (warning: RolldownLog, defaultHandler: (warning: RolldownLogWithString | (() => RolldownLogWithString)) => void) => void;
|
|
2977
|
+
interface InputOptions {
|
|
2978
|
+
/**
|
|
2979
|
+
* Defines entries and location(s) of entry modules for the bundle. Relative paths are resolved based on the {@linkcode cwd} option.
|
|
2980
|
+
* {@include ./docs/input.md}
|
|
2981
|
+
*/
|
|
2982
|
+
input?: InputOption;
|
|
2983
|
+
/**
|
|
2984
|
+
* The list of plugins to use.
|
|
2985
|
+
*
|
|
2986
|
+
* Falsy plugins will be ignored, which can be used to easily activate or deactivate plugins. Nested plugins will be flattened. Async plugins will be awaited and resolved.
|
|
2987
|
+
*
|
|
2988
|
+
* See [Plugin API document](https://rolldown.rs/apis/plugin-api) for more details about creating plugins.
|
|
2989
|
+
*/
|
|
2990
|
+
plugins?: RolldownPluginOption;
|
|
2991
|
+
/**
|
|
2992
|
+
* Specifies which modules should be treated as external and not bundled. External modules will be left as import statements in the output.
|
|
2993
|
+
* {@include ./docs/external.md}
|
|
2994
|
+
*/
|
|
2995
|
+
external?: ExternalOption;
|
|
2996
|
+
/**
|
|
2997
|
+
* Options for built-in module resolution feature.
|
|
2998
|
+
*/
|
|
2999
|
+
resolve?: {
|
|
3000
|
+
/**
|
|
3001
|
+
* Substitute one package for another.
|
|
3002
|
+
*
|
|
3003
|
+
* One use case for this feature is replacing a node-only package with a browser-friendly package in third-party code that you don't control.
|
|
3004
|
+
*
|
|
3005
|
+
* @example
|
|
3006
|
+
* ```js
|
|
3007
|
+
* resolve: {
|
|
3008
|
+
* alias: {
|
|
3009
|
+
* '@': '/src',
|
|
3010
|
+
* 'utils': './src/utils',
|
|
3011
|
+
* }
|
|
3012
|
+
* }
|
|
3013
|
+
* ```
|
|
3014
|
+
* > [!WARNING]
|
|
3015
|
+
* > `resolve.alias` will not call `resolveId` hooks of other plugin.
|
|
3016
|
+
* > If you want to call `resolveId` hooks of other plugin, use `viteAliasPlugin` from `rolldown/experimental` instead.
|
|
3017
|
+
* > You could find more discussion in [this issue](https://github.com/rolldown/rolldown/issues/3615)
|
|
3018
|
+
*/
|
|
3019
|
+
alias?: Record<string, string[] | string | false>;
|
|
3020
|
+
/**
|
|
3021
|
+
* Fields in package.json to check for aliased paths.
|
|
3022
|
+
*
|
|
3023
|
+
* This option is expected to be used for `browser` field support.
|
|
3024
|
+
*
|
|
3025
|
+
* @default
|
|
3026
|
+
* - `[['browser']]` for `browser` platform
|
|
3027
|
+
* - `[]` for other platforms
|
|
3028
|
+
*/
|
|
3029
|
+
aliasFields?: string[][];
|
|
3030
|
+
/**
|
|
3031
|
+
* Condition names to use when resolving exports in package.json.
|
|
3032
|
+
*
|
|
3033
|
+
* @default
|
|
3034
|
+
* Defaults based on platform and import kind:
|
|
3035
|
+
* - `browser` platform
|
|
3036
|
+
* - `["import", "browser", "default"]` for import statements
|
|
3037
|
+
* - `["require", "browser", "default"]` for require() calls
|
|
3038
|
+
* - `node` platform
|
|
3039
|
+
* - `["import", "node", "default"]` for import statements
|
|
3040
|
+
* - `["require", "node", "default"]` for require() calls
|
|
3041
|
+
* - `neutral` platform
|
|
3042
|
+
* - `["import", "default"]` for import statements
|
|
3043
|
+
* - `["require", "default"]` for require() calls
|
|
3044
|
+
*/
|
|
3045
|
+
conditionNames?: string[];
|
|
3046
|
+
/**
|
|
3047
|
+
* Map of extensions to alternative extensions.
|
|
3048
|
+
*
|
|
3049
|
+
* With writing `import './foo.js'` in a file, you want to resolve it to `foo.ts` instead of `foo.js`.
|
|
3050
|
+
* You can achieve this by setting: `extensionAlias: { '.js': ['.ts', '.js'] }`.
|
|
3051
|
+
*/
|
|
3052
|
+
extensionAlias?: Record<string, string[]>;
|
|
3053
|
+
/**
|
|
3054
|
+
* Fields in package.json to check for exports.
|
|
3055
|
+
*
|
|
3056
|
+
* @default `[['exports']]`
|
|
3057
|
+
*/
|
|
3058
|
+
exportsFields?: string[][];
|
|
3059
|
+
/**
|
|
3060
|
+
* Extensions to try when resolving files. These are tried in order from first to last.
|
|
3061
|
+
*
|
|
3062
|
+
* @default `['.tsx', '.ts', '.jsx', '.js', '.json']`
|
|
3063
|
+
*/
|
|
3064
|
+
extensions?: string[];
|
|
3065
|
+
/**
|
|
3066
|
+
* Fields in package.json to check for entry points.
|
|
3067
|
+
*
|
|
3068
|
+
* @default
|
|
3069
|
+
* Defaults based on platform:
|
|
3070
|
+
* - `node` platform: `['main', 'module']`
|
|
3071
|
+
* - `browser` platform: `['browser', 'module', 'main']`
|
|
3072
|
+
* - `neutral` platform: `[]`
|
|
3073
|
+
*/
|
|
3074
|
+
mainFields?: string[];
|
|
3075
|
+
/**
|
|
3076
|
+
* Filenames to try when resolving directories.
|
|
3077
|
+
* @default ['index']
|
|
3078
|
+
*/
|
|
3079
|
+
mainFiles?: string[];
|
|
3080
|
+
/**
|
|
3081
|
+
* Directories to search for modules.
|
|
3082
|
+
* @default ['node_modules']
|
|
3083
|
+
*/
|
|
3084
|
+
modules?: string[];
|
|
3085
|
+
/**
|
|
3086
|
+
* Whether to follow symlinks when resolving modules.
|
|
3087
|
+
* @default true
|
|
3088
|
+
*/
|
|
3089
|
+
symlinks?: boolean;
|
|
3090
|
+
/**
|
|
3091
|
+
* @deprecated Use the top-level {@linkcode tsconfig} option instead.
|
|
3092
|
+
*/
|
|
3093
|
+
tsconfigFilename?: string;
|
|
3094
|
+
};
|
|
3095
|
+
/**
|
|
3096
|
+
* The working directory to use when resolving relative paths in the configuration.
|
|
3097
|
+
* @default process.cwd()
|
|
3098
|
+
*/
|
|
3099
|
+
cwd?: string;
|
|
3100
|
+
/**
|
|
3101
|
+
* Expected platform where the code run.
|
|
3102
|
+
*
|
|
3103
|
+
* When the platform is set to neutral:
|
|
3104
|
+
* - When bundling is enabled the default output format is set to esm, which uses the export syntax introduced with ECMAScript 2015 (i.e. ES6). You can change the output format if this default is not appropriate.
|
|
3105
|
+
* - The main fields setting is empty by default. If you want to use npm-style packages, you will likely have to configure this to be something else such as main for the standard main field used by node.
|
|
3106
|
+
* - The conditions setting does not automatically include any platform-specific values.
|
|
3107
|
+
*
|
|
3108
|
+
* @default
|
|
3109
|
+
* - `'node'` if the format is `'cjs'`
|
|
3110
|
+
* - `'browser'` for other formats
|
|
3111
|
+
* {@include ./docs/platform.md}
|
|
3112
|
+
*/
|
|
3113
|
+
platform?: "node" | "browser" | "neutral";
|
|
3114
|
+
/**
|
|
3115
|
+
* When `true`, creates shim variables for missing exports instead of throwing an error.
|
|
3116
|
+
* @default false
|
|
3117
|
+
* {@include ./docs/shim-missing-exports.md}
|
|
3118
|
+
*/
|
|
3119
|
+
shimMissingExports?: boolean;
|
|
3120
|
+
/**
|
|
3121
|
+
* Controls tree-shaking (dead code elimination).
|
|
3122
|
+
*
|
|
3123
|
+
* When `false`, tree-shaking will be disabled.
|
|
3124
|
+
* When `true`, it is equivalent to setting each options to the default value.
|
|
3125
|
+
*
|
|
3126
|
+
* @default true
|
|
3127
|
+
*/
|
|
3128
|
+
treeshake?: boolean | TreeshakingOptions;
|
|
3129
|
+
/**
|
|
3130
|
+
* Controls the verbosity of console logging during the build.
|
|
3131
|
+
*
|
|
3132
|
+
* {@include ./docs/log-level.md}
|
|
3133
|
+
*
|
|
3134
|
+
* @default 'info'
|
|
3135
|
+
*/
|
|
3136
|
+
logLevel?: LogLevelOption;
|
|
3137
|
+
/**
|
|
3138
|
+
* A function that intercepts log messages. If not supplied, logs are printed to the console.
|
|
3139
|
+
*
|
|
3140
|
+
* {@include ./docs/on-log.md}
|
|
3141
|
+
*
|
|
3142
|
+
* @example
|
|
3143
|
+
* ```js
|
|
3144
|
+
* export default defineConfig({
|
|
3145
|
+
* onLog(level, log, defaultHandler) {
|
|
3146
|
+
* if (log.code === 'CIRCULAR_DEPENDENCY') {
|
|
3147
|
+
* return; // Ignore circular dependency warnings
|
|
3148
|
+
* }
|
|
3149
|
+
* if (level === 'warn') {
|
|
3150
|
+
* defaultHandler('error', log); // turn other warnings into errors
|
|
3151
|
+
* } else {
|
|
3152
|
+
* defaultHandler(level, log); // otherwise, just print the log
|
|
3153
|
+
* }
|
|
3154
|
+
* }
|
|
3155
|
+
* })
|
|
3156
|
+
* ```
|
|
3157
|
+
*/
|
|
3158
|
+
onLog?: OnLogFunction;
|
|
3159
|
+
/**
|
|
3160
|
+
* A function that will intercept warning messages.
|
|
3161
|
+
*
|
|
3162
|
+
* {@include ./docs/on-warn.md}
|
|
3163
|
+
*
|
|
3164
|
+
* @deprecated
|
|
3165
|
+
* This is a legacy API. Consider using {@linkcode onLog} instead for better control over all log types.
|
|
3166
|
+
*
|
|
3167
|
+
* {@include ./docs/on-warn-deprecation.md}
|
|
3168
|
+
*/
|
|
3169
|
+
onwarn?: OnwarnFunction;
|
|
3170
|
+
/**
|
|
3171
|
+
* Maps file patterns to module types, controlling how files are processed.
|
|
3172
|
+
*
|
|
3173
|
+
* This is conceptually similar to esbuild's loader option, allowing you to specify how different file extensions should be handled.
|
|
3174
|
+
*/
|
|
3175
|
+
moduleTypes?: ModuleTypes;
|
|
3176
|
+
/**
|
|
3177
|
+
* Experimental features that may change in future releases and can introduce behavior change without a major version bump.
|
|
3178
|
+
* @experimental
|
|
3179
|
+
*/
|
|
3180
|
+
experimental?: {
|
|
3181
|
+
/**
|
|
3182
|
+
* Enable Vite compatible mode.
|
|
3183
|
+
* @default false
|
|
3184
|
+
* @hidden This option is only meant to be used by Vite. It is not recommended to use this option directly.
|
|
3185
|
+
*/
|
|
3186
|
+
viteMode?: boolean;
|
|
3187
|
+
/**
|
|
3188
|
+
* When enabled, `new URL()` calls will be transformed to a stable asset URL which includes the updated name and content hash.
|
|
3189
|
+
* It is necessary to pass `import.meta.url` as the second argument to the
|
|
3190
|
+
* `new URL` constructor, otherwise no transform will be applied.
|
|
3191
|
+
* :::warning
|
|
3192
|
+
* JavaScript and TypeScript files referenced via `new URL('./file.js', import.meta.url)` or `new URL('./file.ts', import.meta.url)` will **not** be transformed or bundled. The file will be copied as-is, meaning TypeScript files remain untransformed and dependencies are not resolved.
|
|
3193
|
+
*
|
|
3194
|
+
* The expected behavior for JS/TS files is still being discussed and may
|
|
3195
|
+
* change in future releases. See [#7258](https://github.com/rolldown/rolldown/issues/7258) for more context.
|
|
3196
|
+
* :::
|
|
3197
|
+
* @example
|
|
3198
|
+
* ```js
|
|
3199
|
+
* // main.js
|
|
3200
|
+
* const url = new URL('./styles.css', import.meta.url);
|
|
3201
|
+
* console.log(url);
|
|
3202
|
+
*
|
|
3203
|
+
* // Example output after bundling WITHOUT the option (default)
|
|
3204
|
+
* const url = new URL('./styles.css', import.meta.url);
|
|
3205
|
+
* console.log(url);
|
|
3206
|
+
*
|
|
3207
|
+
* // Example output after bundling WITH `experimental.resolveNewUrlToAsset` set to `true`
|
|
3208
|
+
* const url = new URL('assets/styles-CjdrdY7X.css', import.meta.url);
|
|
3209
|
+
* console.log(url);
|
|
3210
|
+
* ```
|
|
3211
|
+
* @default false
|
|
3212
|
+
*/
|
|
3213
|
+
resolveNewUrlToAsset?: boolean;
|
|
3214
|
+
/**
|
|
3215
|
+
* Dev mode related options.
|
|
3216
|
+
* @hidden not ready for public usage yet
|
|
3217
|
+
*/
|
|
3218
|
+
devMode?: DevModeOptions;
|
|
3219
|
+
/**
|
|
3220
|
+
* Control which order should be used when rendering modules in a chunk.
|
|
3221
|
+
*
|
|
3222
|
+
* Available options:
|
|
3223
|
+
* - `exec-order`: Almost equivalent to the topological order of the module graph, but specially handling when module graph has cycle.
|
|
3224
|
+
* - `module-id`: This is more friendly for gzip compression, especially for some javascript static asset lib (e.g. icon library)
|
|
3225
|
+
*
|
|
3226
|
+
* > [!NOTE]
|
|
3227
|
+
* > Try to sort the modules by their module id if possible (Since rolldown scope hoist all modules in the chunk, we only try to sort those modules by module id if we could ensure runtime behavior is correct after sorting).
|
|
3228
|
+
*
|
|
3229
|
+
* @default 'exec-order'
|
|
3230
|
+
*/
|
|
3231
|
+
chunkModulesOrder?: ChunkModulesOrder;
|
|
3232
|
+
/**
|
|
3233
|
+
* Attach debug information to the output bundle.
|
|
3234
|
+
*
|
|
3235
|
+
* Available modes:
|
|
3236
|
+
* - `none`: No debug information is attached.
|
|
3237
|
+
* - `simple`: Attach comments indicating which files the bundled code comes from. These comments could be removed by the minifier.
|
|
3238
|
+
* - `full`: Attach detailed debug information to the output bundle. These comments are using legal comment syntax, so they won't be removed by the minifier.
|
|
3239
|
+
*
|
|
3240
|
+
* @default 'simple'
|
|
3241
|
+
*/
|
|
3242
|
+
attachDebugInfo?: AttachDebugOptions;
|
|
3243
|
+
/**
|
|
3244
|
+
* Enables automatic generation of a chunk import map asset during build.
|
|
3245
|
+
*
|
|
3246
|
+
* This map only includes chunks with hashed filenames, where keys are derived from the facade module
|
|
3247
|
+
* name or primary chunk name. It produces stable and unique hash-based filenames, effectively preventing
|
|
3248
|
+
* cascading cache invalidation caused by content hashes and maximizing browser cache reuse.
|
|
3249
|
+
*
|
|
3250
|
+
* The output defaults to `importmap.json` unless overridden via `fileName`. A base URL prefix
|
|
3251
|
+
* (default `"/"`) can be applied to all paths. The resulting JSON is a valid import map and can be
|
|
3252
|
+
* directly injected into HTML via `<script type="importmap">`.
|
|
3253
|
+
*
|
|
3254
|
+
* @example
|
|
3255
|
+
* ```js
|
|
3256
|
+
* {
|
|
3257
|
+
* experimental: {
|
|
3258
|
+
* chunkImportMap: {
|
|
3259
|
+
* baseUrl: '/',
|
|
3260
|
+
* fileName: 'importmap.json'
|
|
3261
|
+
* }
|
|
3262
|
+
* },
|
|
3263
|
+
* plugins: [
|
|
3264
|
+
* {
|
|
3265
|
+
* name: 'inject-import-map',
|
|
3266
|
+
* generateBundle(_, bundle) {
|
|
3267
|
+
* const chunkImportMap = bundle['importmap.json'];
|
|
3268
|
+
* if (chunkImportMap?.type === 'asset') {
|
|
3269
|
+
* const htmlPath = path.resolve('index.html');
|
|
3270
|
+
* let html = fs.readFileSync(htmlPath, 'utf-8');
|
|
3271
|
+
*
|
|
3272
|
+
* html = html.replace(
|
|
3273
|
+
* /<script\s+type="importmap"[^>]*>[\s\S]*?<\/script>/i,
|
|
3274
|
+
* `<script type="importmap">${chunkImportMap.source}<\/script>`
|
|
3275
|
+
* );
|
|
3276
|
+
*
|
|
3277
|
+
* fs.writeFileSync(htmlPath, html);
|
|
3278
|
+
* delete bundle['importmap.json'];
|
|
3279
|
+
* }
|
|
3280
|
+
* }
|
|
3281
|
+
* }
|
|
3282
|
+
* ]
|
|
3283
|
+
* }
|
|
3284
|
+
* ```
|
|
3285
|
+
*
|
|
3286
|
+
* > [!TIP]
|
|
3287
|
+
* > If you want to learn more, you can check out the example here: [examples/chunk-import-map](https://github.com/rolldown/rolldown/tree/main/examples/chunk-import-map)
|
|
3288
|
+
*
|
|
3289
|
+
* @default false
|
|
3290
|
+
*/
|
|
3291
|
+
chunkImportMap?: boolean | {
|
|
3292
|
+
baseUrl?: string;
|
|
3293
|
+
fileName?: string;
|
|
3294
|
+
};
|
|
3295
|
+
/**
|
|
3296
|
+
* Enable on-demand wrapping of modules.
|
|
3297
|
+
* @default false
|
|
3298
|
+
* @hidden not ready for public usage yet
|
|
3299
|
+
*/
|
|
3300
|
+
onDemandWrapping?: boolean;
|
|
3301
|
+
/**
|
|
3302
|
+
* Enable incremental build support. Required to be used with `watch` mode.
|
|
3303
|
+
* @default false
|
|
3304
|
+
*/
|
|
3305
|
+
incrementalBuild?: boolean;
|
|
3306
|
+
/**
|
|
3307
|
+
* Enable high-resolution source maps for transform operations.
|
|
3308
|
+
* @default false
|
|
3309
|
+
*/
|
|
3310
|
+
transformHiresSourcemap?: boolean | "boundary";
|
|
3311
|
+
/**
|
|
3312
|
+
* Use native Rust implementation of MagicString for source map generation.
|
|
3313
|
+
*
|
|
3314
|
+
* [MagicString](https://github.com/rich-harris/magic-string) is a JavaScript library commonly used by bundlers
|
|
3315
|
+
* for string manipulation and source map generation. When enabled, rolldown will use a native Rust
|
|
3316
|
+
* implementation of MagicString instead of the JavaScript version, providing significantly better performance
|
|
3317
|
+
* during source map generation and code transformation.
|
|
3318
|
+
*
|
|
3319
|
+
* **Benefits**
|
|
3320
|
+
*
|
|
3321
|
+
* - **Improved Performance**: The native Rust implementation is typically faster than the JavaScript version,
|
|
3322
|
+
* especially for large codebases with extensive source maps.
|
|
3323
|
+
* - **Background Processing**: Source map generation is performed asynchronously in a background thread,
|
|
3324
|
+
* allowing the main bundling process to continue without blocking. This parallel processing can significantly
|
|
3325
|
+
* reduce overall build times when working with JavaScript transform hooks.
|
|
3326
|
+
* - **Better Integration**: Seamless integration with rolldown's native Rust architecture.
|
|
3327
|
+
*
|
|
3328
|
+
* @example
|
|
3329
|
+
* ```js
|
|
3330
|
+
* export default {
|
|
3331
|
+
* experimental: {
|
|
3332
|
+
* nativeMagicString: true
|
|
3333
|
+
* },
|
|
3334
|
+
* output: {
|
|
3335
|
+
* sourcemap: true
|
|
3336
|
+
* }
|
|
3337
|
+
* }
|
|
3338
|
+
* ```
|
|
3339
|
+
*
|
|
3340
|
+
* > [!NOTE]
|
|
3341
|
+
* > This is an experimental feature. While it aims to provide identical behavior to the JavaScript
|
|
3342
|
+
* > implementation, there may be edge cases. Please report any discrepancies you encounter.
|
|
3343
|
+
* > For a complete working example, see [examples/native-magic-string](https://github.com/rolldown/rolldown/tree/main/examples/native-magic-string)
|
|
3344
|
+
* @default false
|
|
3345
|
+
*/
|
|
3346
|
+
nativeMagicString?: boolean;
|
|
3347
|
+
/**
|
|
3348
|
+
* Control whether to optimize chunks by allowing entry chunks to have different exports than the underlying entry module.
|
|
3349
|
+
* This optimization can reduce the number of generated chunks.
|
|
3350
|
+
*
|
|
3351
|
+
* When enabled, rolldown will try to insert common modules directly into existing chunks rather than creating
|
|
3352
|
+
* separate chunks for them, which can result in fewer output files and better performance.
|
|
3353
|
+
*
|
|
3354
|
+
* This optimization is automatically disabled when any module uses top-level await (TLA) or contains TLA dependencies,
|
|
3355
|
+
* as it could affect execution order guarantees.
|
|
3356
|
+
*
|
|
3357
|
+
* @default true
|
|
3358
|
+
*/
|
|
3359
|
+
chunkOptimization?: boolean;
|
|
3360
|
+
};
|
|
3361
|
+
/**
|
|
3362
|
+
* Configure how the code is transformed. This process happens after the `transform` hook.
|
|
3363
|
+
*
|
|
3364
|
+
* @example
|
|
3365
|
+
* **Enable legacy decorators**
|
|
3366
|
+
* ```js
|
|
3367
|
+
* export default defineConfig({
|
|
3368
|
+
* transform: {
|
|
3369
|
+
* decorator: {
|
|
3370
|
+
* legacy: true,
|
|
3371
|
+
* },
|
|
3372
|
+
* },
|
|
3373
|
+
* })
|
|
3374
|
+
* ```
|
|
3375
|
+
* Note that if you have correct `tsconfig.json` file, Rolldown will automatically detect and enable legacy decorators support.
|
|
3376
|
+
*
|
|
3377
|
+
* {@include ./docs/transform.md}
|
|
3378
|
+
*/
|
|
3379
|
+
transform?: TransformOptions;
|
|
3380
|
+
/**
|
|
3381
|
+
* Watch mode related options.
|
|
3382
|
+
*
|
|
3383
|
+
* These options only take effect when running with the `--watch` flag, or using `rolldown.watch()` API.
|
|
3384
|
+
*
|
|
3385
|
+
* @experimental
|
|
3386
|
+
*/
|
|
3387
|
+
watch?: WatcherOptions | false;
|
|
3388
|
+
/**
|
|
3389
|
+
* Controls which warnings are emitted during the build process. Each option can be set to `true` (emit warning) or `false` (suppress warning).
|
|
3390
|
+
*/
|
|
3391
|
+
checks?: ChecksOptions;
|
|
3392
|
+
/**
|
|
3393
|
+
* Determines if absolute external paths should be converted to relative paths in the output.
|
|
3394
|
+
*
|
|
3395
|
+
* This does not only apply to paths that are absolute in the source but also to paths that are resolved to an absolute path by either a plugin or Rolldown core.
|
|
3396
|
+
*
|
|
3397
|
+
* {@include ./docs/make-absolute-externals-relative.md}
|
|
3398
|
+
*/
|
|
3399
|
+
makeAbsoluteExternalsRelative?: MakeAbsoluteExternalsRelative;
|
|
3400
|
+
/**
|
|
3401
|
+
* Devtools integration options.
|
|
3402
|
+
* @experimental
|
|
3403
|
+
*/
|
|
3404
|
+
devtools?: {
|
|
3405
|
+
sessionId?: string;
|
|
3406
|
+
};
|
|
3407
|
+
/**
|
|
3408
|
+
* Controls how entry chunk exports are preserved.
|
|
3409
|
+
*
|
|
3410
|
+
* This determines whether Rolldown needs to create facade chunks (additional wrapper chunks) to maintain the exact export signatures of entry modules, or whether it can combine entry modules with other chunks for optimization.
|
|
3411
|
+
*
|
|
3412
|
+
* @default `'exports-only'`
|
|
3413
|
+
* {@include ./docs/preserve-entry-signatures.md}
|
|
3414
|
+
*/
|
|
3415
|
+
preserveEntrySignatures?: false | "strict" | "allow-extension" | "exports-only";
|
|
3416
|
+
/**
|
|
3417
|
+
* Configure optimization features for the bundler.
|
|
3418
|
+
*/
|
|
3419
|
+
optimization?: OptimizationOptions;
|
|
3420
|
+
/**
|
|
3421
|
+
* The value of `this` at the top level of each module. **Normally, you don't need to set this option.**
|
|
3422
|
+
* @default undefined
|
|
3423
|
+
* @example
|
|
3424
|
+
* **Set custom context**
|
|
3425
|
+
* ```js
|
|
3426
|
+
* export default {
|
|
3427
|
+
* context: 'globalThis',
|
|
3428
|
+
* output: {
|
|
3429
|
+
* format: 'iife',
|
|
3430
|
+
* },
|
|
3431
|
+
* };
|
|
3432
|
+
* ```
|
|
3433
|
+
* {@include ./docs/context.md}
|
|
3434
|
+
*/
|
|
3435
|
+
context?: string;
|
|
3436
|
+
/**
|
|
3437
|
+
* Configures TypeScript configuration file resolution and usage.
|
|
3438
|
+
* {@include ./docs/tsconfig.md}
|
|
3439
|
+
* @default true
|
|
3440
|
+
*/
|
|
3441
|
+
tsconfig?: boolean | string;
|
|
3442
|
+
}
|
|
3443
|
+
//#endregion
|
|
3444
|
+
//#region src/types/rolldown-options.d.ts
|
|
3445
|
+
interface RolldownOptions extends InputOptions {
|
|
3446
|
+
output?: OutputOptions | OutputOptions[];
|
|
3447
|
+
}
|
|
3448
|
+
//#endregion
|
|
3449
|
+
//#region src/utils/define-config.d.ts
|
|
3450
|
+
/**
|
|
3451
|
+
* Type for `default export` of `rolldown.config.js` file.
|
|
3452
|
+
* @category Config
|
|
3453
|
+
*/
|
|
3454
|
+
type ConfigExport = RolldownOptions | RolldownOptions[] | RolldownOptionsFunction;
|
|
3455
|
+
/** @category Config */
|
|
3456
|
+
type RolldownOptionsFunction = (commandLineArguments: Record<string, any>) => MaybePromise<RolldownOptions | RolldownOptions[]>;
|
|
3457
|
+
/** @category Config */
|
|
3458
|
+
declare function defineConfig(config: RolldownOptions): RolldownOptions;
|
|
3459
|
+
declare function defineConfig(config: RolldownOptions[]): RolldownOptions[];
|
|
3460
|
+
declare function defineConfig(config: RolldownOptionsFunction): RolldownOptionsFunction;
|
|
3461
|
+
declare function defineConfig(config: ConfigExport): ConfigExport;
|
|
3462
|
+
//#endregion
|
|
3463
|
+
export { BufferEncoding as $, TransformResult as A, MinifyOptions as At, EmittedChunk as B, RenderedModule as Bt, Plugin as C, ChunkingContext as Ct, RolldownPlugin as D, GeneratedCodeOptions as Dt, ResolvedId as E, CodeSplittingOptions as Et, SourceMapInput as F, PartialNull as Ft, PluginContextResolveOptions as G, SourcemapIgnoreListOption as Gt, EmittedPrebuiltChunk as H, SourceMap as Ht, OutputBundle as I, StringOrRegExp as It, MinimalPluginContext as J, DefineParallelPluginResult as K, TreeshakingOptions as L, OutputAsset as Lt, BuiltinPlugin as M, OutputOptions as Mt, VERSION as N, PreRenderedAsset as Nt, RolldownPluginOption as O, GeneratedCodePreset as Ot, ExistingRawSourceMap as P, MaybePromise as Pt, ModuleTypeFilter as Q, TransformPluginContext as R, OutputChunk as Rt, PartialResolvedId as S, ChunkFileNamesFunction as St, ResolveIdResult as T, CodeSplittingNameFunction as Tt, GetModuleInfo as U, freeExternalMemory as Ut, EmittedFile as V, RolldownOutput as Vt, PluginContext as W, ModuleInfo as Wt, GeneralHookFilter as X, PluginContextMeta as Y, HookFilter as Z, LoadResult as _, BuildOptions as _t, ExternalOption as a, NormalizedInputOptions as at, ObjectHook as b, AdvancedChunksGroup as bt, InputOptions as c, LoggingFunction as ct, WatcherOptions as d, RolldownWatcher as dt, RolldownDirectoryEntry as et, AsyncPluginHooks as f, RolldownWatcherEvent as ft, ImportKind as g, RolldownBuild as gt, HookFilterExtension as h, rolldown as ht, RolldownOptions as i, NormalizedOutputOptions as it, withFilter as j, ModuleFormat as jt, SourceDescription as k, GlobalsFunction as kt, ModuleTypes as l, WarningHandlerWithDefault as lt, FunctionPluginHooks as m, WatchOptions as mt, RolldownOptionsFunction as n, RolldownFsModule as nt, ExternalOptionFunction as o, TransformOptions as ot, CustomPluginOptions as p, RolldownWatcherWatcherEventMap as pt, defineParallelPlugin as q, defineConfig as r, InternalModuleFormat as rt, InputOption as s, ChecksOptions as st, ConfigExport as t, RolldownFileStats as tt, OptimizationOptions as u, watch as ut, ModuleOptions as v, build as vt, ResolveIdExtraOptions as w, CodeSplittingGroup as wt, ParallelPluginHooks as x, AdvancedChunksOptions as xt, ModuleType as y, AddonFunction as yt, EmittedAsset as z, RenderedChunk as zt };
|