@rollipop/rolldown 0.0.0-beta.0 → 0.0.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 (46) hide show
  1. package/.editorconfig +10 -0
  2. package/.gitattributes +4 -0
  3. package/README.md +1 -11
  4. package/package.json +2 -126
  5. package/LICENSE +0 -25
  6. package/bin/cli.mjs +0 -3
  7. package/dist/cli-setup.d.mts +0 -1
  8. package/dist/cli-setup.mjs +0 -17
  9. package/dist/cli.d.mts +0 -1
  10. package/dist/cli.mjs +0 -1581
  11. package/dist/config.d.mts +0 -10
  12. package/dist/config.mjs +0 -14
  13. package/dist/experimental-index.d.mts +0 -239
  14. package/dist/experimental-index.mjs +0 -299
  15. package/dist/experimental-runtime-types.d.ts +0 -92
  16. package/dist/filter-index.d.mts +0 -4
  17. package/dist/filter-index.mjs +0 -369
  18. package/dist/get-log-filter.d.mts +0 -7
  19. package/dist/get-log-filter.mjs +0 -48
  20. package/dist/index.d.mts +0 -4
  21. package/dist/index.mjs +0 -38
  22. package/dist/parallel-plugin-worker.d.mts +0 -1
  23. package/dist/parallel-plugin-worker.mjs +0 -32
  24. package/dist/parallel-plugin.d.mts +0 -14
  25. package/dist/parallel-plugin.mjs +0 -7
  26. package/dist/parse-ast-index.d.mts +0 -8
  27. package/dist/parse-ast-index.mjs +0 -4
  28. package/dist/plugins-index.d.mts +0 -31
  29. package/dist/plugins-index.mjs +0 -40
  30. package/dist/shared/binding-DmMMxMk0.mjs +0 -584
  31. package/dist/shared/binding-kAegJ1Bj.d.mts +0 -1775
  32. package/dist/shared/bindingify-input-options-D0BAGfk2.mjs +0 -1622
  33. package/dist/shared/constructors-F44lhsH3.d.mts +0 -30
  34. package/dist/shared/constructors-Rl_oLd2F.mjs +0 -67
  35. package/dist/shared/define-config-BF4P-Pum.mjs +0 -7
  36. package/dist/shared/define-config-DJ1-iIdx.d.mts +0 -2562
  37. package/dist/shared/load-config-BEpugZky.mjs +0 -114
  38. package/dist/shared/logging-DsnCZi19.d.mts +0 -42
  39. package/dist/shared/logs-cyjC0SDv.mjs +0 -183
  40. package/dist/shared/misc-DpjTMcQQ.mjs +0 -22
  41. package/dist/shared/normalize-string-or-regex-DbTZ9prS.mjs +0 -670
  42. package/dist/shared/parse-ast-index-BuuhACPk.mjs +0 -99
  43. package/dist/shared/prompt-5sWCM0jm.mjs +0 -847
  44. package/dist/shared/rolldown-build-viDZfkdI.mjs +0 -2292
  45. package/dist/shared/rolldown-il0-nWH9.mjs +0 -11
  46. package/dist/shared/watch-BSdMzY6q.mjs +0 -352
