define-config-DhJZwTRw.d.mts 135 KB

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