@rolldown/browser 1.0.0-beta.9-commit.0ec9e7d → 1.0.0-rc.2

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