@@ -1,2562 +0,0 @@
1
- import { a as RollupLog, i as RollupError, n as LogLevelOption, o as RollupLogWithString, r as LogOrStringHandler, t as LogLevel } from "./logging-DsnCZi19.mjs";
2
- import { A as BindingWatcherBundler, B as ParserOptions, F as JsxOptions, I as MinifyOptions$1, M as ExternalMemoryStatus, V as PreRenderedChunk, W as TransformOptions$1, a as BindingHookResolveIdExtraArgs, d as BindingTransformHookExtraArgs, j as BindingWatcherEvent, l as BindingRenderedChunk, s as BindingMagicString, t as BindingBuiltinPluginName } from "./binding-kAegJ1Bj.mjs";
3
- import { TopLevelFilterExpression } from "@rollipop/rolldown-pluginutils";
4
- import { Program } from "@oxc-project/types";
5
-
6
- //#region src/types/misc.d.ts
7
- /** @inline */
8
- type SourcemapPathTransformOption = (relativeSourcePath: string, sourcemapPath: string) => string;
9
- /** @inline */
10
- type SourcemapIgnoreListOption = (relativeSourcePath: string, sourcemapPath: string) => boolean;
11
- //#endregion
12
- //#region src/types/module-info.d.ts
13
- /** @category Plugin APIs */
14
- interface ModuleInfo extends ModuleOptions {
15
- /**
16
- * Unsupported at rolldown
17
- */
18
- ast: any;
19
- code: string | null;
20
- id: string;
21
- importers: string[];
22
- dynamicImporters: string[];
23
- importedIds: string[];
24
- dynamicallyImportedIds: string[];
25
- exports: string[];
26
- isEntry: boolean;
27
- }
28
- //#endregion
29
- //#region src/utils/asset-source.d.ts
30
- type AssetSource = string | Uint8Array;
31
- //#endregion
32
- //#region src/types/external-memory-handle.d.ts
33
- declare const symbolForExternalMemoryHandle: "__rolldown_external_memory_handle__";
34
- /**
35
- * Interface for objects that hold external memory that can be explicitly freed.
36
- */
37
- interface ExternalMemoryHandle {
38
- /**
39
- * Frees the external memory held by this object.
40
- * @param keepDataAlive - If true, evaluates all lazy fields before freeing memory.
41
- * This will take time but prevents errors when accessing properties after freeing.
42
- * @returns Status object with `freed` boolean and optional `reason` string.
43
- * @internal
44
- */
45
- [symbolForExternalMemoryHandle]: (keepDataAlive?: boolean) => ExternalMemoryStatus;
46
- }
47
- /**
48
- * Frees the external memory held by the given handle.
49
- *
50
- * This is useful when you want to manually release memory held by Rust objects
51
- * (like `OutputChunk` or `OutputAsset`) before they are garbage collected.
52
- *
53
- * @param handle - The object with external memory to free
54
- * @param keepDataAlive - If true, evaluates all lazy fields before freeing memory (default: false).
55
- * This will take time to copy data from Rust to JavaScript, but prevents errors
56
- * when accessing properties after the memory is freed.
57
- * @returns Status object with `freed` boolean and optional `reason` string.
58
- * - `{ freed: true }` if memory was successfully freed
59
- * - `{ freed: false, reason: "..." }` if memory couldn't be freed (e.g., already freed or other references exist)
60
- *
61
- * @example
62
- * ```typescript
63
- * import { freeExternalMemory } from '@rollipop/rolldown/experimental';
64
- *
65
- * const output = await bundle.generate();
66
- * const chunk = output.output[0];
67
- *
68
- * // Use the chunk...
69
- *
70
- * // Manually free the memory (fast, but accessing properties after will throw)
71
- * const status = freeExternalMemory(chunk); // { freed: true }
72
- * const statusAgain = freeExternalMemory(chunk); // { freed: false, reason: "Memory has already been freed" }
73
- *
74
- * // Keep data alive before freeing (slower, but data remains accessible)
75
- * freeExternalMemory(chunk, true); // Evaluates all lazy fields first
76
- * console.log(chunk.code); // OK - data was copied to JavaScript before freeing
77
- *
78
- * // Without keepDataAlive, accessing chunk properties after freeing will throw an error
79
- * ```
80
- */
81
- declare function freeExternalMemory(handle: ExternalMemoryHandle, keepDataAlive?: boolean): ExternalMemoryStatus;
82
- //#endregion
83
- //#region src/types/rolldown-output.d.ts
84
- /** @category Plugin APIs */
85
- interface OutputAsset extends ExternalMemoryHandle {
86
- type: "asset";
87
- fileName: string;
88
- /** @deprecated Use "originalFileNames" instead. */
89
- originalFileName: string | null;
90
- originalFileNames: string[];
91
- source: AssetSource;
92
- /** @deprecated Use "names" instead. */
93
- name: string | undefined;
94
- names: string[];
95
- }
96
- /** @category Plugin APIs */
97
- interface SourceMap {
98
- file: string;
99
- mappings: string;
100
- names: string[];
101
- sources: string[];
102
- sourcesContent: string[];
103
- version: number;
104
- debugId?: string;
105
- x_google_ignoreList?: number[];
106
- toString(): string;
107
- toUrl(): string;
108
- }
109
- /** @category Plugin APIs */
110
- interface RenderedModule {
111
- readonly code: string | null;
112
- renderedLength: number;
113
- renderedExports: string[];
114
- }
115
- /**
116
- * The information about the chunk being rendered.
117
- *
118
- * Unlike {@link OutputChunk}, `code` and `map` are not set as the chunk has not been rendered yet.
119
- * All referenced chunk file names in each property that would contain hashes will contain hash placeholders instead.
120
- *
121
- * @category Plugin APIs
122
- */
123
- interface RenderedChunk extends Omit<BindingRenderedChunk, "modules"> {
124
- type: "chunk";
125
- modules: {
126
- [id: string]: RenderedModule;
127
- };
128
- name: string;
129
- isEntry: boolean;
130
- isDynamicEntry: boolean;
131
- facadeModuleId: string | null;
132
- moduleIds: Array<string>;
133
- exports: Array<string>;
134
- fileName: string;
135
- imports: Array<string>;
136
- dynamicImports: Array<string>;
137
- }
138
- /** @category Plugin APIs */
139
- interface OutputChunk extends ExternalMemoryHandle {
140
- type: "chunk";
141
- code: string;
142
- name: string;
143
- isEntry: boolean;
144
- exports: string[];
145
- fileName: string;
146
- modules: {
147
- [id: string]: RenderedModule;
148
- };
149
- imports: string[];
150
- dynamicImports: string[];
151
- facadeModuleId: string | null;
152
- isDynamicEntry: boolean;
153
- moduleIds: string[];
154
- map: SourceMap | null;
155
- sourcemapFileName: string | null;
156
- preliminaryFileName: string;
157
- }
158
- /** @category Programmatic APIs */
159
- interface RolldownOutput extends ExternalMemoryHandle {
160
- output: [OutputChunk, ...(OutputChunk | OutputAsset)[]];
161
- }
162
- //#endregion
163
- //#region src/types/utils.d.ts
164
- type MaybePromise<T> = T | Promise<T>;
165
- type NullValue<T = void> = T | undefined | null | void;
166
- type PartialNull<T> = { [P in keyof T]: T[P] | null };
167
- type MakeAsync<Function_> = Function_ extends ((this: infer This, ...parameters: infer Arguments) => infer Return) ? (this: This, ...parameters: Arguments) => Return | Promise<Return> : never;
168
- type MaybeArray<T> = T | T[];
169
- type StringOrRegExp = string | RegExp;
170
- //#endregion
171
- //#region src/options/output-options.d.ts
172
- type GeneratedCodePreset = "es5" | "es2015";
173
- interface GeneratedCodeOptions {
174
- /**
175
- * Whether to use Symbol.toStringTag for namespace objects.
176
- * @default false
177
- */
178
- symbols?: boolean;
179
- /**
180
- * Allows choosing one of the presets listed above while overriding some options.
181
- *
182
- * ```js
183
- * export default {
184
- * output: {
185
- * generatedCode: {
186
- * preset: 'es2015',
187
- * symbols: false
188
- * }
189
- * }
190
- * };
191
- * ```
192
- *
193
- * @default 'es2015'
194
- */
195
- preset?: GeneratedCodePreset;
196
- /**
197
- * Whether to add readable names to internal variables for profiling purposes.
198
- *
199
- * When enabled, generated code will use descriptive variable names that correspond
200
- * to the original module names, making it easier to profile and debug the bundled code.
201
- *
202
- * @default false
203
- *
204
- * {@include ./docs/output-generated-code-profiler-names.md}
205
- */
206
- profilerNames?: boolean;
207
- }
208
- /** @inline */
209
- type ModuleFormat = "es" | "cjs" | "esm" | "module" | "commonjs" | "iife" | "umd";
210
- /** @inline */
211
- type AddonFunction = (chunk: RenderedChunk) => string | Promise<string>;
212
- /** @inline */
213
- type ChunkFileNamesFunction = (chunkInfo: PreRenderedChunk) => string;
214
- /** @inline */
215
- type SanitizeFileNameFunction = (name: string) => string;
216
- /** @category Plugin APIs */
217
- interface PreRenderedAsset {
218
- type: "asset";
219
- name?: string;
220
- names: string[];
221
- originalFileName?: string;
222
- originalFileNames: string[];
223
- source: string | Uint8Array;
224
- }
225
- /** @inline */
226
- type AssetFileNamesFunction = (chunkInfo: PreRenderedAsset) => string;
227
- /** @inline */
228
- type PathsFunction$1 = (id: string) => string;
229
- /** @inline */
230
- type ManualChunksFunction = (moduleId: string, meta: {
231
- getModuleInfo: (moduleId: string) => ModuleInfo | null;
232
- }) => string | NullValue;
233
- /** @inline */
234
- type GlobalsFunction = (name: string) => string;
235
- /** @inline */
236
- type AdvancedChunksNameFunction = (moduleId: string, ctx: ChunkingContext) => string | NullValue;
237
- /** @inline */
238
- type AdvancedChunksTestFunction = (id: string) => boolean | undefined | void;
239
- type MinifyOptions = Omit<MinifyOptions$1, "module" | "sourcemap">;
240
- interface ChunkingContext {
241
- getModuleInfo(moduleId: string): ModuleInfo | null;
242
- }
243
- interface OutputOptions {
244
- /**
245
- * The directory in which all generated chunks are placed.
246
- *
247
- * The {@linkcode file | output.file} option should be used instead if only a single chunk is generated.
248
- *
249
- * @default 'dist'
250
- */
251
- dir?: string;
252
- /**
253
- * The file path for the single generated chunk.
254
- *
255
- * The {@linkcode dir | output.dir} option should be used instead if multiple chunks are generated.
256
- */
257
- file?: string;
258
- /**
259
- * Which exports mode to use.
260
- *
261
- * {@include ./docs/output-exports.md}
262
- *
263
- * @default 'auto'
264
- */
265
- exports?: "auto" | "named" | "default" | "none";
266
- /**
267
- * Specify the character set that Rolldown is allowed to use in file hashes.
268
- *
269
- * - `'base64'`: Uses url-safe base64 characters (0-9, a-z, A-Z, -, _). This will produce the shortest hashes.
270
- * - `'base36'`: Uses alphanumeric characters (0-9, a-z)
271
- * - `'hex'`: Uses hexadecimal characters (0-9, a-f)
272
- *
273
- * @default 'base64'
274
- */
275
- hashCharacters?: "base64" | "base36" | "hex";
276
- /**
277
- * Expected format of generated code.
278
- *
279
- * - `'es'`, `'esm'` and `'module'` are the same format, all stand for ES module.
280
- * - `'cjs'` and `'commonjs'` are the same format, all stand for CommonJS module.
281
- * - `'iife'` stands for [Immediately Invoked Function Expression](https://developer.mozilla.org/en-US/docs/Glossary/IIFE).
282
- * - `'umd'` stands for [Universal Module Definition](https://github.com/umdjs/umd).
283
- *
284
- * @default 'esm'
285
- */
286
- format?: ModuleFormat;
287
- /**
288
- * Whether to generate sourcemaps.
289
- *
290
- * - `false`: No sourcemap will be generated.
291
- * - `true`: A separate sourcemap file will be generated.
292
- * - `'inline'`: The sourcemap will be appended to the output file as a data URL.
293
- * - `'hidden'`: A separate sourcemap file will be generated, but the link to the sourcemap (`//# sourceMappingURL` comment) will not be included in the output file.
294
- *
295
- * @default false
296
- */
297
- sourcemap?: boolean | "inline" | "hidden";
298
- /**
299
- * The base URL for the links to the sourcemap file in the output file.
300
- *
301
- * 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.
302
- */
303
- sourcemapBaseUrl?: string;
304
- /**
305
- * Whether to include [debug IDs](https://github.com/tc39/ecma426/blob/main/proposals/debug-id.md) in the sourcemap.
306
- *
307
- * When `true`, a unique debug ID will be emitted in source and sourcemaps which streamlines identifying sourcemaps across different builds.
308
- *
309
- * @default false
310
- */
311
- sourcemapDebugIds?: boolean;
312
- /**
313
- * Control which source files are included in the sourcemap ignore list.
314
- *
315
- * Files in the ignore list are excluded from debugger stepping and error stack traces.
316
- *
317
- * - `false`: Include no source files in the ignore list
318
- * - `true`: Include all source files in the ignore list
319
- * - `string`: Files containing this string in their path will be included in the ignore list
320
- * - `RegExp`: Files matching this regular expression will be included in the ignore list
321
- * - `function`: Custom function to determine if a source should be ignored
322
- *
323
- * :::tip Performance
324
- * Using static values (`boolean`, `string`, or `RegExp`) is significantly more performant than functions.
325
- * Calling JavaScript functions from Rust has extremely high overhead, so prefer static patterns when possible.
326
- * :::
327
- *
328
- * @example
329
- * ```js
330
- * // ✅ Preferred: Use RegExp for better performance
331
- * sourcemapIgnoreList: /node_modules/
332
- *
333
- * // ✅ Preferred: Use string pattern for better performance
334
- * sourcemapIgnoreList: "vendor"
335
- *
336
- * // ! Use sparingly: Function calls have high overhead
337
- * sourcemapIgnoreList: (source, sourcemapPath) => {
338
- * return source.includes('node_modules') || source.includes('.min.');
339
- * }
340
- * ```
341
- *
342
- * @default /node_modules/
343
- */
344
- sourcemapIgnoreList?: boolean | SourcemapIgnoreListOption | StringOrRegExp;
345
- /**
346
- * A transformation to apply to each path in a sourcemap.
347
- *
348
- * @example
349
- * ```js
350
- * export default defineConfig({
351
- * output: {
352
- * sourcemap: true,
353
- * sourcemapPathTransform: (source, sourcemapPath) => {
354
- * // Remove 'src/' prefix from all source paths
355
- * return source.replace(/^src\//, '');
356
- * },
357
- * },
358
- * });
359
- * ```
360
- */
361
- sourcemapPathTransform?: SourcemapPathTransformOption;
362
- /**
363
- * A string to prepend to the bundle before `renderChunk` hook.
364
- *
365
- * See {@linkcode intro | output.intro}, {@linkcode postBanner | output.postBanner} as well.
366
- *
367
- * {@include ./docs/output-banner.md}
368
- */
369
- banner?: string | AddonFunction;
370
- /**
371
- * A string to append to the bundle before `renderChunk` hook.
372
- *
373
- * See {@linkcode outro | output.outro}, {@linkcode postFooter | output.postFooter} as well.
374
- *
375
- * {@include ./docs/output-footer.md}
376
- */
377
- footer?: string | AddonFunction;
378
- /**
379
- * A string to prepend to the bundle after `renderChunk` hook and minification.
380
- *
381
- * See {@linkcode banner | output.banner}, {@linkcode intro | output.intro} as well.
382
- */
383
- postBanner?: string | AddonFunction;
384
- /**
385
- * A string to append to the bundle after `renderChunk` hook and minification.
386
- *
387
- * See {@linkcode footer | output.footer}, {@linkcode outro | output.outro} as well.
388
- */
389
- postFooter?: string | AddonFunction;
390
- /**
391
- * A string to prepend inside any format-specific wrapper.
392
- *
393
- * See {@linkcode banner | output.banner}, {@linkcode postBanner | output.postBanner} as well.
394
- */
395
- intro?: string | AddonFunction;
396
- /**
397
- * A string to append inside any format-specific wrapper.
398
- *
399
- * See {@linkcode footer | output.footer}, {@linkcode postFooter | output.postFooter} as well.
400
- */
401
- outro?: string | AddonFunction;
402
- /**
403
- * Whether to extend the global variable defined by the {@linkcode OutputOptions.name | name} option in `umd` or `iife` formats.
404
- *
405
- * When `true`, the global variable will be defined as `global.name = global.name || {}`.
406
- * When `false`, the global defined by name will be overwritten like `global.name = {}`.
407
- *
408
- * @default false
409
- */
410
- extend?: boolean;
411
- /**
412
- * Whether to add a `__esModule: true` property when generating exports for non-ES formats.
413
- *
414
- * 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.
415
- *
416
- * - `true`: Always add the property when using named exports mode, which is similar to what other tools do.
417
- * - `"if-default-prop"`: Only add the property when using named exports mode and there also is a default export. The subtle difference is that if there is no default export, consumers of the CommonJS version of your library will get all named exports as default export instead of an error or `undefined`.
418
- * - `false`: Never add the property even if the default export would become a property `.default`.
419
- *
420
- * @default 'if-default-prop'
421
- */
422
- esModule?: boolean | "if-default-prop";
423
- /**
424
- * The pattern to use for naming custom emitted assets to include in the build output, or a function that is called per asset to return such a pattern.
425
- *
426
- * Patterns support the following placeholders:
427
- * - `[extname]`: The file extension of the asset including a leading dot, e.g. `.css`.
428
- * - `[ext]`: The file extension without a leading dot, e.g. css.
429
- * - `[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}.
430
- * - `[name]`: The file name of the asset excluding any extension.
431
- *
432
- * Forward slashes (`/`) can be used to place files in sub-directories.
433
- *
434
- * See also {@linkcode chunkFileNames | output.chunkFileNames}, {@linkcode entryFileNames | output.entryFileNames}.
435
- *
436
- * @default 'assets/[name]-[hash][extname]'
437
- */
438
- assetFileNames?: string | AssetFileNamesFunction;
439
- /**
440
- * The pattern to use for chunks created from entry points, or a function that is called per entry chunk to return such a pattern.
441
- *
442
- * Patterns support the following placeholders:
443
- * - `[format]`: The rendering format defined in the output options, e.g. `es` or `cjs`.
444
- * - `[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}.
445
- * - `[name]`: The file name (without extension) of the entry point, unless the object form of input was used to define a different name.
446
- *
447
- * 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.
448
- *
449
- * See also {@linkcode assetFileNames | output.assetFileNames}, {@linkcode chunkFileNames | output.chunkFileNames}.
450
- *
451
- * @default '[name].js'
452
- */
453
- entryFileNames?: string | ChunkFileNamesFunction;
454
- /**
455
- * The pattern to use for naming shared chunks created when code-splitting, or a function that is called per chunk to return such a pattern.
456
- *
457
- * Patterns support the following placeholders:
458
- * - `[format]`: The rendering format defined in the output options, e.g. `es` or `cjs`.
459
- * - `[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}.
460
- * - `[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.
461
- *
462
- * Forward slashes (`/`) can be used to place files in sub-directories.
463
- *
464
- * See also {@linkcode assetFileNames | output.assetFileNames}, {@linkcode entryFileNames | output.entryFileNames}.
465
- *
466
- * @default '[name]-[hash].js'
467
- */
468
- chunkFileNames?: string | ChunkFileNamesFunction;
469
- /**
470
- * @default '[name].css'
471
- * @experimental
472
- * @hidden not ready for public usage yet
473
- */
474
- cssEntryFileNames?: string | ChunkFileNamesFunction;
475
- /**
476
- * @default '[name]-[hash].css'
477
- * @experimental
478
- * @hidden not ready for public usage yet
479
- */
480
- cssChunkFileNames?: string | ChunkFileNamesFunction;
481
- /**
482
- * Whether to enable chunk name sanitization (removal of non-URL-safe characters like `\0`, `?` and `*`).
483
- *
484
- * Set `false` to disable the sanitization. You can also provide a custom sanitization function.
485
- *
486
- * @default true
487
- */
488
- sanitizeFileName?: boolean | SanitizeFileNameFunction;
489
- /**
490
- * Control code minification.
491
- *
492
- * - `true`: Enable full minification including code compression and dead code elimination
493
- * - `false`: Disable minification (default)
494
- * - `'dce-only'`: Only perform dead code elimination without code compression
495
- * - `MinifyOptions`: Fine-grained control over minification settings
496
- *
497
- * @default false
498
- */
499
- minify?: boolean | "dce-only" | MinifyOptions;
500
- /**
501
- * Specifies the global variable name that contains the exports of `umd` / `iife` bundles.
502
- *
503
- * @example
504
- * ```js
505
- * export default defineConfig({
506
- * output: {
507
- * format: 'iife',
508
- * name: 'MyBundle',
509
- * }
510
- * });
511
- * ```
512
- * ```js
513
- * // output
514
- * var MyBundle = (function () {
515
- * // ...
516
- * })();
517
- * ```
518
- *
519
- * {@include ./docs/output-name.md}
520
- */
521
- name?: string;
522
- /**
523
- * Specifies `id: variableName` pairs necessary for external imports in `umd` / `iife` bundles.
524
- *
525
- * @example
526
- * ```js
527
- * export default defineConfig({
528
- * external: ['jquery'],
529
- * output: {
530
- * format: 'iife',
531
- * name: 'MyBundle',
532
- * globals: {
533
- * jquery: '$',
534
- * }
535
- * }
536
- * });
537
- * ```
538
- * ```js
539
- * // input
540
- * import $ from 'jquery';
541
- * ```
542
- * ```js
543
- * // output
544
- * var MyBundle = (function ($) {
545
- * // ...
546
- * })($);
547
- * ```
548
- */
549
- globals?: Record<string, string> | GlobalsFunction;
550
- /**
551
- * Maps external module IDs to paths.
552
- *
553
- * Allows customizing the path used when importing external dependencies.
554
- * This is particularly useful for loading dependencies from CDNs or custom locations.
555
- *
556
- * - Object form: Maps module IDs to their replacement paths
557
- * - Function form: Takes a module ID and returns its replacement path
558
- *
559
- * @example
560
- * ```js
561
- * {
562
- * paths: {
563
- * 'd3': 'https://cdn.jsdelivr.net/npm/d3@7'
564
- * }
565
- * }
566
- * ```
567
- *
568
- * @example
569
- * ```js
570
- * {
571
- * paths: (id) => {
572
- * if (id.startsWith('lodash')) {
573
- * return `https://cdn.jsdelivr.net/npm/${id}`
574
- * }
575
- * return id
576
- * }
577
- * }
578
- * ```
579
- */
580
- paths?: Record<string, string> | PathsFunction$1;
581
- /**
582
- * Which language features Rolldown can safely use in generated code.
583
- *
584
- * This will not transpile any user code but only change the code Rolldown uses in wrappers and helpers.
585
- */
586
- generatedCode?: Partial<GeneratedCodeOptions>;
587
- /**
588
- * Whether to generate code to support live bindings for external imports.
589
- *
590
- * With the default value of `true`, Rolldown will generate code to support live bindings for external imports.
591
- *
592
- * 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.
593
- *
594
- * @default true
595
- *
596
- * {@include ./docs/output-external-live-bindings.md}
597
- */
598
- externalLiveBindings?: boolean;
599
- /**
600
- * Whether to inline dynamic imports instead of creating new chunks to create a single bundle.
601
- *
602
- * This option can be used only when a single input is provided.
603
- *
604
- * @default false
605
- */
606
- inlineDynamicImports?: boolean;
607
- /**
608
- * Whether to keep external dynamic imports as `import(...)` expressions in CommonJS output.
609
- *
610
- * If set to `false`, external dynamic imports will be rewritten to use `require(...)` calls.
611
- * This may be necessary to support environments that do not support dynamic `import()` in CommonJS modules like old Node.js versions.
612
- *
613
- * @default true
614
- */
615
- dynamicImportInCjs?: boolean;
616
- /**
617
- * Allows you to do manual chunking. Provided for Rollup compatibility.
618
- *
619
- * You could use this option for migration purpose. Under the hood,
620
- *
621
- * ```js
622
- * {
623
- * manualChunks: (moduleId, meta) => {
624
- * if (moduleId.includes('node_modules')) {
625
- * return 'vendor';
626
- * }
627
- * return null;
628
- * }
629
- * }
630
- * ```
631
- *
632
- * will be transformed to
633
- *
634
- * ```js
635
- * {
636
- * codeSplitting: {
637
- * groups: [
638
- * {
639
- * name(moduleId) {
640
- * if (moduleId.includes('node_modules')) {
641
- * return 'vendor';
642
- * }
643
- * return null;
644
- * },
645
- * },
646
- * ],
647
- * }
648
- * }
649
- *
650
- * ```
651
- *
652
- * Note that unlike Rollup, object form is not supported.
653
- *
654
- * @deprecated
655
- * Please use {@linkcode codeSplitting | output.codeSplitting} instead.
656
- *
657
- * :::warning
658
- * If `manualChunks` and `codeSplitting` are both specified, `manualChunks` option will be ignored.
659
- * :::
660
- */
661
- manualChunks?: ManualChunksFunction;
662
- /**
663
- * Allows you to do manual chunking. For deeper understanding, please refer to the in-depth [documentation](https://rolldown.rs/in-depth/advanced-chunks).
664
- *
665
- * @example
666
- * **Basic vendor chunk**
667
- * ```js
668
- * export default defineConfig({
669
- * output: {
670
- * codeSplitting: {
671
- * minSize: 20000,
672
- * groups: [
673
- * {
674
- * name: 'vendor',
675
- * test: /node_modules/,
676
- * },
677
- * ],
678
- * },
679
- * },
680
- * });
681
- * ```
682
- * {@include ./docs/output-advanced-chunks.md}
683
- */
684
- codeSplitting?: {
685
- /**
686
- * By default, each group will also include captured modules' dependencies. This reduces the chance of generating circular chunks.
687
- *
688
- * If you want to disable this behavior, it's recommended to both set
689
- * - {@linkcode InputOptions.preserveEntrySignatures | preserveEntrySignatures}: `false | 'allow-extension'`
690
- * - `experimental.strictExecutionOrder`: `true`
691
- *
692
- * to avoid generating invalid chunks.
693
- *
694
- * @default true
695
- */
696
- includeDependenciesRecursively?: boolean;
697
- /**
698
- * Global fallback of {@linkcode CodeSplittingGroup.minSize | group.minSize}, if it's not specified in the group.
699
- */
700
- minSize?: number;
701
- /**
702
- * Global fallback of {@linkcode CodeSplittingGroup.maxSize | group.maxSize}, if it's not specified in the group.
703
- */
704
- maxSize?: number;
705
- /**
706
- * Global fallback of {@linkcode CodeSplittingGroup.maxModuleSize | group.maxModuleSize}, if it's not specified in the group.
707
- */
708
- maxModuleSize?: number;
709
- /**
710
- * Global fallback of {@linkcode CodeSplittingGroup.minModuleSize | group.minModuleSize}, if it's not specified in the group.
711
- */
712
- minModuleSize?: number;
713
- /**
714
- * Global fallback of {@linkcode CodeSplittingGroup.minShareCount | group.minShareCount}, if it's not specified in the group.
715
- */
716
- minShareCount?: number;
717
- /**
718
- * Groups to be used for code splitting.
719
- */
720
- groups?: CodeSplittingGroup[];
721
- };
722
- /**
723
- * @deprecated Please use {@linkcode codeSplitting | output.codeSplitting} instead.
724
- *
725
- * Allows you to do manual chunking.
726
- *
727
- * :::warning
728
- * If `advancedChunks` and `codeSplitting` are both specified, `advancedChunks` option will be ignored.
729
- * :::
730
- */
731
- advancedChunks?: {
732
- includeDependenciesRecursively?: boolean;
733
- minSize?: number;
734
- maxSize?: number;
735
- maxModuleSize?: number;
736
- minModuleSize?: number;
737
- minShareCount?: number;
738
- groups?: CodeSplittingGroup[];
739
- };
740
- /**
741
- * Control comments in the output.
742
- *
743
- * - `none`: no comments
744
- * - `inline`: preserve comments that contain `@license`, `@preserve` or starts with `//!` `/*!`
745
- */
746
- legalComments?: "none" | "inline";
747
- /**
748
- * The list of plugins to use only for this output.
749
- */
750
- plugins?: RolldownOutputPluginOption;
751
- /**
752
- * Whether to add a polyfill for `require()` function in non-CommonJS formats.
753
- *
754
- * This option is useful when you want to inject your own `require` implementation.
755
- *
756
- * @default true
757
- */
758
- polyfillRequire?: boolean;
759
- /**
760
- * This option is not implemented yet.
761
- * @hidden
762
- */
763
- hoistTransitiveImports?: false;
764
- /**
765
- * Whether to use preserve modules mode.
766
- *
767
- * {@include ./docs/output-preserve-modules.md}
768
- *
769
- * @default false
770
- */
771
- preserveModules?: boolean;
772
- /**
773
- * Specifies the directory name for "virtual" files that might be emitted by plugins when using preserve modules mode.
774
- *
775
- * @default '_virtual'
776
- */
777
- virtualDirname?: string;
778
- /**
779
- * A directory path to input modules that should be stripped away from {@linkcode dir | output.dir} when using preserve modules mode.
780
- *
781
- * {@include ./docs/output-preserve-modules-root.md}
782
- */
783
- preserveModulesRoot?: string;
784
- /**
785
- * Whether to use `var` declarations at the top level scope instead of function / class / let / const expressions.
786
- *
787
- * Enabling this option can improve runtime performance of the generated code in certain environments.
788
- *
789
- * @default false
790
- *
791
- * {@include ./docs/output-top-level-var.md}
792
- */
793
- topLevelVar?: boolean;
794
- /**
795
- * Whether to minify internal exports as single letter variables to allow for better minification.
796
- *
797
- * @default
798
- * `true` for format `es` or if `output.minify` is `true` or object, `false` otherwise
799
- *
800
- * {@include ./docs/output-minify-internal-exports.md}
801
- */
802
- minifyInternalExports?: boolean;
803
- /**
804
- * Clean output directory ({@linkcode dir | output.dir}) before emitting output.
805
- *
806
- * @default false
807
- *
808
- * {@include ./docs/output-clean-dir.md}
809
- */
810
- cleanDir?: boolean;
811
- /**
812
- * Keep `name` property of functions and classes after bundling.
813
- *
814
- * When enabled, the bundler will preserve the original `name` property value of functions and
815
- * classes in the output. This is useful for debugging and some frameworks that rely on it for
816
- * registration and binding purposes.
817
- *
818
- * @default false
819
- */
820
- keepNames?: boolean;
821
- }
822
- type CodeSplittingGroup = {
823
- /**
824
- * 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.
825
- *
826
- * For example,
827
- *
828
- * ```js
829
- * import { defineConfig } from '@rollipop/rolldown';
830
- *
831
- * export default defineConfig({
832
- * advancedChunks: {
833
- * groups: [
834
- * {
835
- * name: 'libs',
836
- * test: /node_modules/,
837
- * },
838
- * ],
839
- * },
840
- * });
841
- * ```
842
- * will create a chunk named `libs-[hash].js` in the end.
843
- *
844
- * It's ok to have the same name for different groups. Rolldown will deduplicate the chunk names if necessary.
845
- *
846
- * #### Dynamic `name()`
847
- *
848
- * 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.
849
- *
850
- * Notice, each returned new name will be treated as a separate group.
851
- *
852
- * For example,
853
- *
854
- * ```js
855
- * import { defineConfig } from '@rollipop/rolldown';
856
- *
857
- * export default defineConfig({
858
- * advancedChunks: {
859
- * groups: [
860
- * {
861
- * name: (moduleId) => moduleId.includes('node_modules') ? 'libs' : 'app',
862
- * minSize: 100 * 1024,
863
- * },
864
- * ],
865
- * },
866
- * });
867
- * ```
868
- *
869
- * :::warning
870
- * Constraints like `minSize`, `maxSize`, etc. are applied separately for different names returned by the function.
871
- * :::
872
- */
873
- name: string | AdvancedChunksNameFunction;
874
- /**
875
- * Controls which modules are captured in this group.
876
- *
877
- * - If `test` is a string, the module whose id contains the string will be captured.
878
- * - If `test` is a regular expression, the module whose id matches the regular expression will be captured.
879
- * - If `test` is a function, modules for which `test(id)` returns `true` will be captured.
880
- * - If `test` is empty, any module will be considered as matched.
881
- *
882
- * :::warning
883
- * When using regular expression, it's recommended to use `[\\/]` to match the path separator instead of `/` to avoid potential issues on Windows.
884
- * - ✅ Recommended: `/node_modules[\\/]react/`
885
- * - ❌ Not recommended: `/node_modules/react/`
886
- * :::
887
- */
888
- test?: StringOrRegExp | AdvancedChunksTestFunction;
889
- /**
890
- * 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.
891
- *
892
- * If two groups have the same priority, the group whose index is smaller will be chosen.
893
- *
894
- * @example
895
- * ```js
896
- * import { defineConfig } from '@rollipop/rolldown';
897
- *
898
- * export default defineConfig({
899
- * advancedChunks: {
900
- * groups: [
901
- * {
902
- * name: 'react',
903
- * test: /node_modules[\\/]react/,
904
- * priority: 2,
905
- * },
906
- * {
907
- * name: 'other-libs',
908
- * test: /node_modules/,
909
- * priority: 1,
910
- * },
911
- * ],
912
- * });
913
- * ```
914
- *
915
- * @default 0
916
- */
917
- priority?: number;
918
- /**
919
- * 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.
920
- *
921
- * @default 0
922
- */
923
- minSize?: number;
924
- /**
925
- * Controls if a module should be captured based on how many entry chunks reference it.
926
- *
927
- * @default 1
928
- */
929
- minShareCount?: number;
930
- /**
931
- * 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.
932
- *
933
- * @default Infinity
934
- */
935
- maxSize?: number;
936
- /**
937
- * Controls whether a module can only be captured if its size in bytes is smaller than or equal to this value.
938
- *
939
- * @default Infinity
940
- */
941
- maxModuleSize?: number;
942
- /**
943
- * Controls whether a module can only be captured if its size in bytes is larger than or equal to this value.
944
- *
945
- * @default 0
946
- */
947
- minModuleSize?: number;
948
- };
949
- /**
950
- * Alias for {@linkcode CodeSplittingGroup}. Use this type for the `codeSplitting.groups` option.
951
- */
952
- type AdvancedChunksGroup = CodeSplittingGroup;
953
- //#endregion
954
- //#region src/api/build.d.ts
955
- interface BuildOptions extends InputOptions {
956
- /**
957
- * Write the output to the file system
958
- *
959
- * @default true
960
- */
961
- write?: boolean;
962
- output?: OutputOptions;
963
- }
964
- /** @category Programmatic APIs */
965
- declare function build(options: BuildOptions): Promise<RolldownOutput>;
966
- /**
967
- * Build multiple outputs __sequentially__.
968
- */
969
- declare function build(options: BuildOptions[]): Promise<RolldownOutput[]>;
970
- //#endregion
971
- //#region src/api/rolldown/rolldown-build.d.ts
972
- /** @category Programmatic APIs */
973
- declare class RolldownBuild {
974
- #private;
975
- static asyncRuntimeShutdown: boolean;
976
- constructor(inputOptions: InputOptions);
977
- get closed(): boolean;
978
- generate(outputOptions?: OutputOptions): Promise<RolldownOutput>;
979
- write(outputOptions?: OutputOptions): Promise<RolldownOutput>;
980
- /**
981
- * Close the build and free resources.
982
- */
983
- close(): Promise<void>;
984
- [Symbol.asyncDispose](): Promise<void>;
985
- get watchFiles(): Promise<string[]>;
986
- }
987
- //#endregion
988
- //#region src/api/rolldown/index.d.ts
989
- /** @category Programmatic APIs */
990
- declare const rolldown: (input: InputOptions) => Promise<RolldownBuild>;
991
- //#endregion
992
- //#region src/options/watch-options.d.ts
993
- /** @category Programmatic APIs */
994
- interface WatchOptions extends InputOptions {
995
- output?: OutputOptions | OutputOptions[];
996
- }
997
- //#endregion
998
- //#region src/api/watch/watch-emitter.d.ts
999
- type WatcherEvent = "close" | "event" | "restart" | "change";
1000
- type ChangeEvent$1 = "create" | "update" | "delete";
1001
- type RolldownWatchBuild = BindingWatcherBundler;
1002
- /** @category Programmatic APIs */
1003
- type RolldownWatcherEvent = {
1004
- code: "START";
1005
- } | {
1006
- code: "BUNDLE_START";
1007
- } | {
1008
- code: "BUNDLE_END";
1009
- duration: number;
1010
- output: readonly string[];
1011
- result: RolldownWatchBuild;
1012
- } | {
1013
- code: "END";
1014
- } | {
1015
- code: "ERROR";
1016
- error: Error;
1017
- result: RolldownWatchBuild;
1018
- };
1019
- declare class WatcherEmitter {
1020
- listeners: Map<WatcherEvent, Array<(...parameters: any[]) => MaybePromise<void>>>;
1021
- timer: any;
1022
- constructor();
1023
- on(event: "change", listener: (id: string, change: {
1024
- event: ChangeEvent$1;
1025
- }) => MaybePromise<void>): this;
1026
- on(event: "event", listener: (data: RolldownWatcherEvent) => MaybePromise<void>): this;
1027
- on(event: "restart" | "close", listener: () => MaybePromise<void>): this;
1028
- off(event: WatcherEvent, listener: (...parameters: any[]) => MaybePromise<void>): this;
1029
- clear(event: WatcherEvent): void;
1030
- onEvent(event: BindingWatcherEvent): Promise<void>;
1031
- close(): Promise<void>;
1032
- }
1033
- /** @category Programmatic APIs */
1034
- type RolldownWatcher = WatcherEmitter;
1035
- //#endregion
1036
- //#region src/api/watch/index.d.ts
1037
- /** @category Programmatic APIs */
1038
- declare const watch: (input: WatchOptions | WatchOptions[]) => RolldownWatcher;
1039
- //#endregion
1040
- //#region src/log/log-handler.d.ts
1041
- type LoggingFunction = (log: RollupLog | string | (() => RollupLog | string)) => void;
1042
- type LoggingFunctionWithPosition = (log: RollupLog | string | (() => RollupLog | string), pos?: number | {
1043
- column: number;
1044
- line: number;
1045
- }) => void;
1046
- type WarningHandlerWithDefault = (warning: RollupLog, defaultHandler: LoggingFunction) => void;
1047
- //#endregion
1048
- //#region src/options/generated/checks-options.d.ts
1049
- interface ChecksOptions {
1050
- /**
1051
- * Whether to emit warnings when detecting circular dependency
1052
- *
1053
- * Circular dependencies lead to a bigger bundle size and sometimes cause execution order issues and are better to avoid.
1054
- * @default false
1055
- * */
1056
- circularDependency?: boolean;
1057
- /**
1058
- * Whether to emit warnings when detecting uses of direct `eval`s
1059
- *
1060
- * See [Avoiding Direct `eval` in Troubleshooting page](https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval) for more details.
1061
- * @default true
1062
- * */
1063
- eval?: boolean;
1064
- /**
1065
- * Whether to emit warnings when the `output.globals` option is missing when needed
1066
- *
1067
- * See [`output.globals`](https://rolldown.rs/reference/OutputOptions.globals).
1068
- * @default true
1069
- * */
1070
- missingGlobalName?: boolean;
1071
- /**
1072
- * Whether to emit warnings when the `output.name` option is missing when needed
1073
- *
1074
- * See [`output.name`](https://rolldown.rs/reference/OutputOptions.name).
1075
- * @default true
1076
- * */
1077
- missingNameOptionForIifeExport?: boolean;
1078
- /**
1079
- * Whether to emit warnings when the way to export values is ambiguous
1080
- *
1081
- * See [`output.exports`](https://rolldown.rs/reference/OutputOptions.exports).
1082
- * @default true
1083
- * */
1084
- mixedExports?: boolean;
1085
- /**
1086
- * Whether to emit warnings when an entrypoint cannot be resolved
1087
- * @default true
1088
- * */
1089
- unresolvedEntry?: boolean;
1090
- /**
1091
- * Whether to emit warnings when an import cannot be resolved
1092
- * @default true
1093
- * */
1094
- unresolvedImport?: boolean;
1095
- /**
1096
- * Whether to emit warnings when files generated have the same name with different contents
1097
- * @default true
1098
- * */
1099
- filenameConflict?: boolean;
1100
- /**
1101
- * Whether to emit warnings when a CommonJS variable is used in an ES module
1102
- *
1103
- * CommonJS variables like `module` and `exports` are treated as global variables in ES modules and may not work as expected.
1104
- * @default true
1105
- * */
1106
- commonJsVariableInEsm?: boolean;
1107
- /**
1108
- * Whether to emit warnings when an imported variable is not exported
1109
- *
1110
- * 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.
1111
- * @default true
1112
- * */
1113
- importIsUndefined?: boolean;
1114
- /**
1115
- * Whether to emit warnings when `import.meta` is not supported with the output format and is replaced with an empty object (`{}`)
1116
- *
1117
- * See [`import.meta` in Non-ESM Output Formats page](https://rolldown.rs/in-depth/non-esm-output-formats#import-meta) for more details.
1118
- * @default true
1119
- * */
1120
- emptyImportMeta?: boolean;
1121
- /**
1122
- * Whether to emit warnings when a namespace is called as a function
1123
- *
1124
- * A module namespace object is an object and not a function. Calling it as a function will cause a runtime error.
1125
- * @default true
1126
- * */
1127
- cannotCallNamespace?: boolean;
1128
- /**
1129
- * Whether to emit warnings when a config value is overridden by another config value with a higher priority
1130
- * @default true
1131
- * */
1132
- configurationFieldConflict?: boolean;
1133
- /**
1134
- * Whether to emit warnings when a plugin that is covered by a built-in feature is used
1135
- *
1136
- * Using built-in features is generally more performant than using plugins.
1137
- * @default true
1138
- * */
1139
- preferBuiltinFeature?: boolean;
1140
- /**
1141
- * Whether to emit warnings when Rolldown could not clean the output directory
1142
- *
1143
- * See [`output.cleanDir`](https://rolldown.rs/reference/OutputOptions.cleanDir).
1144
- * @default true
1145
- * */
1146
- couldNotCleanDirectory?: boolean;
1147
- /**
1148
- * Whether to emit warnings when plugins take significant time during the build process
1149
- *
1150
- * {@include ../docs/checks-plugin-timings.md}
1151
- * @default true
1152
- * */
1153
- pluginTimings?: boolean;
1154
- }
1155
- //#endregion
1156
- //#region src/options/transform-options.d.ts
1157
- interface TransformOptions extends Omit<TransformOptions$1, "sourceType" | "lang" | "cwd" | "sourcemap" | "define" | "inject" | "jsx"> {
1158
- /**
1159
- * Replace global variables or [property accessors](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors) with the provided values.
1160
- *
1161
- * @example
1162
- * **Replace the global variable `IS_PROD` with `true`**
1163
- * ```js rolldown.config.js
1164
- * export default defineConfig({
1165
- * transform: { define: { IS_PROD: 'true' } }
1166
- * })
1167
- * ```
1168
- * Result:
1169
- * ```js
1170
- * // Input
1171
- * if (IS_PROD) {
1172
- * console.log('Production mode')
1173
- * }
1174
- *
1175
- * // After bundling
1176
- * if (true) {
1177
- * console.log('Production mode')
1178
- * }
1179
- * ```
1180
- *
1181
- * **Replace the property accessor `process.env.NODE_ENV` with `'production'`**
1182
- * ```js rolldown.config.js
1183
- * export default defineConfig({
1184
- * transform: { define: { 'process.env.NODE_ENV': "'production'" } }
1185
- * })
1186
- * ```
1187
- * Result:
1188
- * ```js
1189
- * // Input
1190
- * if (process.env.NODE_ENV === 'production') {
1191
- * console.log('Production mode')
1192
- * }
1193
- *
1194
- * // After bundling
1195
- * if ('production' === 'production') {
1196
- * console.log('Production mode')
1197
- * }
1198
- * ```
1199
- */
1200
- define?: Record<string, string>;
1201
- /**
1202
- * Inject import statements on demand.
1203
- *
1204
- * The API is aligned with `@rollup/plugin-inject`.
1205
- *
1206
- * #### Supported patterns
1207
- * ```js
1208
- * {
1209
- * // import { Promise } from 'es6-promise'
1210
- * Promise: ['es6-promise', 'Promise'],
1211
- *
1212
- * // import { Promise as P } from 'es6-promise'
1213
- * P: ['es6-promise', 'Promise'],
1214
- *
1215
- * // import $ from 'jquery'
1216
- * $: 'jquery',
1217
- *
1218
- * // import * as fs from 'node:fs'
1219
- * fs: ['node:fs', '*'],
1220
- *
1221
- * // Inject shims for property access pattern
1222
- * 'Object.assign': path.resolve( 'src/helpers/object-assign.js' ),
1223
- * }
1224
- * ```
1225
- */
1226
- inject?: Record<string, string | [string, string]>;
1227
- /**
1228
- * Remove labeled statements with these label names.
1229
- *
1230
- * Labeled statements are JavaScript statements prefixed with a label identifier.
1231
- * This option allows you to strip specific labeled statements from the output,
1232
- * which is useful for removing debug-only code in production builds.
1233
- *
1234
- * @example
1235
- * ```js rolldown.config.js
1236
- * export default defineConfig({
1237
- * transform: { dropLabels: ['DEBUG', 'DEV'] }
1238
- * })
1239
- * ```
1240
- * Result:
1241
- * ```js
1242
- * // Input
1243
- * DEBUG: console.log('Debug info');
1244
- * DEV: {
1245
- * console.log('Development mode');
1246
- * }
1247
- * console.log('Production code');
1248
- *
1249
- * // After bundling
1250
- * console.log('Production code');
1251
- * ```
1252
- */
1253
- dropLabels?: string[];
1254
- /**
1255
- * Controls how JSX syntax is transformed.
1256
- *
1257
- * - If set to `false`, an error will be thrown if JSX syntax is encountered.
1258
- * - If set to `'react'`, JSX syntax will be transformed to classic runtime React code.
1259
- * - If set to `'react-jsx'`, JSX syntax will be transformed to automatic runtime React code.
1260
- * - If set to `'preserve'`, JSX syntax will be preserved as-is.
1261
- */
1262
- jsx?: false | "react" | "react-jsx" | "preserve" | JsxOptions;
1263
- }
1264
- //#endregion
1265
- //#region src/options/normalized-input-options.d.ts
1266
- /** @category Plugin APIs */
1267
- interface NormalizedInputOptions {
1268
- input: string[] | Record<string, string>;
1269
- cwd: string;
1270
- platform: InputOptions["platform"];
1271
- shimMissingExports: boolean;
1272
- context: string;
1273
- }
1274
- //#endregion
1275
- //#region src/options/normalized-output-options.d.ts
1276
- type PathsFunction = (id: string) => string;
1277
- /** @category Plugin APIs */
1278
- type InternalModuleFormat = "es" | "cjs" | "iife" | "umd";
1279
- /** @category Plugin APIs */
1280
- interface NormalizedOutputOptions {
1281
- name: string | undefined;
1282
- file: string | undefined;
1283
- dir: string | undefined;
1284
- entryFileNames: string | ChunkFileNamesFunction;
1285
- chunkFileNames: string | ChunkFileNamesFunction;
1286
- assetFileNames: string | AssetFileNamesFunction;
1287
- format: InternalModuleFormat;
1288
- exports: NonNullable<OutputOptions["exports"]>;
1289
- sourcemap: boolean | "inline" | "hidden";
1290
- sourcemapBaseUrl: string | undefined;
1291
- cssEntryFileNames: string | ChunkFileNamesFunction;
1292
- cssChunkFileNames: string | ChunkFileNamesFunction;
1293
- inlineDynamicImports: boolean;
1294
- dynamicImportInCjs: boolean;
1295
- externalLiveBindings: boolean;
1296
- banner: AddonFunction;
1297
- footer: AddonFunction;
1298
- postBanner: AddonFunction;
1299
- postFooter: AddonFunction;
1300
- intro: AddonFunction;
1301
- outro: AddonFunction;
1302
- esModule: boolean | "if-default-prop";
1303
- extend: boolean;
1304
- globals: Record<string, string> | GlobalsFunction;
1305
- paths: Record<string, string> | PathsFunction | undefined;
1306
- hashCharacters: "base64" | "base36" | "hex";
1307
- sourcemapDebugIds: boolean;
1308
- sourcemapIgnoreList: boolean | SourcemapIgnoreListOption | StringOrRegExp | undefined;
1309
- sourcemapPathTransform: SourcemapPathTransformOption | undefined;
1310
- minify: false | MinifyOptions | "dce-only";
1311
- legalComments: "none" | "inline";
1312
- polyfillRequire: boolean;
1313
- plugins: RolldownPlugin[];
1314
- preserveModules: boolean;
1315
- virtualDirname: string;
1316
- preserveModulesRoot?: string;
1317
- topLevelVar?: boolean;
1318
- minifyInternalExports?: boolean;
1319
- }
1320
- //#endregion
1321
- //#region src/plugin/fs.d.ts
1322
- /** @category Plugin APIs */
1323
- interface RolldownFsModule {
1324
- appendFile(path: string, data: string | Uint8Array, options?: {
1325
- encoding?: BufferEncoding | null;
1326
- mode?: string | number;
1327
- flag?: string | number;
1328
- }): Promise<void>;
1329
- copyFile(source: string, destination: string, mode?: string | number): Promise<void>;
1330
- mkdir(path: string, options?: {
1331
- recursive?: boolean;
1332
- mode?: string | number;
1333
- }): Promise<void>;
1334
- mkdtemp(prefix: string): Promise<string>;
1335
- readdir(path: string, options?: {
1336
- withFileTypes?: false;
1337
- }): Promise<string[]>;
1338
- readdir(path: string, options?: {
1339
- withFileTypes: true;
1340
- }): Promise<RolldownDirectoryEntry[]>;
1341
- readFile(path: string, options?: {
1342
- encoding?: null;
1343
- flag?: string | number;
1344
- signal?: AbortSignal;
1345
- }): Promise<Uint8Array>;
1346
- readFile(path: string, options?: {
1347
- encoding: BufferEncoding;
1348
- flag?: string | number;
1349
- signal?: AbortSignal;
1350
- }): Promise<string>;
1351
- realpath(path: string): Promise<string>;
1352
- rename(oldPath: string, newPath: string): Promise<void>;
1353
- rmdir(path: string, options?: {
1354
- recursive?: boolean;
1355
- }): Promise<void>;
1356
- stat(path: string): Promise<RolldownFileStats>;
1357
- lstat(path: string): Promise<RolldownFileStats>;
1358
- unlink(path: string): Promise<void>;
1359
- writeFile(path: string, data: string | Uint8Array, options?: {
1360
- encoding?: BufferEncoding | null;
1361
- mode?: string | number;
1362
- flag?: string | number;
1363
- }): Promise<void>;
1364
- }
1365
- /** @category Plugin APIs */
1366
- type BufferEncoding = "ascii" | "utf8" | "utf16le" | "ucs2" | "base64" | "base64url" | "latin1" | "binary" | "hex";
1367
- /** @category Plugin APIs */
1368
- interface RolldownDirectoryEntry {
1369
- isFile(): boolean;
1370
- isDirectory(): boolean;
1371
- isSymbolicLink(): boolean;
1372
- name: string;
1373
- }
1374
- /** @category Plugin APIs */
1375
- interface RolldownFileStats {
1376
- isFile(): boolean;
1377
- isDirectory(): boolean;
1378
- isSymbolicLink(): boolean;
1379
- size: number;
1380
- mtime: Date;
1381
- ctime: Date;
1382
- atime: Date;
1383
- birthtime: Date;
1384
- }
1385
- //#endregion
1386
- //#region src/plugin/hook-filter.d.ts
1387
- /** @category Plugin APIs */
1388
- type GeneralHookFilter<Value = StringOrRegExp> = MaybeArray<Value> | {
1389
- include?: MaybeArray<Value>;
1390
- exclude?: MaybeArray<Value>;
1391
- };
1392
- interface FormalModuleTypeFilter {
1393
- include?: ModuleType[];
1394
- }
1395
- /** @category Plugin APIs */
1396
- type ModuleTypeFilter = ModuleType[] | FormalModuleTypeFilter;
1397
- /** @category Plugin APIs */
1398
- interface HookFilter {
1399
- /**
1400
- * This filter is used to do a pre-test to determine whether the hook should be called.
1401
- *
1402
- * @example
1403
- * Include all `id`s that contain `node_modules` in the path.
1404
- * ```js
1405
- * { id: '**'+'/node_modules/**' }
1406
- * ```
1407
- * @example
1408
- * Include all `id`s that contain `node_modules` or `src` in the path.
1409
- * ```js
1410
- * { id: ['**'+'/node_modules/**', '**'+'/src/**'] }
1411
- * ```
1412
- * @example
1413
- * Include all `id`s that start with `http`
1414
- * ```js
1415
- * { id: /^http/ }
1416
- * ```
1417
- * @example
1418
- * Exclude all `id`s that contain `node_modules` in the path.
1419
- * ```js
1420
- * { id: { exclude: '**'+'/node_modules/**' } }
1421
- * ```
1422
- * @example
1423
- * Formal pattern to define includes and excludes.
1424
- * ```
1425
- * { id : {
1426
- * include: ['**'+'/foo/**', /bar/],
1427
- * exclude: ['**'+'/baz/**', /qux/]
1428
- * }}
1429
- * ```
1430
- */
1431
- id?: GeneralHookFilter;
1432
- moduleType?: ModuleTypeFilter;
1433
- code?: GeneralHookFilter;
1434
- }
1435
- type TUnionWithTopLevelFilterExpressionArray<T> = T | TopLevelFilterExpression[];
1436
- //#endregion
1437
- //#region src/plugin/minimal-plugin-context.d.ts
1438
- /** @category Plugin APIs */
1439
- interface PluginContextMeta {
1440
- rollupVersion: string;
1441
- rolldownVersion: string;
1442
- watchMode: boolean;
1443
- }
1444
- /** @category Plugin APIs */
1445
- interface MinimalPluginContext {
1446
- readonly pluginName: string;
1447
- error: (e: RollupError | string) => never;
1448
- info: LoggingFunction;
1449
- warn: LoggingFunction;
1450
- debug: LoggingFunction;
1451
- meta: PluginContextMeta;
1452
- }
1453
- //#endregion
1454
- //#region src/plugin/parallel-plugin.d.ts
1455
- type ParallelPlugin = {
1456
- _parallel: {
1457
- fileUrl: string;
1458
- options: unknown;
1459
- };
1460
- };
1461
- /** @internal */
1462
- type DefineParallelPluginResult<Options> = (options: Options) => ParallelPlugin;
1463
- declare function defineParallelPlugin<Options>(pluginPath: string): DefineParallelPluginResult<Options>;
1464
- //#endregion
1465
- //#region src/plugin/plugin-context.d.ts
1466
- /** @category Plugin APIs */
1467
- interface EmittedAsset {
1468
- type: "asset";
1469
- name?: string;
1470
- fileName?: string;
1471
- originalFileName?: string;
1472
- source: AssetSource;
1473
- }
1474
- interface EmittedChunk {
1475
- type: "chunk";
1476
- name?: string;
1477
- fileName?: string;
1478
- preserveSignature?: "strict" | "allow-extension" | "exports-only" | false;
1479
- id: string;
1480
- importer?: string;
1481
- }
1482
- interface EmittedPrebuiltChunk {
1483
- type: "prebuilt-chunk";
1484
- fileName: string;
1485
- code: string;
1486
- exports?: string[];
1487
- map?: SourceMap;
1488
- sourcemapFileName?: string;
1489
- }
1490
- /** @category Plugin APIs */
1491
- type EmittedFile = EmittedAsset | EmittedChunk | EmittedPrebuiltChunk;
1492
- interface PluginContextResolveOptions {
1493
- isEntry?: boolean;
1494
- skipSelf?: boolean;
1495
- custom?: CustomPluginOptions;
1496
- }
1497
- /** @category Plugin APIs */
1498
- type GetModuleInfo = (moduleId: string) => ModuleInfo | null;
1499
- /** @category Plugin APIs */
1500
- interface PluginContext extends MinimalPluginContext {
1501
- fs: RolldownFsModule;
1502
- emitFile(file: EmittedFile): string;
1503
- getFileName(referenceId: string): string;
1504
- getModuleIds(): IterableIterator<string>;
1505
- getModuleInfo: GetModuleInfo;
1506
- addWatchFile(id: string): void;
1507
- load(options: {
1508
- id: string;
1509
- resolveDependencies?: boolean;
1510
- } & Partial<PartialNull<ModuleOptions>>): Promise<ModuleInfo>;
1511
- parse(input: string, options?: ParserOptions | null): Program;
1512
- resolve(source: string, importer?: string, options?: PluginContextResolveOptions): Promise<ResolvedId | null>;
1513
- }
1514
- //#endregion
1515
- //#region src/plugin/transform-plugin-context.d.ts
1516
- /** @category Plugin APIs */
1517
- interface TransformPluginContext extends PluginContext {
1518
- debug: LoggingFunctionWithPosition;
1519
- info: LoggingFunctionWithPosition;
1520
- warn: LoggingFunctionWithPosition;
1521
- error(e: RollupError | string, pos?: number | {
1522
- column: number;
1523
- line: number;
1524
- }): never;
1525
- getCombinedSourcemap(): SourceMap;
1526
- }
1527
- //#endregion
1528
- //#region src/types/module-side-effects.d.ts
1529
- interface ModuleSideEffectsRule {
1530
- test?: RegExp;
1531
- external?: boolean;
1532
- sideEffects: boolean;
1533
- }
1534
- type ModuleSideEffectsOption = boolean | readonly string[] | ModuleSideEffectsRule[] | ((id: string, external: boolean) => boolean | undefined) | "no-external";
1535
- /**
1536
- * When passing an object, you can fine-tune the tree-shaking behavior.
1537
- */
1538
- type TreeshakingOptions = {
1539
- /**
1540
- * **Values:**
1541
- *
1542
- * - **`true`**: All modules are assumed to have side effects and will be included in the bundle even if none of their exports are used.
1543
- * - **`false`**: No modules have side effects. This enables aggressive tree-shaking, removing any modules whose exports are not used.
1544
- * - **`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.
1545
- * - **`'no-external'`**: Assumes no external modules have side effects while preserving the default behavior for local modules.
1546
- * - **`ModuleSideEffectsRule[]`**: Array of rules with `test`, `external`, and `sideEffects` properties for fine-grained control.
1547
- * - **`function`**: Function that receives `(id, external)` and returns whether the module has side effects.
1548
- *
1549
- * **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.
1550
- *
1551
- * > [!NOTE]
1552
- * > **Performance: Prefer `ModuleSideEffectsRule[]` over functions**
1553
- * >
1554
- * > 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.
1555
- * >
1556
- * > **Functions should be a last resort**: Only use the function signature when your logic cannot be expressed with patterns or simple string matching.
1557
- * >
1558
- * > **Rule advantages**: `ModuleSideEffectsRule[]` provides better performance by avoiding Rust-JavaScript runtime calls, clearer intent, and easier maintenance.
1559
- *
1560
- * @example
1561
- * ```js
1562
- * // Assume no modules have side effects (aggressive tree-shaking)
1563
- * treeshake: {
1564
- * moduleSideEffects: false
1565
- * }
1566
- *
1567
- * // Only specific modules have side effects (string array)
1568
- * treeshake: {
1569
- * moduleSideEffects: [
1570
- * 'lodash',
1571
- * 'react-dom',
1572
- * ]
1573
- * }
1574
- *
1575
- * // Use rules for pattern matching and granular control
1576
- * treeshake: {
1577
- * moduleSideEffects: [
1578
- * { test: /^node:/, sideEffects: true },
1579
- * { test: /\.css$/, sideEffects: true },
1580
- * { test: /some-package/, sideEffects: false, external: false },
1581
- * ]
1582
- * }
1583
- *
1584
- * // Custom function to determine side effects
1585
- * treeshake: {
1586
- * moduleSideEffects: (id, external) => {
1587
- * if (external) return false; // external modules have no side effects
1588
- * return id.includes('/side-effects/') || id.endsWith('.css');
1589
- * }
1590
- * }
1591
- *
1592
- * // Assume no external modules have side effects
1593
- * treeshake: {
1594
- * moduleSideEffects: 'no-external',
1595
- * }
1596
- * ```
1597
- *
1598
- * **Common Use Cases:**
1599
- * - **CSS files**: `{ test: /\.css$/, sideEffects: true }` - preserve CSS imports
1600
- * - **Polyfills**: Add specific polyfill modules to the array
1601
- * - **Plugins**: Modules that register themselves globally on import
1602
- * - **Library development**: Set to `false` for libraries where unused exports should be removed
1603
- *
1604
- * @default true
1605
- */
1606
- moduleSideEffects?: ModuleSideEffectsOption;
1607
- /**
1608
- * Whether to respect `/*@__PURE__*\/` annotations and other tree-shaking hints in the code.
1609
- *
1610
- * See [related Oxc documentation](https://oxc.rs/docs/guide/usage/minifier/dead-code-elimination#pure-annotations) for more details.
1611
- *
1612
- * @default true
1613
- */
1614
- annotations?: boolean;
1615
- /**
1616
- * Array of function names that should be considered pure (no side effects) even if they can't be automatically detected as pure.
1617
- *
1618
- * See [related Oxc documentation](https://oxc.rs/docs/guide/usage/minifier/dead-code-elimination#define-pure-functions) for more details.
1619
- *
1620
- * @example
1621
- * ```js
1622
- * treeshake: {
1623
- * manualPureFunctions: ['console.log', 'debug.trace']
1624
- * }
1625
- * ```
1626
- * @default []
1627
- */
1628
- manualPureFunctions?: readonly string[];
1629
- /**
1630
- * Whether to assume that accessing unknown global properties might have side effects.
1631
- *
1632
- * See [related Oxc documentation](https://oxc.rs/docs/guide/usage/minifier/dead-code-elimination#ignoring-global-variable-access-side-effects) for more details.
1633
- *
1634
- * @default true
1635
- */
1636
- unknownGlobalSideEffects?: boolean;
1637
- /**
1638
- * 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.
1639
- *
1640
- * This option allows rolldown to analyze `exports.property` assignments in CommonJS modules and remove unused exports while preserving the module's side effects.
1641
- *
1642
- * @example
1643
- * ```js
1644
- * // source.js (CommonJS)
1645
- * exports.used = 'This will be kept';
1646
- * exports.unused = 'This will be tree-shaken away';
1647
- *
1648
- * // main.js
1649
- * import { used } from './source.js';
1650
- * // With commonjs: true, only the 'used' export is included in the bundle
1651
- * // With commonjs: false, both exports are included
1652
- * ```
1653
- * @default true
1654
- */
1655
- commonjs?: boolean;
1656
- /**
1657
- * Controls whether reading properties from objects is considered to have side effects.
1658
- *
1659
- * Set to `false` for more aggressive tree-shaking behavior.
1660
- *
1661
- * See [related Oxc documentation](https://oxc.rs/docs/guide/usage/minifier/dead-code-elimination#ignoring-property-read-side-effects) for more details.
1662
- *
1663
- * @default 'always'
1664
- */
1665
- propertyReadSideEffects?: false | "always";
1666
- /**
1667
- * Controls whether writing properties to objects is considered to have side effects.
1668
- *
1669
- * Set to `false` for more aggressive behavior.
1670
- *
1671
- * @default 'always'
1672
- */
1673
- propertyWriteSideEffects?: false | "always";
1674
- };
1675
- //#endregion
1676
- //#region src/types/output-bundle.d.ts
1677
- /** @category Plugin APIs */
1678
- interface OutputBundle {
1679
- [fileName: string]: OutputAsset | OutputChunk;
1680
- }
1681
- //#endregion
1682
- //#region src/types/sourcemap.d.ts
1683
- /** @category Plugin APIs */
1684
- interface ExistingRawSourceMap {
1685
- file?: string | null;
1686
- mappings: string;
1687
- names?: string[];
1688
- sources?: (string | null)[];
1689
- sourcesContent?: (string | null)[];
1690
- sourceRoot?: string;
1691
- version?: number;
1692
- x_google_ignoreList?: number[];
1693
- }
1694
- type SourceMapInput = ExistingRawSourceMap | string | null;
1695
- //#endregion
1696
- //#region src/version.d.ts
1697
- /** @category Plugin APIs */
1698
- declare const VERSION: string;
1699
- //#endregion
1700
- //#region src/builtin-plugin/utils.d.ts
1701
- declare class BuiltinPlugin {
1702
- name: BindingBuiltinPluginName;
1703
- _options?: unknown;
1704
- /** Vite-specific option to control plugin ordering */
1705
- enforce?: "pre" | "post";
1706
- constructor(name: BindingBuiltinPluginName, _options?: unknown);
1707
- }
1708
- //#endregion
1709
- //#region src/constants/plugin.d.ts
1710
- declare const ENUMERATED_INPUT_PLUGIN_HOOK_NAMES: readonly ["options", "buildStart", "resolveId", "load", "transform", "moduleParsed", "buildEnd", "onLog", "resolveDynamicImport", "closeBundle", "closeWatcher", "watchChange"];
1711
- declare const ENUMERATED_OUTPUT_PLUGIN_HOOK_NAMES: readonly ["augmentChunkHash", "outputOptions", "renderChunk", "renderStart", "renderError", "writeBundle", "generateBundle"];
1712
- declare const ENUMERATED_PLUGIN_HOOK_NAMES: [...typeof ENUMERATED_INPUT_PLUGIN_HOOK_NAMES, ...typeof ENUMERATED_OUTPUT_PLUGIN_HOOK_NAMES, "footer", "banner", "intro", "outro"];
1713
- /**
1714
- * Names of all defined hooks. It's like
1715
- * ```ts
1716
- * type DefinedHookNames = {
1717
- * options: 'options',
1718
- * buildStart: 'buildStart',
1719
- * ...
1720
- * }
1721
- * ```
1722
- */
1723
- type DefinedHookNames = { readonly [K in (typeof ENUMERATED_PLUGIN_HOOK_NAMES)[number]]: K };
1724
- /**
1725
- * Names of all defined hooks. It's like
1726
- * ```js
1727
- * const DEFINED_HOOK_NAMES ={
1728
- * options: 'options',
1729
- * buildStart: 'buildStart',
1730
- * ...
1731
- * }
1732
- * ```
1733
- */
1734
- declare const DEFINED_HOOK_NAMES: DefinedHookNames;
1735
- //#endregion
1736
- //#region src/plugin/with-filter.d.ts
1737
- type OverrideFilterObject = {
1738
- transform?: HookFilterExtension<"transform">["filter"];
1739
- resolveId?: HookFilterExtension<"resolveId">["filter"];
1740
- load?: HookFilterExtension<"load">["filter"];
1741
- pluginNamePattern?: StringOrRegExp[];
1742
- };
1743
- declare function withFilter<A, T extends RolldownPluginOption<A>>(pluginOption: T, filterObject: OverrideFilterObject | OverrideFilterObject[]): T;
1744
- //#endregion
1745
- //#region src/plugin/index.d.ts
1746
- type ModuleSideEffects = boolean | "no-treeshake" | null;
1747
- /** @category Plugin APIs */
1748
- type ModuleType = "js" | "jsx" | "ts" | "tsx" | "json" | "text" | "base64" | "dataurl" | "binary" | "empty" | (string & {});
1749
- /** @category Plugin APIs */
1750
- type ImportKind = BindingHookResolveIdExtraArgs["kind"];
1751
- /** @category Plugin APIs */
1752
- interface CustomPluginOptions {
1753
- [plugin: string]: any;
1754
- }
1755
- /** @category Plugin APIs */
1756
- interface ModuleOptions {
1757
- moduleSideEffects: ModuleSideEffects;
1758
- meta: CustomPluginOptions;
1759
- invalidate?: boolean;
1760
- packageJsonPath?: string;
1761
- }
1762
- /** @category Plugin APIs */
1763
- interface ResolvedId extends ModuleOptions {
1764
- external: boolean | "absolute";
1765
- id: string;
1766
- }
1767
- /** @category Plugin APIs */
1768
- interface PartialResolvedId extends Partial<PartialNull<ModuleOptions>> {
1769
- external?: boolean | "absolute" | "relative";
1770
- id: string;
1771
- }
1772
- /** @category Plugin APIs */
1773
- interface SourceDescription extends Partial<PartialNull<ModuleOptions>> {
1774
- code: string;
1775
- map?: SourceMapInput;
1776
- moduleType?: ModuleType;
1777
- }
1778
- /** @category Plugin APIs */
1779
- interface ResolveIdExtraOptions {
1780
- custom?: CustomPluginOptions;
1781
- isEntry: boolean;
1782
- kind: BindingHookResolveIdExtraArgs["kind"];
1783
- }
1784
- /** @category Plugin APIs */
1785
- type ResolveIdResult = string | NullValue | false | PartialResolvedId;
1786
- /** @category Plugin APIs */
1787
- type LoadResult = NullValue | string | SourceDescription;
1788
- /** @category Plugin APIs */
1789
- type TransformResult = NullValue | string | (Omit<SourceDescription, "code"> & {
1790
- code?: string | BindingMagicString;
1791
- });
1792
- type RenderedChunkMeta = {
1793
- chunks: Record<string, RenderedChunk>;
1794
- };
1795
- /** @category Plugin APIs */
1796
- interface FunctionPluginHooks {
1797
- [DEFINED_HOOK_NAMES.onLog]: (this: MinimalPluginContext, level: LogLevel, log: RollupLog) => NullValue | boolean;
1798
- [DEFINED_HOOK_NAMES.options]: (this: MinimalPluginContext, options: InputOptions) => NullValue | InputOptions;
1799
- [DEFINED_HOOK_NAMES.outputOptions]: (this: MinimalPluginContext, options: OutputOptions) => NullValue | OutputOptions;
1800
- [DEFINED_HOOK_NAMES.buildStart]: (this: PluginContext, options: NormalizedInputOptions) => void;
1801
- [DEFINED_HOOK_NAMES.resolveId]: (this: PluginContext, source: string, importer: string | undefined, extraOptions: ResolveIdExtraOptions) => ResolveIdResult;
1802
- /**
1803
- * @deprecated
1804
- * This hook is only for rollup plugin compatibility. Please use `resolveId` instead.
1805
- */
1806
- [DEFINED_HOOK_NAMES.resolveDynamicImport]: (this: PluginContext, source: string, importer: string | undefined) => ResolveIdResult;
1807
- [DEFINED_HOOK_NAMES.load]: (this: PluginContext, id: string) => MaybePromise<LoadResult>;
1808
- [DEFINED_HOOK_NAMES.transform]: (this: TransformPluginContext, code: string, id: string, meta: BindingTransformHookExtraArgs & {
1809
- moduleType: ModuleType;
1810
- magicString?: BindingMagicString;
1811
- ast?: Program;
1812
- }) => TransformResult;
1813
- [DEFINED_HOOK_NAMES.moduleParsed]: (this: PluginContext, moduleInfo: ModuleInfo) => void;
1814
- [DEFINED_HOOK_NAMES.buildEnd]: (this: PluginContext, err?: Error) => void;
1815
- [DEFINED_HOOK_NAMES.renderStart]: (this: PluginContext, outputOptions: NormalizedOutputOptions, inputOptions: NormalizedInputOptions) => void;
1816
- [DEFINED_HOOK_NAMES.renderChunk]: (this: PluginContext, code: string, chunk: RenderedChunk, outputOptions: NormalizedOutputOptions, meta: RenderedChunkMeta) => NullValue | string | {
1817
- code: string;
1818
- map?: SourceMapInput;
1819
- };
1820
- [DEFINED_HOOK_NAMES.augmentChunkHash]: (this: PluginContext, chunk: RenderedChunk) => string | void;
1821
- [DEFINED_HOOK_NAMES.renderError]: (this: PluginContext, error: Error) => void;
1822
- [DEFINED_HOOK_NAMES.generateBundle]: (this: PluginContext, outputOptions: NormalizedOutputOptions, bundle: OutputBundle, isWrite: boolean) => void;
1823
- [DEFINED_HOOK_NAMES.writeBundle]: (this: PluginContext, outputOptions: NormalizedOutputOptions, bundle: OutputBundle) => void;
1824
- [DEFINED_HOOK_NAMES.closeBundle]: (this: PluginContext, error?: Error) => void;
1825
- [DEFINED_HOOK_NAMES.watchChange]: (this: PluginContext, id: string, event: {
1826
- event: ChangeEvent;
1827
- }) => void;
1828
- [DEFINED_HOOK_NAMES.closeWatcher]: (this: PluginContext) => void;
1829
- }
1830
- type ChangeEvent = "create" | "update" | "delete";
1831
- type PluginOrder = "pre" | "post" | null;
1832
- type ObjectHookMeta = {
1833
- order?: PluginOrder;
1834
- };
1835
- /** @category Plugin APIs */
1836
- type ObjectHook<T, O = {}> = T | ({
1837
- handler: T;
1838
- } & ObjectHookMeta & O);
1839
- type SyncPluginHooks = DefinedHookNames["augmentChunkHash" | "onLog" | "outputOptions"];
1840
- /** @category Plugin APIs */
1841
- type AsyncPluginHooks = Exclude<keyof FunctionPluginHooks, SyncPluginHooks>;
1842
- type FirstPluginHooks = DefinedHookNames["load" | "resolveDynamicImport" | "resolveId"];
1843
- type SequentialPluginHooks = DefinedHookNames["augmentChunkHash" | "generateBundle" | "onLog" | "options" | "outputOptions" | "renderChunk" | "transform"];
1844
- type AddonHooks = DefinedHookNames["banner" | "footer" | "intro" | "outro"];
1845
- type OutputPluginHooks = DefinedHookNames["augmentChunkHash" | "generateBundle" | "outputOptions" | "renderChunk" | "renderError" | "renderStart" | "writeBundle"];
1846
- /** @internal */
1847
- type ParallelPluginHooks = Exclude<keyof FunctionPluginHooks | AddonHooks, FirstPluginHooks | SequentialPluginHooks>;
1848
- /** @category Plugin APIs */
1849
- type HookFilterExtension<K extends keyof FunctionPluginHooks> = K extends "transform" ? {
1850
- filter?: TUnionWithTopLevelFilterExpressionArray<HookFilter>;
1851
- } : K extends "load" ? {
1852
- filter?: TUnionWithTopLevelFilterExpressionArray<Pick<HookFilter, "id">>;
1853
- } : K extends "resolveId" ? {
1854
- filter?: TUnionWithTopLevelFilterExpressionArray<{
1855
- id?: GeneralHookFilter<RegExp>;
1856
- }>;
1857
- } : K extends "renderChunk" ? {
1858
- filter?: TUnionWithTopLevelFilterExpressionArray<Pick<HookFilter, "code">>;
1859
- } : {};
1860
- type PluginHooks = { [K in keyof FunctionPluginHooks]: ObjectHook<K extends AsyncPluginHooks ? MakeAsync<FunctionPluginHooks[K]> : FunctionPluginHooks[K], HookFilterExtension<K> & (K extends ParallelPluginHooks ? {
1861
- /**
1862
- * @deprecated
1863
- * this is only for rollup Plugin type compatibility.
1864
- * hooks always work as `sequential: true`.
1865
- */
1866
- sequential?: boolean;
1867
- } : {})> };
1868
- type AddonHookFunction = (this: PluginContext, chunk: RenderedChunk) => string | Promise<string>;
1869
- type AddonHook = string | AddonHookFunction;
1870
- interface OutputPlugin extends Partial<{ [K in keyof PluginHooks as K & OutputPluginHooks]: PluginHooks[K] }>, Partial<{ [K in AddonHooks]: ObjectHook<AddonHook> }> {
1871
- name: string;
1872
- }
1873
- /** @category Plugin APIs */
1874
- interface Plugin<A = any> extends OutputPlugin, Partial<PluginHooks> {
1875
- api?: A;
1876
- }
1877
- type RolldownPlugin<A = any> = Plugin<A> | BuiltinPlugin | ParallelPlugin;
1878
- type RolldownPluginOption<A = any> = MaybePromise<NullValue<RolldownPlugin<A>> | {
1879
- name: string;
1880
- } | false | RolldownPluginOption[]>;
1881
- type RolldownOutputPlugin = OutputPlugin | BuiltinPlugin;
1882
- type RolldownOutputPluginOption = MaybePromise<NullValue<RolldownOutputPlugin> | {
1883
- name: string;
1884
- } | false | RolldownOutputPluginOption[]>;
1885
- //#endregion
1886
- //#region src/options/input-options.d.ts
1887
- /**
1888
- * @inline
1889
- */
1890
- type InputOption = string | string[] | Record<string, string>;
1891
- /**
1892
- * @param id The id of the module being checked.
1893
- * @param parentId The id of the module importing the id being checked.
1894
- * @param isResolved Whether the id has been resolved.
1895
- * @returns Whether the module should be treated as external.
1896
- */
1897
- type ExternalOptionFunction = (id: string, parentId: string | undefined, isResolved: boolean) => NullValue<boolean>;
1898
- /** @inline */
1899
- type ExternalOption = StringOrRegExp | StringOrRegExp[] | ExternalOptionFunction;
1900
- type ModuleTypes = Record<string, "js" | "jsx" | "ts" | "tsx" | "json" | "text" | "base64" | "dataurl" | "binary" | "empty" | "css" | "asset">;
1901
- interface WatcherOptions {
1902
- /**
1903
- * Whether to skip the `bundle.write()` step when a rebuild is triggered.
1904
- * @default false
1905
- */
1906
- skipWrite?: boolean;
1907
- /**
1908
- * Configures how long Rolldown will wait for further changes until it triggers
1909
- * a rebuild in milliseconds.
1910
- *
1911
- * Even if this value is set to 0, there's a small debounce timeout configured
1912
- * in the file system watcher. Setting this to a value greater than 0 will mean
1913
- * that Rolldown will only trigger a rebuild if there was no change for the
1914
- * configured number of milliseconds. If several configurations are watched,
1915
- * Rolldown will use the largest configured build delay.
1916
- *
1917
- * @default 0
1918
- */
1919
- buildDelay?: number;
1920
- /**
1921
- * An optional object of options that will be passed to the [notify](https://github.com/rolldown/notify) file watcher.
1922
- */
1923
- notify?: {
1924
- /**
1925
- * Interval between each re-scan attempt in milliseconds.
1926
- *
1927
- * This option is only used when polling backend is used.
1928
- *
1929
- * @default 30_000
1930
- */
1931
- pollInterval?: number;
1932
- /**
1933
- * Whether to compare file contents when checking for changes.
1934
- *
1935
- * This is especially important for pseudo filesystems like those on Linux
1936
- * under `/sys` and `/proc` which are not obligated to respect any other
1937
- * filesystem norms such as modification timestamps, file sizes, etc. By
1938
- * enabling this feature, performance will be significantly impacted as
1939
- * all files will need to be read and hashed at each interval.
1940
- *
1941
- * This option is only used when polling backend is used.
1942
- *
1943
- * @default false
1944
- */
1945
- compareContents?: boolean;
1946
- };
1947
- /**
1948
- * Filter to limit the file-watching to certain files.
1949
- *
1950
- * Strings are treated as glob patterns.
1951
- * Note that this only filters the module graph but does not allow adding
1952
- * additional watch files.
1953
- *
1954
- * @example
1955
- * ```js
1956
- * export default defineConfig({
1957
- * watch: {
1958
- * include: 'src/**',
1959
- * },
1960
- * })
1961
- * ```
1962
- * @default []
1963
- */
1964
- include?: StringOrRegExp | StringOrRegExp[];
1965
- /**
1966
- * Filter to prevent files from being watched.
1967
- *
1968
- * Strings are treated as glob patterns.
1969
- *
1970
- * @example
1971
- * ```js
1972
- * export default defineConfig({
1973
- * watch: {
1974
- * exclude: 'node_modules/**',
1975
- * },
1976
- * })
1977
- * ```
1978
- * @default []
1979
- */
1980
- exclude?: StringOrRegExp | StringOrRegExp[];
1981
- /**
1982
- * An optional function that will be called immediately every time
1983
- * a module changes that is part of the build.
1984
- *
1985
- * This is different from the `watchChange` plugin hook, which is
1986
- * only called once the running build has finished. This may for
1987
- * instance be used to prevent additional steps from being performed
1988
- * if we know another build will be started anyway once the current
1989
- * build finished. This callback may be called multiple times per
1990
- * build as it tracks every change.
1991
- *
1992
- * @param id The id of the changed module.
1993
- */
1994
- onInvalidate?: (id: string) => void;
1995
- /**
1996
- * Whether to clear the screen when a rebuild is triggered.
1997
- * @default true
1998
- */
1999
- clearScreen?: boolean;
2000
- }
2001
- /** @inline */
2002
- type MakeAbsoluteExternalsRelative = boolean | "ifRelativeSource";
2003
- type DevModeOptions = boolean | {
2004
- host?: string;
2005
- port?: number;
2006
- implement?: string;
2007
- lazy?: boolean;
2008
- };
2009
- type OptimizationOptions = {
2010
- /**
2011
- * Inline imported constant values during bundling instead of preserving variable references.
2012
- *
2013
- * When enabled, constant values from imported modules will be inlined at their usage sites,
2014
- * potentially reducing bundle size and improving runtime performance by eliminating variable lookups.
2015
- *
2016
- * **Options:**
2017
- * - `true`: equivalent to `{ mode: 'all', pass: 1 }`, enabling constant inlining for all eligible constants with a single pass.
2018
- * - `false`: Disable constant inlining
2019
- * - `{ mode: 'smart' | 'all', pass?: number }`:
2020
- * - `mode: 'smart'`: Only inline constants in specific scenarios where it is likely to reduce bundle size and improve performance.
2021
- * Smart mode inlines constants in these specific scenarios:
2022
- * 1. `if (test) {} else {}` - condition expressions in if statements
2023
- * 2. `test ? a : b` - condition expressions in ternary operators
2024
- * 3. `test1 || test2` - logical OR expressions
2025
- * 4. `test1 && test2` - logical AND expressions
2026
- * 5. `test1 ?? test2` - nullish coalescing expressions
2027
- * - `mode: 'all'`: Inline all imported constants wherever they are used.
2028
- * - `pass`: Number of passes to perform for inlining constants.
2029
- *
2030
- * @example
2031
- * ```js
2032
- * // Input files:
2033
- * // constants.js
2034
- * export const API_URL = 'https://api.example.com';
2035
- *
2036
- * // main.js
2037
- * import { API_URL } from './constants.js';
2038
- * console.log(API_URL);
2039
- *
2040
- * // With inlineConst: true, the bundled output becomes:
2041
- * console.log('https://api.example.com');
2042
- *
2043
- * // Instead of:
2044
- * const API_URL = 'https://api.example.com';
2045
- * console.log(API_URL);
2046
- * ```
2047
- *
2048
- * @default false
2049
- */
2050
- inlineConst?: boolean | {
2051
- mode?: "all" | "smart";
2052
- pass?: number;
2053
- };
2054
- /**
2055
- * Use PIFE pattern for module wrappers.
2056
- *
2057
- * Enabling this option improves the start up performance of the generated bundle with the cost of a slight increase in bundle size.
2058
- *
2059
- * {@include ./docs/optimization-pife-for-module-wrappers.md}
2060
- *
2061
- * @default true
2062
- */
2063
- pifeForModuleWrappers?: boolean;
2064
- };
2065
- /** @inline */
2066
- type AttachDebugOptions = "none" | "simple" | "full";
2067
- /** @inline */
2068
- type ChunkModulesOrder = "exec-order" | "module-id";
2069
- /** @inline */
2070
- type OnLogFunction = (level: LogLevel, log: RollupLog, defaultHandler: LogOrStringHandler) => void;
2071
- /** @inline */
2072
- type OnwarnFunction = (warning: RollupLog, defaultHandler: (warning: RollupLogWithString | (() => RollupLogWithString)) => void) => void;
2073
- interface InputOptions {
2074
- /**
2075
- * Defines entries and location(s) of entry modules for the bundle. Relative paths are resolved based on the {@linkcode cwd} option.
2076
- * {@include ./docs/input.md}
2077
- */
2078
- input?: InputOption;
2079
- /**
2080
- * The list of plugins to use.
2081
- *
2082
- * 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.
2083
- */
2084
- plugins?: RolldownPluginOption;
2085
- /**
2086
- * Specifies which modules should be treated as external and not bundled. External modules will be left as import statements in the output.
2087
- * {@include ./docs/external.md}
2088
- */
2089
- external?: ExternalOption;
2090
- /**
2091
- * Options for built-in module resolution feature.
2092
- */
2093
- resolve?: {
2094
- /**
2095
- * Substitute one package for another.
2096
- *
2097
- * 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.
2098
- *
2099
- * @example
2100
- * ```js
2101
- * resolve: {
2102
- * alias: {
2103
- * '@': '/src',
2104
- * 'utils': './src/utils',
2105
- * }
2106
- * }
2107
- * ```
2108
- * > [!WARNING]
2109
- * > `resolve.alias` will not call `resolveId` hooks of other plugin.
2110
- * > If you want to call `resolveId` hooks of other plugin, use `viteAliasPlugin` from `rolldown/experimental` instead.
2111
- * > You could find more discussion in [this issue](https://github.com/rolldown/rolldown/issues/3615)
2112
- */
2113
- alias?: Record<string, string[] | string | false>;
2114
- /**
2115
- * Fields in package.json to check for aliased paths.
2116
- *
2117
- * This option is expected to be used for `browser` field support.
2118
- *
2119
- * @default
2120
- * - `[['browser']]` for `browser` platform
2121
- * - `[]` for other platforms
2122
- */
2123
- aliasFields?: string[][];
2124
- /**
2125
- * Condition names to use when resolving exports in package.json.
2126
- *
2127
- * @default
2128
- * Defaults based on platform and import kind:
2129
- * - `browser` platform
2130
- * - `["import", "browser", "default"]` for import statements
2131
- * - `["require", "browser", "default"]` for require() calls
2132
- * - `node` platform
2133
- * - `["import", "node", "default"]` for import statements
2134
- * - `["require", "node", "default"]` for require() calls
2135
- * - `neutral` platform
2136
- * - `["import", "default"]` for import statements
2137
- * - `["require", "default"]` for require() calls
2138
- */
2139
- conditionNames?: string[];
2140
- /**
2141
- * Map of extensions to alternative extensions.
2142
- *
2143
- * With writing `import './foo.js'` in a file, you want to resolve it to `foo.ts` instead of `foo.js`.
2144
- * You can achieve this by setting: `extensionAlias: { '.js': ['.ts', '.js'] }`.
2145
- */
2146
- extensionAlias?: Record<string, string[]>;
2147
- /**
2148
- * Fields in package.json to check for exports.
2149
- *
2150
- * @default `[['exports']]`
2151
- */
2152
- exportsFields?: string[][];
2153
- /**
2154
- * Extensions to try when resolving files. These are tried in order from first to last.
2155
- *
2156
- * @default `['.tsx', '.ts', '.jsx', '.js', '.json']`
2157
- */
2158
- extensions?: string[];
2159
- /**
2160
- * Fields in package.json to check for entry points.
2161
- *
2162
- * @default
2163
- * Defaults based on platform:
2164
- * - `node` platform: `['main', 'module']`
2165
- * - `browser` platform: `['browser', 'module', 'main']`
2166
- * - `neutral` platform: `[]`
2167
- */
2168
- mainFields?: string[];
2169
- /**
2170
- * Filenames to try when resolving directories.
2171
- * @default ['index']
2172
- */
2173
- mainFiles?: string[];
2174
- /**
2175
- * Directories to search for modules.
2176
- * @default ['node_modules']
2177
- */
2178
- modules?: string[];
2179
- /**
2180
- * Whether to follow symlinks when resolving modules.
2181
- * @default true
2182
- */
2183
- symlinks?: boolean;
2184
- /**
2185
- * @deprecated Use the top-level {@linkcode tsconfig} option instead.
2186
- */
2187
- tsconfigFilename?: string;
2188
- };
2189
- /**
2190
- * The working directory to use when resolving relative paths in the configuration.
2191
- * @default process.cwd()
2192
- */
2193
- cwd?: string;
2194
- /**
2195
- * Expected platform where the code run.
2196
- *
2197
- * When the platform is set to neutral:
2198
- * - 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.
2199
- * - 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.
2200
- * - The conditions setting does not automatically include any platform-specific values.
2201
- *
2202
- * @default
2203
- * - `'node'` if the format is `'cjs'`
2204
- * - `'browser'` for other formats
2205
- * {@include ./docs/platform.md}
2206
- */
2207
- platform?: "node" | "browser" | "neutral";
2208
- /**
2209
- * When `true`, creates shim variables for missing exports instead of throwing an error.
2210
- * @default false
2211
- * {@include ./docs/shim-missing-exports.md}
2212
- */
2213
- shimMissingExports?: boolean;
2214
- /**
2215
- * Controls tree-shaking (dead code elimination).
2216
- *
2217
- * When `false`, tree-shaking will be disabled.
2218
- * When `true`, it is equivalent to setting each options to the default value.
2219
- *
2220
- * @default true
2221
- */
2222
- treeshake?: boolean | TreeshakingOptions;
2223
- /**
2224
- * Controls the verbosity of console logging during the build.
2225
- *
2226
- * {@include ./docs/log-level.md}
2227
- *
2228
- * @default 'info'
2229
- */
2230
- logLevel?: LogLevelOption;
2231
- /**
2232
- * A function that intercepts log messages. If not supplied, logs are printed to the console.
2233
- *
2234
- * {@include ./docs/on-log.md}
2235
- *
2236
- * @example
2237
- * ```js
2238
- * export default defineConfig({
2239
- * onLog(level, log, defaultHandler) {
2240
- * if (log.code === 'CIRCULAR_DEPENDENCY') {
2241
- * return; // Ignore circular dependency warnings
2242
- * }
2243
- * if (level === 'warn') {
2244
- * defaultHandler('error', log); // turn other warnings into errors
2245
- * } else {
2246
- * defaultHandler(level, log); // otherwise, just print the log
2247
- * }
2248
- * }
2249
- * })
2250
- * ```
2251
- */
2252
- onLog?: OnLogFunction;
2253
- /**
2254
- * A function that will intercept warning messages.
2255
- *
2256
- * {@include ./docs/on-warn.md}
2257
- *
2258
- * @deprecated
2259
- * This is a legacy API. Consider using {@linkcode onLog} instead for better control over all log types.
2260
- *
2261
- * {@include ./docs/on-warn-deprecation.md}
2262
- */
2263
- onwarn?: OnwarnFunction;
2264
- /**
2265
- * Maps file patterns to module types, controlling how files are processed.
2266
- *
2267
- * This is conceptually similar to esbuild's loader option, allowing you to specify how different file extensions should be handled.
2268
- */
2269
- moduleTypes?: ModuleTypes;
2270
- /**
2271
- * Experimental features that may change in future releases and can introduce behavior change without a major version bump.
2272
- * @experimental
2273
- */
2274
- experimental?: {
2275
- /**
2276
- * Lets modules be executed in the order they are declared.
2277
- *
2278
- * This is done by injecting runtime helpers to ensure that modules are executed in the order they are imported. External modules won't be affected.
2279
- *
2280
- * > [!WARNING]
2281
- * > Enabling this option may negatively increase bundle size. It is recommended to use this option only when absolutely necessary.
2282
- * @default false
2283
- */
2284
- strictExecutionOrder?: boolean;
2285
- /**
2286
- * Enable Vite compatible mode.
2287
- * @default false
2288
- * @hidden This option is only meant to be used by Vite. It is not recommended to use this option directly.
2289
- */
2290
- viteMode?: boolean;
2291
- /**
2292
- * When enabled, `new URL()` calls will be transformed to a stable asset URL which includes the updated name and content hash.
2293
- * It is necessary to pass `import.meta.url` as the second argument to the
2294
- * `new URL` constructor, otherwise no transform will be applied.
2295
- * :::warning
2296
- * 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.
2297
- *
2298
- * The expected behavior for JS/TS files is still being discussed and may
2299
- * change in future releases. See [#7258](https://github.com/rolldown/rolldown/issues/7258) for more context.
2300
- * :::
2301
- * @example
2302
- * ```js
2303
- * // main.js
2304
- * const url = new URL('./styles.css', import.meta.url);
2305
- * console.log(url);
2306
- *
2307
- * // Example output after bundling WITHOUT the option (default)
2308
- * const url = new URL('./styles.css', import.meta.url);
2309
- * console.log(url);
2310
- *
2311
- * // Example output after bundling WITH `experimental.resolveNewUrlToAsset` set to `true`
2312
- * const url = new URL('assets/styles-CjdrdY7X.css', import.meta.url);
2313
- * console.log(url);
2314
- * ```
2315
- * @default false
2316
- */
2317
- resolveNewUrlToAsset?: boolean;
2318
- /**
2319
- * Dev mode related options.
2320
- * @hidden not ready for public usage yet
2321
- */
2322
- devMode?: DevModeOptions;
2323
- /**
2324
- * Control which order should be used when rendering modules in a chunk.
2325
- *
2326
- * Available options:
2327
- * - `exec-order`: Almost equivalent to the topological order of the module graph, but specially handling when module graph has cycle.
2328
- * - `module-id`: This is more friendly for gzip compression, especially for some javascript static asset lib (e.g. icon library)
2329
- *
2330
- * > [!NOTE]
2331
- * > 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).
2332
- *
2333
- * @default 'exec-order'
2334
- */
2335
- chunkModulesOrder?: ChunkModulesOrder;
2336
- /**
2337
- * Attach debug information to the output bundle.
2338
- *
2339
- * Available modes:
2340
- * - `none`: No debug information is attached.
2341
- * - `simple`: Attach comments indicating which files the bundled code comes from. These comments could be removed by the minifier.
2342
- * - `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.
2343
- *
2344
- * @default 'simple'
2345
- */
2346
- attachDebugInfo?: AttachDebugOptions;
2347
- /**
2348
- * Enables automatic generation of a chunk import map asset during build.
2349
- *
2350
- * This map only includes chunks with hashed filenames, where keys are derived from the facade module
2351
- * name or primary chunk name. It produces stable and unique hash-based filenames, effectively preventing
2352
- * cascading cache invalidation caused by content hashes and maximizing browser cache reuse.
2353
- *
2354
- * The output defaults to `importmap.json` unless overridden via `fileName`. A base URL prefix
2355
- * (default `"/"`) can be applied to all paths. The resulting JSON is a valid import map and can be
2356
- * directly injected into HTML via `<script type="importmap">`.
2357
- *
2358
- * @example
2359
- * ```js
2360
- * {
2361
- * experimental: {
2362
- * chunkImportMap: {
2363
- * baseUrl: '/',
2364
- * fileName: 'importmap.json'
2365
- * }
2366
- * },
2367
- * plugins: [
2368
- * {
2369
- * name: 'inject-import-map',
2370
- * generateBundle(_, bundle) {
2371
- * const chunkImportMap = bundle['importmap.json'];
2372
- * if (chunkImportMap?.type === 'asset') {
2373
- * const htmlPath = path.resolve('index.html');
2374
- * let html = fs.readFileSync(htmlPath, 'utf-8');
2375
- *
2376
- * html = html.replace(
2377
- * /<script\s+type="importmap"[^>]*>[\s\S]*?<\/script>/i,
2378
- * `<script type="importmap">${chunkImportMap.source}<\/script>`
2379
- * );
2380
- *
2381
- * fs.writeFileSync(htmlPath, html);
2382
- * delete bundle['importmap.json'];
2383
- * }
2384
- * }
2385
- * }
2386
- * ]
2387
- * }
2388
- * ```
2389
- *
2390
- * > [!TIP]
2391
- * > 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)
2392
- *
2393
- * @default false
2394
- */
2395
- chunkImportMap?: boolean | {
2396
- baseUrl?: string;
2397
- fileName?: string;
2398
- };
2399
- /**
2400
- * Enable on-demand wrapping of modules.
2401
- * @default false
2402
- * @hidden not ready for public usage yet
2403
- */
2404
- onDemandWrapping?: boolean;
2405
- /**
2406
- * Enable incremental build support. Required to be used with `watch` mode.
2407
- * @default false
2408
- */
2409
- incrementalBuild?: boolean;
2410
- /**
2411
- * Enable high-resolution source maps for transform operations.
2412
- * @default false
2413
- */
2414
- transformHiresSourcemap?: boolean | "boundary";
2415
- /**
2416
- * Use native Rust implementation of MagicString for source map generation.
2417
- *
2418
- * [MagicString](https://github.com/rich-harris/magic-string) is a JavaScript library commonly used by bundlers
2419
- * for string manipulation and source map generation. When enabled, rolldown will use a native Rust
2420
- * implementation of MagicString instead of the JavaScript version, providing significantly better performance
2421
- * during source map generation and code transformation.
2422
- *
2423
- * **Benefits**
2424
- *
2425
- * - **Improved Performance**: The native Rust implementation is typically faster than the JavaScript version,
2426
- * especially for large codebases with extensive source maps.
2427
- * - **Background Processing**: Source map generation is performed asynchronously in a background thread,
2428
- * allowing the main bundling process to continue without blocking. This parallel processing can significantly
2429
- * reduce overall build times when working with JavaScript transform hooks.
2430
- * - **Better Integration**: Seamless integration with rolldown's native Rust architecture.
2431
- *
2432
- * @example
2433
- * ```js
2434
- * export default {
2435
- * experimental: {
2436
- * nativeMagicString: true
2437
- * },
2438
- * output: {
2439
- * sourcemap: true
2440
- * }
2441
- * }
2442
- * ```
2443
- *
2444
- * > [!NOTE]
2445
- * > This is an experimental feature. While it aims to provide identical behavior to the JavaScript
2446
- * > implementation, there may be edge cases. Please report any discrepancies you encounter.
2447
- * > For a complete working example, see [examples/native-magic-string](https://github.com/rolldown/rolldown/tree/main/examples/native-magic-string)
2448
- * @default false
2449
- */
2450
- nativeMagicString?: boolean;
2451
- /**
2452
- * Control whether to optimize chunks by allowing entry chunks to have different exports than the underlying entry module.
2453
- * This optimization can reduce the number of generated chunks.
2454
- *
2455
- * When enabled, rolldown will try to insert common modules directly into existing chunks rather than creating
2456
- * separate chunks for them, which can result in fewer output files and better performance.
2457
- *
2458
- * This optimization is automatically disabled when any module uses top-level await (TLA) or contains TLA dependencies,
2459
- * as it could affect execution order guarantees.
2460
- *
2461
- * @default true
2462
- */
2463
- chunkOptimization?: boolean;
2464
- };
2465
- /**
2466
- * Configure how the code is transformed. This process happens after the `transform` hook.
2467
- *
2468
- * @example
2469
- * **Enable legacy decorators**
2470
- * ```js
2471
- * export default defineConfig({
2472
- * transform: {
2473
- * decorator: {
2474
- * legacy: true,
2475
- * },
2476
- * },
2477
- * })
2478
- * ```
2479
- * Note that if you have correct `tsconfig.json` file, Rolldown will automatically detect and enable legacy decorators support.
2480
- *
2481
- * {@include ./docs/transform.md}
2482
- */
2483
- transform?: TransformOptions;
2484
- /**
2485
- * Watch mode related options.
2486
- *
2487
- * These options only take effect when running with the `--watch` flag, or using `rolldown.watch()` API.
2488
- */
2489
- watch?: WatcherOptions | false;
2490
- /**
2491
- * Controls which warnings are emitted during the build process. Each option can be set to `true` (emit warning) or `false` (suppress warning).
2492
- */
2493
- checks?: ChecksOptions;
2494
- /**
2495
- * Determines if absolute external paths should be converted to relative paths in the output.
2496
- *
2497
- * 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.
2498
- *
2499
- * {@include ./docs/make-absolute-externals-relative.md}
2500
- */
2501
- makeAbsoluteExternalsRelative?: MakeAbsoluteExternalsRelative;
2502
- /**
2503
- * Devtools integration options.
2504
- * @experimental
2505
- */
2506
- devtools?: {
2507
- sessionId?: string;
2508
- };
2509
- /**
2510
- * Controls how entry chunk exports are preserved.
2511
- *
2512
- * 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.
2513
- *
2514
- * @default `'exports-only'`
2515
- * {@include ./docs/preserve-entry-signatures.md}
2516
- */
2517
- preserveEntrySignatures?: false | "strict" | "allow-extension" | "exports-only";
2518
- /**
2519
- * Configure optimization features for the bundler.
2520
- */
2521
- optimization?: OptimizationOptions;
2522
- /**
2523
- * The value of `this` at the top level of each module. **Normally, you don't need to set this option.**
2524
- * @default undefined
2525
- * @example
2526
- * **Set custom context**
2527
- * ```js
2528
- * export default {
2529
- * context: 'globalThis',
2530
- * output: {
2531
- * format: 'iife',
2532
- * },
2533
- * };
2534
- * ```
2535
- * {@include ./docs/context.md}
2536
- */
2537
- context?: string;
2538
- /**
2539
- * Configures TypeScript configuration file resolution and usage.
2540
- * {@include ./docs/tsconfig.md}
2541
- * @default true
2542
- */
2543
- tsconfig?: boolean | string;
2544
- }
2545
- //#endregion
2546
- //#region src/types/rolldown-options.d.ts
2547
- interface RolldownOptions extends InputOptions {
2548
- output?: OutputOptions | OutputOptions[];
2549
- }
2550
- //#endregion
2551
- //#region src/utils/define-config.d.ts
2552
- /**
2553
- * Type for `default export` of `rolldown.config.js` file.
2554
- */
2555
- type ConfigExport = RolldownOptions | RolldownOptions[] | RolldownOptionsFunction;
2556
- type RolldownOptionsFunction = (commandLineArguments: Record<string, any>) => MaybePromise<RolldownOptions | RolldownOptions[]>;
2557
- declare function defineConfig(config: RolldownOptions): RolldownOptions;
2558
- declare function defineConfig(config: RolldownOptions[]): RolldownOptions[];
2559
- declare function defineConfig(config: RolldownOptionsFunction): RolldownOptionsFunction;
2560
- declare function defineConfig(config: ConfigExport): ConfigExport;
2561
- //#endregion
2562
- export { RolldownFileStats as $, TransformResult as A, StringOrRegExp as At, EmittedFile as B, Plugin as C, GlobalsFunction as Ct, RolldownPlugin as D, PreRenderedAsset as Dt, ResolvedId as E, OutputOptions as Et, SourceMapInput as F, RolldownOutput as Ft, defineParallelPlugin as G, GetModuleInfo as H, OutputBundle as I, SourceMap as It, GeneralHookFilter as J, MinimalPluginContext as K, TreeshakingOptions as L, freeExternalMemory as Lt, BuiltinPlugin as M, OutputChunk as Mt, VERSION as N, RenderedChunk as Nt, RolldownPluginOption as O, MaybePromise as Ot, ExistingRawSourceMap as P, RenderedModule as Pt, RolldownDirectoryEntry as Q, TransformPluginContext as R, ModuleInfo as Rt, PartialResolvedId as S, GeneratedCodePreset as St, ResolveIdResult as T, ModuleFormat as Tt, PluginContext as U, EmittedPrebuiltChunk as V, DefineParallelPluginResult as W, ModuleTypeFilter as X, HookFilter as Y, BufferEncoding as Z, LoadResult as _, AdvancedChunksGroup as _t, ExternalOption as a, ChecksOptions as at, ObjectHook as b, CodeSplittingGroup as bt, InputOptions as c, watch as ct, WatcherOptions as d, WatchOptions as dt, RolldownFsModule as et, AsyncPluginHooks as f, rolldown as ft, ImportKind as g, AddonFunction as gt, HookFilterExtension as h, build as ht, RolldownOptions as i, TransformOptions as it, withFilter as j, OutputAsset as jt, SourceDescription as k, PartialNull as kt, ModuleTypes as l, RolldownWatcher as lt, FunctionPluginHooks as m, BuildOptions as mt, RolldownOptionsFunction as n, NormalizedOutputOptions as nt, ExternalOptionFunction as o, LoggingFunction as ot, CustomPluginOptions as p, RolldownBuild as pt, PluginContextMeta as q, defineConfig as r, NormalizedInputOptions as rt, InputOption as s, WarningHandlerWithDefault as st, ConfigExport as t, InternalModuleFormat as tt, OptimizationOptions as u, RolldownWatcherEvent as ut, ModuleOptions as v, ChunkFileNamesFunction as vt, ResolveIdExtraOptions as w, MinifyOptions as wt, ParallelPluginHooks as x, GeneratedCodeOptions as xt, ModuleType as y, ChunkingContext as yt, EmittedAsset as z, SourcemapIgnoreListOption as zt };