@ohos-ports/rolldown 1.2.6-beta.0

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