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