index.d.ts 146 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713
  1. /// <reference types="node" />
  2. import { t as ModuleRunnerTransport } from "./chunks/moduleRunnerTransport.js";
  3. import { ConnectedPayload, CustomPayload, CustomPayload as hmrPayload_CustomPayload, ErrorPayload, FullReloadPayload, HMRPayload, HotPayload, HotPayload as hmrPayload_HotPayload, PrunePayload, Update, UpdatePayload } from "#types/hmrPayload";
  4. import { CustomEventMap, InferCustomEventPayload, InferCustomEventPayload as hmrPayload_InferCustomEventPayload, InvalidatePayload } from "#types/customEvent";
  5. import * as Rollup from "rollup";
  6. import { CustomPluginOptions, ExistingRawSourceMap, InputOption, InputOptions, LoadResult, MinimalPluginContext, ModuleFormat, ModuleInfo, ObjectHook, OutputBundle, OutputChunk, PartialResolvedId, PluginContext, PluginContextMeta, PluginHooks, ResolveIdResult, RollupError, RollupLog, RollupOptions, RollupOutput, RollupWatcher, SourceDescription, SourceMap, SourceMapInput, TransformPluginContext, WatcherOptions } from "rollup";
  7. import { parseAst, parseAstAsync } from "rollup/parseAst";
  8. import * as http from "node:http";
  9. import { Agent, ClientRequest, ClientRequestArgs, OutgoingHttpHeaders, ServerResponse } from "node:http";
  10. import { Http2SecureServer } from "node:http2";
  11. import * as fs from "node:fs";
  12. import { EventEmitter } from "node:events";
  13. import { Server as HttpsServer, ServerOptions as HttpsServerOptions } from "node:https";
  14. import * as net from "node:net";
  15. import { Duplex, DuplexOptions, Stream } from "node:stream";
  16. import { FetchFunction, FetchFunctionOptions, FetchResult, FetchResult as moduleRunner_FetchResult, ModuleEvaluator, ModuleRunner, ModuleRunnerHmr, ModuleRunnerOptions } from "vite/module-runner";
  17. import { BuildOptions as esbuild_BuildOptions, TransformOptions as EsbuildTransformOptions, TransformOptions as esbuild_TransformOptions, TransformResult as esbuild_TransformResult, version as esbuildVersion } from "esbuild";
  18. import { SecureContextOptions } from "node:tls";
  19. import { URL as url_URL } from "node:url";
  20. import { ZlibOptions } from "node:zlib";
  21. import { Terser, TerserMinifyOptions } from "#types/internal/terserOptions";
  22. import * as PostCSS from "postcss";
  23. import { LessPreprocessorBaseOptions, SassModernPreprocessBaseOptions, StylusPreprocessorBaseOptions } from "#types/internal/cssPreprocessorOptions";
  24. import { LightningCSSOptions, LightningCSSOptions as lightningcssOptions_LightningCSSOptions } from "#types/internal/lightningcssOptions";
  25. import { GeneralImportGlobOptions, ImportGlobFunction, ImportGlobOptions, KnownAsTypeMap } from "#types/importGlob";
  26. import { ChunkMetadata, CustomPluginOptionsVite } from "#types/metadata";
  27. //#region rolldown:runtime
  28. //#endregion
  29. //#region src/types/alias.d.ts
  30. interface Alias {
  31. find: string | RegExp;
  32. replacement: string;
  33. /**
  34. * Instructs the plugin to use an alternative resolving algorithm,
  35. * rather than the Rollup's resolver.
  36. * @default null
  37. */
  38. customResolver?: ResolverFunction | ResolverObject | null;
  39. }
  40. type MapToFunction<T$1> = T$1 extends Function ? T$1 : never;
  41. type ResolverFunction = MapToFunction<PluginHooks['resolveId']>;
  42. interface ResolverObject {
  43. buildStart?: PluginHooks['buildStart'];
  44. resolveId: ResolverFunction;
  45. }
  46. /**
  47. * Specifies an `Object`, or an `Array` of `Object`,
  48. * which defines aliases used to replace values in `import` or `require` statements.
  49. * With either format, the order of the entries is important,
  50. * in that the first defined rules are applied first.
  51. *
  52. * This is passed to \@rollup/plugin-alias as the "entries" field
  53. * https://github.com/rollup/plugins/tree/master/packages/alias#entries
  54. */
  55. type AliasOptions = readonly Alias[] | {
  56. [find: string]: string;
  57. };
  58. //#endregion
  59. //#region src/types/anymatch.d.ts
  60. type AnymatchFn = (testString: string) => boolean;
  61. type AnymatchPattern = string | RegExp | AnymatchFn;
  62. type AnymatchMatcher = AnymatchPattern | AnymatchPattern[];
  63. //#endregion
  64. //#region src/types/chokidar.d.ts
  65. declare class FSWatcher extends EventEmitter implements fs.FSWatcher {
  66. options: WatchOptions;
  67. /**
  68. * Constructs a new FSWatcher instance with optional WatchOptions parameter.
  69. */
  70. constructor(options?: WatchOptions);
  71. /**
  72. * When called, requests that the Node.js event loop not exit so long as the fs.FSWatcher is active.
  73. * Calling watcher.ref() multiple times will have no effect.
  74. */
  75. ref(): this;
  76. /**
  77. * When called, the active fs.FSWatcher object will not require the Node.js event loop to remain active.
  78. * If there is no other activity keeping the event loop running, the process may exit before the fs.FSWatcher object's callback is invoked.
  79. * Calling watcher.unref() multiple times will have no effect.
  80. */
  81. unref(): this;
  82. /**
  83. * Add files, directories, or glob patterns for tracking. Takes an array of strings or just one
  84. * string.
  85. */
  86. add(paths: string | ReadonlyArray<string>): this;
  87. /**
  88. * Stop watching files, directories, or glob patterns. Takes an array of strings or just one
  89. * string.
  90. */
  91. unwatch(paths: string | ReadonlyArray<string>): this;
  92. /**
  93. * Returns an object representing all the paths on the file system being watched by this
  94. * `FSWatcher` instance. The object's keys are all the directories (using absolute paths unless
  95. * the `cwd` option was used), and the values are arrays of the names of the items contained in
  96. * each directory.
  97. */
  98. getWatched(): {
  99. [directory: string]: string[];
  100. };
  101. /**
  102. * Removes all listeners from watched files.
  103. */
  104. close(): Promise<void>;
  105. on(event: 'add' | 'addDir' | 'change', listener: (path: string, stats?: fs.Stats) => void): this;
  106. on(event: 'all', listener: (eventName: 'add' | 'addDir' | 'change' | 'unlink' | 'unlinkDir', path: string, stats?: fs.Stats) => void): this;
  107. /**
  108. * Error occurred
  109. */
  110. on(event: 'error', listener: (error: Error) => void): this;
  111. /**
  112. * Exposes the native Node `fs.FSWatcher events`
  113. */
  114. on(event: 'raw', listener: (eventName: string, path: string, details: any) => void): this;
  115. /**
  116. * Fires when the initial scan is complete
  117. */
  118. on(event: 'ready', listener: () => void): this;
  119. on(event: 'unlink' | 'unlinkDir', listener: (path: string) => void): this;
  120. on(event: string, listener: (...args: any[]) => void): this;
  121. }
  122. interface WatchOptions {
  123. /**
  124. * Indicates whether the process should continue to run as long as files are being watched. If
  125. * set to `false` when using `fsevents` to watch, no more events will be emitted after `ready`,
  126. * even if the process continues to run.
  127. */
  128. persistent?: boolean;
  129. /**
  130. * ([anymatch](https://github.com/micromatch/anymatch)-compatible definition) Defines files/paths to
  131. * be ignored. The whole relative or absolute path is tested, not just filename. If a function
  132. * with two arguments is provided, it gets called twice per path - once with a single argument
  133. * (the path), second time with two arguments (the path and the
  134. * [`fs.Stats`](https://nodejs.org/api/fs.html#fs_class_fs_stats) object of that path).
  135. */
  136. ignored?: AnymatchMatcher;
  137. /**
  138. * If set to `false` then `add`/`addDir` events are also emitted for matching paths while
  139. * instantiating the watching as chokidar discovers these file paths (before the `ready` event).
  140. */
  141. ignoreInitial?: boolean;
  142. /**
  143. * When `false`, only the symlinks themselves will be watched for changes instead of following
  144. * the link references and bubbling events through the link's path.
  145. */
  146. followSymlinks?: boolean;
  147. /**
  148. * The base directory from which watch `paths` are to be derived. Paths emitted with events will
  149. * be relative to this.
  150. */
  151. cwd?: string;
  152. /**
  153. * If set to true then the strings passed to .watch() and .add() are treated as literal path
  154. * names, even if they look like globs.
  155. *
  156. * @default false
  157. */
  158. disableGlobbing?: boolean;
  159. /**
  160. * Whether to use fs.watchFile (backed by polling), or fs.watch. If polling leads to high CPU
  161. * utilization, consider setting this to `false`. It is typically necessary to **set this to
  162. * `true` to successfully watch files over a network**, and it may be necessary to successfully
  163. * watch files in other non-standard situations. Setting to `true` explicitly on OS X overrides
  164. * the `useFsEvents` default.
  165. */
  166. usePolling?: boolean;
  167. /**
  168. * Whether to use the `fsevents` watching interface if available. When set to `true` explicitly
  169. * and `fsevents` is available this supersedes the `usePolling` setting. When set to `false` on
  170. * OS X, `usePolling: true` becomes the default.
  171. */
  172. useFsEvents?: boolean;
  173. /**
  174. * If relying upon the [`fs.Stats`](https://nodejs.org/api/fs.html#fs_class_fs_stats) object that
  175. * may get passed with `add`, `addDir`, and `change` events, set this to `true` to ensure it is
  176. * provided even in cases where it wasn't already available from the underlying watch events.
  177. */
  178. alwaysStat?: boolean;
  179. /**
  180. * If set, limits how many levels of subdirectories will be traversed.
  181. */
  182. depth?: number;
  183. /**
  184. * Interval of file system polling.
  185. */
  186. interval?: number;
  187. /**
  188. * Interval of file system polling for binary files. ([see list of binary extensions](https://gi
  189. * thub.com/sindresorhus/binary-extensions/blob/master/binary-extensions.json))
  190. */
  191. binaryInterval?: number;
  192. /**
  193. * Indicates whether to watch files that don't have read permissions if possible. If watching
  194. * fails due to `EPERM` or `EACCES` with this set to `true`, the errors will be suppressed
  195. * silently.
  196. */
  197. ignorePermissionErrors?: boolean;
  198. /**
  199. * `true` if `useFsEvents` and `usePolling` are `false`. Automatically filters out artifacts
  200. * that occur when using editors that use "atomic writes" instead of writing directly to the
  201. * source file. If a file is re-added within 100 ms of being deleted, Chokidar emits a `change`
  202. * event rather than `unlink` then `add`. If the default of 100 ms does not work well for you,
  203. * you can override it by setting `atomic` to a custom value, in milliseconds.
  204. */
  205. atomic?: boolean | number;
  206. /**
  207. * can be set to an object in order to adjust timing params:
  208. */
  209. awaitWriteFinish?: AwaitWriteFinishOptions | boolean;
  210. }
  211. interface AwaitWriteFinishOptions {
  212. /**
  213. * Amount of time in milliseconds for a file size to remain constant before emitting its event.
  214. */
  215. stabilityThreshold?: number;
  216. /**
  217. * File size polling interval.
  218. */
  219. pollInterval?: number;
  220. }
  221. //#endregion
  222. //#region src/types/connect.d.ts
  223. declare namespace Connect {
  224. export type ServerHandle = HandleFunction | http.Server;
  225. export class IncomingMessage extends http.IncomingMessage {
  226. originalUrl?: http.IncomingMessage['url'] | undefined;
  227. }
  228. export type NextFunction = (err?: any) => void;
  229. export type SimpleHandleFunction = (req: IncomingMessage, res: http.ServerResponse) => void;
  230. export type NextHandleFunction = (req: IncomingMessage, res: http.ServerResponse, next: NextFunction) => void;
  231. export type ErrorHandleFunction = (err: any, req: IncomingMessage, res: http.ServerResponse, next: NextFunction) => void;
  232. export type HandleFunction = SimpleHandleFunction | NextHandleFunction | ErrorHandleFunction;
  233. export interface ServerStackItem {
  234. route: string;
  235. handle: ServerHandle;
  236. }
  237. export interface Server extends NodeJS.EventEmitter {
  238. (req: http.IncomingMessage, res: http.ServerResponse, next?: Function): void;
  239. route: string;
  240. stack: ServerStackItem[];
  241. /**
  242. * Utilize the given middleware `handle` to the given `route`,
  243. * defaulting to _/_. This "route" is the mount-point for the
  244. * middleware, when given a value other than _/_ the middleware
  245. * is only effective when that segment is present in the request's
  246. * pathname.
  247. *
  248. * For example if we were to mount a function at _/admin_, it would
  249. * be invoked on _/admin_, and _/admin/settings_, however it would
  250. * not be invoked for _/_, or _/posts_.
  251. */
  252. use(fn: NextHandleFunction): Server;
  253. use(fn: HandleFunction): Server;
  254. use(route: string, fn: NextHandleFunction): Server;
  255. use(route: string, fn: HandleFunction): Server;
  256. /**
  257. * Handle server requests, punting them down
  258. * the middleware stack.
  259. */
  260. handle(req: http.IncomingMessage, res: http.ServerResponse, next: Function): void;
  261. /**
  262. * Listen for connections.
  263. *
  264. * This method takes the same arguments
  265. * as node's `http.Server#listen()`.
  266. *
  267. * HTTP and HTTPS:
  268. *
  269. * If you run your application both as HTTP
  270. * and HTTPS you may wrap them individually,
  271. * since your Connect "server" is really just
  272. * a JavaScript `Function`.
  273. *
  274. * var connect = require('connect')
  275. * , http = require('http')
  276. * , https = require('https');
  277. *
  278. * var app = connect();
  279. *
  280. * http.createServer(app).listen(80);
  281. * https.createServer(options, app).listen(443);
  282. */
  283. listen(port: number, hostname?: string, backlog?: number, callback?: Function): http.Server;
  284. listen(port: number, hostname?: string, callback?: Function): http.Server;
  285. listen(path: string, callback?: Function): http.Server;
  286. listen(handle: any, listeningListener?: Function): http.Server;
  287. }
  288. }
  289. //#endregion
  290. //#region ../../node_modules/.pnpm/http-proxy-3@1.22.0_patch_hash=d89dff5a0afc2cb277080ad056a3baf7feeeeac19144878abc17f4c91ad89095_ms@2.1.3/node_modules/http-proxy-3/dist/lib/http-proxy/index.d.ts
  291. interface ProxyTargetDetailed {
  292. host: string;
  293. port: number;
  294. protocol?: string;
  295. hostname?: string;
  296. socketPath?: string;
  297. key?: string;
  298. passphrase?: string;
  299. pfx?: Buffer | string;
  300. cert?: string;
  301. ca?: string;
  302. ciphers?: string;
  303. secureProtocol?: string;
  304. }
  305. type ProxyType = "ws" | "web";
  306. type ProxyTarget = ProxyTargetUrl | ProxyTargetDetailed;
  307. type ProxyTargetUrl = URL | string | {
  308. port: number;
  309. host: string;
  310. protocol?: string;
  311. };
  312. type NormalizeProxyTarget<T$1 extends ProxyTargetUrl> = Exclude<T$1, string> | URL;
  313. interface ServerOptions$3 {
  314. /** URL string to be parsed with the url module. */
  315. target?: ProxyTarget;
  316. /** URL string to be parsed with the url module or a URL object. */
  317. forward?: ProxyTargetUrl;
  318. /** Object to be passed to http(s).request. */
  319. agent?: any;
  320. /** Object to be passed to https.createServer(). */
  321. ssl?: any;
  322. /** If you want to proxy websockets. */
  323. ws?: boolean;
  324. /** Adds x- forward headers. */
  325. xfwd?: boolean;
  326. /** Verify SSL certificate. */
  327. secure?: boolean;
  328. /** Explicitly specify if we are proxying to another proxy. */
  329. toProxy?: boolean;
  330. /** Specify whether you want to prepend the target's path to the proxy path. */
  331. prependPath?: boolean;
  332. /** Specify whether you want to ignore the proxy path of the incoming request. */
  333. ignorePath?: boolean;
  334. /** Local interface string to bind for outgoing connections. */
  335. localAddress?: string;
  336. /** Changes the origin of the host header to the target URL. */
  337. changeOrigin?: boolean;
  338. /** specify whether you want to keep letter case of response header key */
  339. preserveHeaderKeyCase?: boolean;
  340. /** Basic authentication i.e. 'user:password' to compute an Authorization header. */
  341. auth?: string;
  342. /** Rewrites the location hostname on (301 / 302 / 307 / 308) redirects, Default: null. */
  343. hostRewrite?: string;
  344. /** Rewrites the location host/ port on (301 / 302 / 307 / 308) redirects based on requested host/ port.Default: false. */
  345. autoRewrite?: boolean;
  346. /** Rewrites the location protocol on (301 / 302 / 307 / 308) redirects to 'http' or 'https'.Default: null. */
  347. protocolRewrite?: string;
  348. /** rewrites domain of set-cookie headers. */
  349. cookieDomainRewrite?: false | string | {
  350. [oldDomain: string]: string;
  351. };
  352. /** rewrites path of set-cookie headers. Default: false */
  353. cookiePathRewrite?: false | string | {
  354. [oldPath: string]: string;
  355. };
  356. /** object with extra headers to be added to target requests. */
  357. headers?: {
  358. [header: string]: string | string[] | undefined;
  359. };
  360. /** Timeout (in milliseconds) when proxy receives no response from target. Default: 120000 (2 minutes) */
  361. proxyTimeout?: number;
  362. /** Timeout (in milliseconds) for incoming requests */
  363. timeout?: number;
  364. /** Specify whether you want to follow redirects. Default: false */
  365. followRedirects?: boolean;
  366. /** If set to true, none of the webOutgoing passes are called and it's your responsibility to appropriately return the response by listening and acting on the proxyRes event */
  367. selfHandleResponse?: boolean;
  368. /** Buffer */
  369. buffer?: Stream;
  370. /** Explicitly set the method type of the ProxyReq */
  371. method?: string;
  372. /**
  373. * Optionally override the trusted CA certificates.
  374. * This is passed to https.request.
  375. */
  376. ca?: string;
  377. }
  378. interface NormalizedServerOptions extends ServerOptions$3 {
  379. target?: NormalizeProxyTarget<ProxyTarget>;
  380. forward?: NormalizeProxyTarget<ProxyTargetUrl>;
  381. }
  382. type ErrorCallback<TIncomingMessage extends typeof http.IncomingMessage = typeof http.IncomingMessage, TServerResponse extends typeof http.ServerResponse = typeof http.ServerResponse, TError = Error> = (err: TError, req: InstanceType<TIncomingMessage>, res: InstanceType<TServerResponse> | net.Socket, target?: ProxyTargetUrl) => void;
  383. type ProxyServerEventMap<TIncomingMessage extends typeof http.IncomingMessage = typeof http.IncomingMessage, TServerResponse extends typeof http.ServerResponse = typeof http.ServerResponse, TError = Error> = {
  384. error: Parameters<ErrorCallback<TIncomingMessage, TServerResponse, TError>>;
  385. start: [req: InstanceType<TIncomingMessage>, res: InstanceType<TServerResponse>, target: ProxyTargetUrl];
  386. open: [socket: net.Socket];
  387. proxyReq: [proxyReq: http.ClientRequest, req: InstanceType<TIncomingMessage>, res: InstanceType<TServerResponse>, options: ServerOptions$3, socket: net.Socket];
  388. proxyRes: [proxyRes: InstanceType<TIncomingMessage>, req: InstanceType<TIncomingMessage>, res: InstanceType<TServerResponse>];
  389. proxyReqWs: [proxyReq: http.ClientRequest, req: InstanceType<TIncomingMessage>, socket: net.Socket, options: ServerOptions$3, head: any];
  390. econnreset: [err: Error, req: InstanceType<TIncomingMessage>, res: InstanceType<TServerResponse>, target: ProxyTargetUrl];
  391. end: [req: InstanceType<TIncomingMessage>, res: InstanceType<TServerResponse>, proxyRes: InstanceType<TIncomingMessage>];
  392. close: [proxyRes: InstanceType<TIncomingMessage>, proxySocket: net.Socket, proxyHead: any];
  393. };
  394. type ProxyMethodArgs<TIncomingMessage extends typeof http.IncomingMessage = typeof http.IncomingMessage, TServerResponse extends typeof http.ServerResponse = typeof http.ServerResponse, TError = Error> = {
  395. ws: [req: InstanceType<TIncomingMessage>, socket: any, head: any, ...args: [options?: ServerOptions$3, callback?: ErrorCallback<TIncomingMessage, TServerResponse, TError>] | [callback?: ErrorCallback<TIncomingMessage, TServerResponse, TError>]];
  396. web: [req: InstanceType<TIncomingMessage>, res: InstanceType<TServerResponse>, ...args: [options: ServerOptions$3, callback?: ErrorCallback<TIncomingMessage, TServerResponse, TError>] | [callback?: ErrorCallback<TIncomingMessage, TServerResponse, TError>]];
  397. };
  398. type PassFunctions<TIncomingMessage extends typeof http.IncomingMessage = typeof http.IncomingMessage, TServerResponse extends typeof http.ServerResponse = typeof http.ServerResponse, TError = Error> = {
  399. ws: (req: InstanceType<TIncomingMessage>, socket: net.Socket, options: NormalizedServerOptions, head: Buffer | undefined, server: ProxyServer<TIncomingMessage, TServerResponse, TError>, cb?: ErrorCallback<TIncomingMessage, TServerResponse, TError>) => unknown;
  400. web: (req: InstanceType<TIncomingMessage>, res: InstanceType<TServerResponse>, options: NormalizedServerOptions, head: Buffer | undefined, server: ProxyServer<TIncomingMessage, TServerResponse, TError>, cb?: ErrorCallback<TIncomingMessage, TServerResponse, TError>) => unknown;
  401. };
  402. declare class ProxyServer<TIncomingMessage extends typeof http.IncomingMessage = typeof http.IncomingMessage, TServerResponse extends typeof http.ServerResponse = typeof http.ServerResponse, TError = Error> extends EventEmitter<ProxyServerEventMap<TIncomingMessage, TServerResponse, TError>> {
  403. /**
  404. * Used for proxying WS(S) requests
  405. * @param req - Client request.
  406. * @param socket - Client socket.
  407. * @param head - Client head.
  408. * @param options - Additional options.
  409. */
  410. readonly ws: (...args: ProxyMethodArgs<TIncomingMessage, TServerResponse, TError>["ws"]) => void;
  411. /**
  412. * Used for proxying regular HTTP(S) requests
  413. * @param req - Client request.
  414. * @param res - Client response.
  415. * @param options - Additional options.
  416. */
  417. readonly web: (...args: ProxyMethodArgs<TIncomingMessage, TServerResponse, TError>["web"]) => void;
  418. private options;
  419. private webPasses;
  420. private wsPasses;
  421. private _server?;
  422. /**
  423. * Creates the proxy server with specified options.
  424. * @param options - Config object passed to the proxy
  425. */
  426. constructor(options?: ServerOptions$3);
  427. /**
  428. * Creates the proxy server with specified options.
  429. * @param options Config object passed to the proxy
  430. * @returns Proxy object with handlers for `ws` and `web` requests
  431. */
  432. static createProxyServer<TIncomingMessage extends typeof http.IncomingMessage, TServerResponse extends typeof http.ServerResponse, TError = Error>(options?: ServerOptions$3): ProxyServer<TIncomingMessage, TServerResponse, TError>;
  433. /**
  434. * Creates the proxy server with specified options.
  435. * @param options Config object passed to the proxy
  436. * @returns Proxy object with handlers for `ws` and `web` requests
  437. */
  438. static createServer<TIncomingMessage extends typeof http.IncomingMessage, TServerResponse extends typeof http.ServerResponse, TError = Error>(options?: ServerOptions$3): ProxyServer<TIncomingMessage, TServerResponse, TError>;
  439. /**
  440. * Creates the proxy server with specified options.
  441. * @param options Config object passed to the proxy
  442. * @returns Proxy object with handlers for `ws` and `web` requests
  443. */
  444. static createProxy<TIncomingMessage extends typeof http.IncomingMessage, TServerResponse extends typeof http.ServerResponse, TError = Error>(options?: ServerOptions$3): ProxyServer<TIncomingMessage, TServerResponse, TError>;
  445. createRightProxy: <PT extends ProxyType>(type: PT) => Function;
  446. onError: (err: TError) => void;
  447. /**
  448. * A function that wraps the object in a webserver, for your convenience
  449. * @param port - Port to listen on
  450. * @param hostname - The hostname to listen on
  451. */
  452. listen: (port: number, hostname?: string) => this;
  453. address: () => string | net.AddressInfo | null | undefined;
  454. /**
  455. * A function that closes the inner webserver and stops listening on given port
  456. */
  457. close: (cb?: Function) => void;
  458. before: <PT extends ProxyType>(type: PT, passName: string, cb: PassFunctions<TIncomingMessage, TServerResponse, TError>[PT]) => void;
  459. after: <PT extends ProxyType>(type: PT, passName: string, cb: PassFunctions<TIncomingMessage, TServerResponse, TError>[PT]) => void;
  460. }
  461. //#endregion
  462. //#region ../../node_modules/.pnpm/http-proxy-3@1.22.0_patch_hash=d89dff5a0afc2cb277080ad056a3baf7feeeeac19144878abc17f4c91ad89095_ms@2.1.3/node_modules/http-proxy-3/dist/lib/http-proxy/passes/ws-incoming.d.ts
  463. declare function numOpenSockets(): number;
  464. declare namespace index_d_exports {
  465. export { ErrorCallback, ProxyServer, ProxyTarget, ProxyTargetUrl, ServerOptions$3 as ServerOptions, createProxyServer as createProxy, createProxyServer, createProxyServer as createServer, ProxyServer as default, numOpenSockets };
  466. }
  467. /**
  468. * Creates the proxy server.
  469. *
  470. * Examples:
  471. *
  472. * httpProxy.createProxyServer({ .. }, 8000)
  473. * // => '{ web: [Function], ws: [Function] ... }'
  474. *
  475. * @param {Object} Options Config object passed to the proxy
  476. *
  477. * @return {Object} Proxy Proxy object with handlers for `ws` and `web` requests
  478. *
  479. * @api public
  480. */
  481. declare function createProxyServer<TIncomingMessage extends typeof http.IncomingMessage = typeof http.IncomingMessage, TServerResponse extends typeof http.ServerResponse = typeof http.ServerResponse, TError = Error>(options?: ServerOptions$3): ProxyServer<TIncomingMessage, TServerResponse, TError>;
  482. //#endregion
  483. //#region src/node/server/middlewares/proxy.d.ts
  484. interface ProxyOptions extends ServerOptions$3 {
  485. /**
  486. * rewrite path
  487. */
  488. rewrite?: (path: string) => string;
  489. /**
  490. * configure the proxy server (e.g. listen to events)
  491. */
  492. configure?: (proxy: ProxyServer, options: ProxyOptions) => void;
  493. /**
  494. * webpack-dev-server style bypass function
  495. */
  496. bypass?: (req: http.IncomingMessage, res: http.ServerResponse | undefined, options: ProxyOptions) => void | null | undefined | false | string | Promise<void | null | undefined | boolean | string>;
  497. /**
  498. * rewrite the Origin header of a WebSocket request to match the target
  499. *
  500. * **Exercise caution as rewriting the Origin can leave the proxying open to [CSRF attacks](https://owasp.org/www-community/attacks/csrf).**
  501. */
  502. rewriteWsOrigin?: boolean | undefined;
  503. }
  504. //#endregion
  505. //#region src/node/logger.d.ts
  506. type LogType = "error" | "warn" | "info";
  507. type LogLevel = LogType | "silent";
  508. interface Logger {
  509. info(msg: string, options?: LogOptions): void;
  510. warn(msg: string, options?: LogOptions): void;
  511. warnOnce(msg: string, options?: LogOptions): void;
  512. error(msg: string, options?: LogErrorOptions): void;
  513. clearScreen(type: LogType): void;
  514. hasErrorLogged(error: Error | RollupError): boolean;
  515. hasWarned: boolean;
  516. }
  517. interface LogOptions {
  518. clear?: boolean;
  519. timestamp?: boolean;
  520. environment?: string;
  521. }
  522. interface LogErrorOptions extends LogOptions {
  523. error?: Error | RollupError | null;
  524. }
  525. interface LoggerOptions {
  526. prefix?: string;
  527. allowClearScreen?: boolean;
  528. customLogger?: Logger;
  529. console?: Console;
  530. }
  531. declare function createLogger(level?: LogLevel, options?: LoggerOptions): Logger;
  532. //#endregion
  533. //#region src/node/http.d.ts
  534. interface CommonServerOptions {
  535. /**
  536. * Specify server port. Note if the port is already being used, Vite will
  537. * automatically try the next available port so this may not be the actual
  538. * port the server ends up listening on.
  539. */
  540. port?: number;
  541. /**
  542. * If enabled, vite will exit if specified port is already in use
  543. */
  544. strictPort?: boolean;
  545. /**
  546. * Specify which IP addresses the server should listen on.
  547. * Set to 0.0.0.0 to listen on all addresses, including LAN and public addresses.
  548. */
  549. host?: string | boolean;
  550. /**
  551. * The hostnames that Vite is allowed to respond to.
  552. * `localhost` and subdomains under `.localhost` and all IP addresses are allowed by default.
  553. * When using HTTPS, this check is skipped.
  554. *
  555. * If a string starts with `.`, it will allow that hostname without the `.` and all subdomains under the hostname.
  556. * For example, `.example.com` will allow `example.com`, `foo.example.com`, and `foo.bar.example.com`.
  557. *
  558. * If set to `true`, the server is allowed to respond to requests for any hosts.
  559. * This is not recommended as it will be vulnerable to DNS rebinding attacks.
  560. */
  561. allowedHosts?: string[] | true;
  562. /**
  563. * Enable TLS + HTTP/2.
  564. * Note: this downgrades to TLS only when the proxy option is also used.
  565. */
  566. https?: HttpsServerOptions;
  567. /**
  568. * Open browser window on startup
  569. */
  570. open?: boolean | string;
  571. /**
  572. * Configure custom proxy rules for the dev server. Expects an object
  573. * of `{ key: options }` pairs.
  574. * Uses [`http-proxy-3`](https://github.com/sagemathinc/http-proxy-3).
  575. * Full options [here](https://github.com/sagemathinc/http-proxy-3#options).
  576. *
  577. * Example `vite.config.js`:
  578. * ``` js
  579. * module.exports = {
  580. * proxy: {
  581. * // string shorthand: /foo -> http://localhost:4567/foo
  582. * '/foo': 'http://localhost:4567',
  583. * // with options
  584. * '/api': {
  585. * target: 'http://jsonplaceholder.typicode.com',
  586. * changeOrigin: true,
  587. * rewrite: path => path.replace(/^\/api/, '')
  588. * }
  589. * }
  590. * }
  591. * ```
  592. */
  593. proxy?: Record<string, string | ProxyOptions>;
  594. /**
  595. * Configure CORS for the dev server.
  596. * Uses https://github.com/expressjs/cors.
  597. *
  598. * When enabling this option, **we recommend setting a specific value
  599. * rather than `true`** to avoid exposing the source code to untrusted origins.
  600. *
  601. * Set to `true` to allow all methods from any origin, or configure separately
  602. * using an object.
  603. *
  604. * @default false
  605. */
  606. cors?: CorsOptions | boolean;
  607. /**
  608. * Specify server response headers.
  609. */
  610. headers?: OutgoingHttpHeaders;
  611. }
  612. /**
  613. * https://github.com/expressjs/cors#configuration-options
  614. */
  615. interface CorsOptions {
  616. /**
  617. * Configures the Access-Control-Allow-Origin CORS header.
  618. *
  619. * **We recommend setting a specific value rather than
  620. * `true`** to avoid exposing the source code to untrusted origins.
  621. */
  622. origin?: CorsOrigin | ((origin: string | undefined, cb: (err: Error, origins: CorsOrigin) => void) => void);
  623. methods?: string | string[];
  624. allowedHeaders?: string | string[];
  625. exposedHeaders?: string | string[];
  626. credentials?: boolean;
  627. maxAge?: number;
  628. preflightContinue?: boolean;
  629. optionsSuccessStatus?: number;
  630. }
  631. type CorsOrigin = boolean | string | RegExp | (string | RegExp)[];
  632. //#endregion
  633. //#region src/node/typeUtils.d.ts
  634. type RequiredExceptFor<T$1, K$1 extends keyof T$1> = Pick<T$1, K$1> & Required<Omit<T$1, K$1>>;
  635. //#endregion
  636. //#region src/node/preview.d.ts
  637. interface PreviewOptions extends CommonServerOptions {}
  638. interface ResolvedPreviewOptions extends RequiredExceptFor<PreviewOptions, "host" | "https" | "proxy"> {}
  639. interface PreviewServer {
  640. /**
  641. * The resolved vite config object
  642. */
  643. config: ResolvedConfig;
  644. /**
  645. * Stop the server.
  646. */
  647. close(): Promise<void>;
  648. /**
  649. * A connect app instance.
  650. * - Can be used to attach custom middlewares to the preview server.
  651. * - Can also be used as the handler function of a custom http server
  652. * or as a middleware in any connect-style Node.js frameworks
  653. *
  654. * https://github.com/senchalabs/connect#use-middleware
  655. */
  656. middlewares: Connect.Server;
  657. /**
  658. * native Node http server instance
  659. */
  660. httpServer: HttpServer;
  661. /**
  662. * The resolved urls Vite prints on the CLI (URL-encoded). Returns `null`
  663. * if the server is not listening on any port.
  664. */
  665. resolvedUrls: ResolvedServerUrls | null;
  666. /**
  667. * Print server urls
  668. */
  669. printUrls(): void;
  670. /**
  671. * Bind CLI shortcuts
  672. */
  673. bindCLIShortcuts(options?: BindCLIShortcutsOptions<PreviewServer>): void;
  674. }
  675. type PreviewServerHook = (this: MinimalPluginContextWithoutEnvironment, server: PreviewServer) => (() => void) | void | Promise<(() => void) | void>;
  676. /**
  677. * Starts the Vite server in preview mode, to simulate a production deployment
  678. */
  679. declare function preview(inlineConfig?: InlineConfig): Promise<PreviewServer>;
  680. //#endregion
  681. //#region src/node/shortcuts.d.ts
  682. type BindCLIShortcutsOptions<Server$3 = ViteDevServer | PreviewServer> = {
  683. /**
  684. * Print a one-line shortcuts "help" hint to the terminal
  685. */
  686. print?: boolean;
  687. /**
  688. * Custom shortcuts to run when a key is pressed. These shortcuts take priority
  689. * over the default shortcuts if they have the same keys (except the `h` key).
  690. * To disable a default shortcut, define the same key but with `action: undefined`.
  691. */
  692. customShortcuts?: CLIShortcut<Server$3>[];
  693. };
  694. type CLIShortcut<Server$3 = ViteDevServer | PreviewServer> = {
  695. key: string;
  696. description: string;
  697. action?(server: Server$3): void | Promise<void>;
  698. };
  699. //#endregion
  700. //#region src/node/baseEnvironment.d.ts
  701. declare class PartialEnvironment {
  702. name: string;
  703. getTopLevelConfig(): ResolvedConfig;
  704. config: ResolvedConfig & ResolvedEnvironmentOptions;
  705. logger: Logger;
  706. constructor(name: string, topLevelConfig: ResolvedConfig, options?: ResolvedEnvironmentOptions);
  707. }
  708. declare class BaseEnvironment extends PartialEnvironment {
  709. get plugins(): readonly Plugin[];
  710. constructor(name: string, config: ResolvedConfig, options?: ResolvedEnvironmentOptions);
  711. }
  712. /**
  713. * This class discourages users from inversely checking the `mode`
  714. * to determine the type of environment, e.g.
  715. *
  716. * ```js
  717. * const isDev = environment.mode !== 'build' // bad
  718. * const isDev = environment.mode === 'dev' // good
  719. * ```
  720. *
  721. * You should also not check against `"unknown"` specifically. It's
  722. * a placeholder for more possible environment types.
  723. */
  724. declare class UnknownEnvironment extends BaseEnvironment {
  725. mode: "unknown";
  726. }
  727. //#endregion
  728. //#region src/node/optimizer/scan.d.ts
  729. declare class ScanEnvironment extends BaseEnvironment {
  730. mode: "scan";
  731. get pluginContainer(): EnvironmentPluginContainer;
  732. init(): Promise<void>;
  733. }
  734. //#endregion
  735. //#region src/node/optimizer/index.d.ts
  736. type ExportsData = {
  737. hasModuleSyntax: boolean;
  738. exports: readonly string[];
  739. jsxLoader?: boolean;
  740. };
  741. interface DepsOptimizer {
  742. init: () => Promise<void>;
  743. metadata: DepOptimizationMetadata;
  744. scanProcessing?: Promise<void>;
  745. registerMissingImport: (id: string, resolved: string) => OptimizedDepInfo;
  746. run: () => void;
  747. isOptimizedDepFile: (id: string) => boolean;
  748. isOptimizedDepUrl: (url: string) => boolean;
  749. getOptimizedDepId: (depInfo: OptimizedDepInfo) => string;
  750. close: () => Promise<void>;
  751. options: DepOptimizationOptions;
  752. }
  753. interface DepOptimizationConfig {
  754. /**
  755. * Force optimize listed dependencies (must be resolvable import paths,
  756. * cannot be globs).
  757. */
  758. include?: string[];
  759. /**
  760. * Do not optimize these dependencies (must be resolvable import paths,
  761. * cannot be globs).
  762. */
  763. exclude?: string[];
  764. /**
  765. * Forces ESM interop when importing these dependencies. Some legacy
  766. * packages advertise themselves as ESM but use `require` internally
  767. * @experimental
  768. */
  769. needsInterop?: string[];
  770. /**
  771. * Options to pass to esbuild during the dep scanning and optimization
  772. *
  773. * Certain options are omitted since changing them would not be compatible
  774. * with Vite's dep optimization.
  775. *
  776. * - `external` is also omitted, use Vite's `optimizeDeps.exclude` option
  777. * - `plugins` are merged with Vite's dep plugin
  778. *
  779. * https://esbuild.github.io/api
  780. */
  781. esbuildOptions?: Omit<esbuild_BuildOptions, "bundle" | "entryPoints" | "external" | "write" | "watch" | "outdir" | "outfile" | "outbase" | "outExtension" | "metafile">;
  782. /**
  783. * List of file extensions that can be optimized. A corresponding esbuild
  784. * plugin must exist to handle the specific extension.
  785. *
  786. * By default, Vite can optimize `.mjs`, `.js`, `.ts`, and `.mts` files. This option
  787. * allows specifying additional extensions.
  788. *
  789. * @experimental
  790. */
  791. extensions?: string[];
  792. /**
  793. * Deps optimization during build was removed in Vite 5.1. This option is
  794. * now redundant and will be removed in a future version. Switch to using
  795. * `optimizeDeps.noDiscovery` and an empty or undefined `optimizeDeps.include`.
  796. * true or 'dev' disables the optimizer, false or 'build' leaves it enabled.
  797. * @default 'build'
  798. * @deprecated
  799. * @experimental
  800. */
  801. disabled?: boolean | "build" | "dev";
  802. /**
  803. * Automatic dependency discovery. When `noDiscovery` is true, only dependencies
  804. * listed in `include` will be optimized. The scanner isn't run for cold start
  805. * in this case. CJS-only dependencies must be present in `include` during dev.
  806. * @default false
  807. */
  808. noDiscovery?: boolean;
  809. /**
  810. * When enabled, it will hold the first optimized deps results until all static
  811. * imports are crawled on cold start. This avoids the need for full-page reloads
  812. * when new dependencies are discovered and they trigger the generation of new
  813. * common chunks. If all dependencies are found by the scanner plus the explicitly
  814. * defined ones in `include`, it is better to disable this option to let the
  815. * browser process more requests in parallel.
  816. * @default true
  817. * @experimental
  818. */
  819. holdUntilCrawlEnd?: boolean;
  820. /**
  821. * When enabled, Vite will not throw an error when an outdated optimized
  822. * dependency is requested. Enabling this option may cause a single module
  823. * to have a multiple reference.
  824. * @default false
  825. * @experimental
  826. */
  827. ignoreOutdatedRequests?: boolean;
  828. }
  829. type DepOptimizationOptions = DepOptimizationConfig & {
  830. /**
  831. * By default, Vite will crawl your `index.html` to detect dependencies that
  832. * need to be pre-bundled. If `build.rollupOptions.input` is specified, Vite
  833. * will crawl those entry points instead.
  834. *
  835. * If neither of these fit your needs, you can specify custom entries using
  836. * this option - the value should be a tinyglobby pattern or array of patterns
  837. * (https://github.com/SuperchupuDev/tinyglobby) that are relative from
  838. * vite project root. This will overwrite default entries inference.
  839. */
  840. entries?: string | string[];
  841. /**
  842. * Force dep pre-optimization regardless of whether deps have changed.
  843. * @experimental
  844. */
  845. force?: boolean;
  846. };
  847. interface OptimizedDepInfo {
  848. id: string;
  849. file: string;
  850. src?: string;
  851. needsInterop?: boolean;
  852. browserHash?: string;
  853. fileHash?: string;
  854. /**
  855. * During optimization, ids can still be resolved to their final location
  856. * but the bundles may not yet be saved to disk
  857. */
  858. processing?: Promise<void>;
  859. /**
  860. * ExportData cache, discovered deps will parse the src entry to get exports
  861. * data used both to define if interop is needed and when pre-bundling
  862. */
  863. exportsData?: Promise<ExportsData>;
  864. }
  865. interface DepOptimizationMetadata {
  866. /**
  867. * The main hash is determined by user config and dependency lockfiles.
  868. * This is checked on server startup to avoid unnecessary re-bundles.
  869. */
  870. hash: string;
  871. /**
  872. * This hash is determined by dependency lockfiles.
  873. * This is checked on server startup to avoid unnecessary re-bundles.
  874. */
  875. lockfileHash: string;
  876. /**
  877. * This hash is determined by user config.
  878. * This is checked on server startup to avoid unnecessary re-bundles.
  879. */
  880. configHash: string;
  881. /**
  882. * The browser hash is determined by the main hash plus additional dependencies
  883. * discovered at runtime. This is used to invalidate browser requests to
  884. * optimized deps.
  885. */
  886. browserHash: string;
  887. /**
  888. * Metadata for each already optimized dependency
  889. */
  890. optimized: Record<string, OptimizedDepInfo>;
  891. /**
  892. * Metadata for non-entry optimized chunks and dynamic imports
  893. */
  894. chunks: Record<string, OptimizedDepInfo>;
  895. /**
  896. * Metadata for each newly discovered dependency after processing
  897. */
  898. discovered: Record<string, OptimizedDepInfo>;
  899. /**
  900. * OptimizedDepInfo list
  901. */
  902. depInfoList: OptimizedDepInfo[];
  903. }
  904. /**
  905. * Scan and optimize dependencies within a project.
  906. * Used by Vite CLI when running `vite optimize`.
  907. *
  908. * @deprecated the optimization process runs automatically and does not need to be called
  909. */
  910. declare function optimizeDeps(config: ResolvedConfig, force?: boolean | undefined, asCommand?: boolean): Promise<DepOptimizationMetadata>;
  911. //#endregion
  912. //#region src/node/server/transformRequest.d.ts
  913. interface TransformResult {
  914. code: string;
  915. map: SourceMap | {
  916. mappings: "";
  917. } | null;
  918. ssr?: boolean;
  919. etag?: string;
  920. deps?: string[];
  921. dynamicDeps?: string[];
  922. }
  923. interface TransformOptions {
  924. /**
  925. * @deprecated inferred from environment
  926. */
  927. ssr?: boolean;
  928. }
  929. interface TransformOptionsInternal {}
  930. //#endregion
  931. //#region src/node/server/moduleGraph.d.ts
  932. declare class EnvironmentModuleNode {
  933. environment: string;
  934. /**
  935. * Public served url path, starts with /
  936. */
  937. url: string;
  938. /**
  939. * Resolved file system path + query
  940. */
  941. id: string | null;
  942. file: string | null;
  943. type: "js" | "css" | "asset";
  944. info?: ModuleInfo;
  945. meta?: Record<string, any>;
  946. importers: Set<EnvironmentModuleNode>;
  947. importedModules: Set<EnvironmentModuleNode>;
  948. acceptedHmrDeps: Set<EnvironmentModuleNode>;
  949. acceptedHmrExports: Set<string> | null;
  950. importedBindings: Map<string, Set<string>> | null;
  951. isSelfAccepting?: boolean;
  952. transformResult: TransformResult | null;
  953. ssrModule: Record<string, any> | null;
  954. ssrError: Error | null;
  955. lastHMRTimestamp: number;
  956. lastInvalidationTimestamp: number;
  957. /**
  958. * @param setIsSelfAccepting - set `false` to set `isSelfAccepting` later. e.g. #7870
  959. */
  960. constructor(url: string, environment: string, setIsSelfAccepting?: boolean);
  961. }
  962. type ResolvedUrl = [url: string, resolvedId: string, meta: object | null | undefined];
  963. declare class EnvironmentModuleGraph {
  964. environment: string;
  965. urlToModuleMap: Map<string, EnvironmentModuleNode>;
  966. idToModuleMap: Map<string, EnvironmentModuleNode>;
  967. etagToModuleMap: Map<string, EnvironmentModuleNode>;
  968. fileToModulesMap: Map<string, Set<EnvironmentModuleNode>>;
  969. constructor(environment: string, resolveId: (url: string) => Promise<PartialResolvedId | null>);
  970. getModuleByUrl(rawUrl: string): Promise<EnvironmentModuleNode | undefined>;
  971. getModuleById(id: string): EnvironmentModuleNode | undefined;
  972. getModulesByFile(file: string): Set<EnvironmentModuleNode> | undefined;
  973. onFileChange(file: string): void;
  974. onFileDelete(file: string): void;
  975. invalidateModule(mod: EnvironmentModuleNode, seen?: Set<EnvironmentModuleNode>, timestamp?: number, isHmr?: boolean, softInvalidate?: boolean): void;
  976. invalidateAll(): void;
  977. /**
  978. * Update the module graph based on a module's updated imports information
  979. * If there are dependencies that no longer have any importers, they are
  980. * returned as a Set.
  981. *
  982. * @param staticImportedUrls Subset of `importedModules` where they're statically imported in code.
  983. * This is only used for soft invalidations so `undefined` is fine but may cause more runtime processing.
  984. */
  985. updateModuleInfo(mod: EnvironmentModuleNode, importedModules: Set<string | EnvironmentModuleNode>, importedBindings: Map<string, Set<string>> | null, acceptedModules: Set<string | EnvironmentModuleNode>, acceptedExports: Set<string> | null, isSelfAccepting: boolean, staticImportedUrls?: Set<string>): Promise<Set<EnvironmentModuleNode> | undefined>;
  986. ensureEntryFromUrl(rawUrl: string, setIsSelfAccepting?: boolean): Promise<EnvironmentModuleNode>;
  987. createFileOnlyEntry(file: string): EnvironmentModuleNode;
  988. resolveUrl(url: string): Promise<ResolvedUrl>;
  989. updateModuleTransformResult(mod: EnvironmentModuleNode, result: TransformResult | null): void;
  990. getModuleByEtag(etag: string): EnvironmentModuleNode | undefined;
  991. }
  992. //#endregion
  993. //#region src/node/server/mixedModuleGraph.d.ts
  994. declare class ModuleNode {
  995. _moduleGraph: ModuleGraph;
  996. _clientModule: EnvironmentModuleNode | undefined;
  997. _ssrModule: EnvironmentModuleNode | undefined;
  998. constructor(moduleGraph: ModuleGraph, clientModule?: EnvironmentModuleNode, ssrModule?: EnvironmentModuleNode);
  999. _get<T$1 extends keyof EnvironmentModuleNode>(prop: T$1): EnvironmentModuleNode[T$1];
  1000. _set<T$1 extends keyof EnvironmentModuleNode>(prop: T$1, value: EnvironmentModuleNode[T$1]): void;
  1001. _wrapModuleSet(prop: ModuleSetNames, module: EnvironmentModuleNode | undefined): Set<ModuleNode>;
  1002. _getModuleSetUnion(prop: "importedModules" | "importers"): Set<ModuleNode>;
  1003. _getModuleInfoUnion(prop: "info"): ModuleInfo | undefined;
  1004. _getModuleObjectUnion(prop: "meta"): Record<string, any> | undefined;
  1005. get url(): string;
  1006. set url(value: string);
  1007. get id(): string | null;
  1008. set id(value: string | null);
  1009. get file(): string | null;
  1010. set file(value: string | null);
  1011. get type(): "js" | "css" | "asset";
  1012. get info(): ModuleInfo | undefined;
  1013. get meta(): Record<string, any> | undefined;
  1014. get importers(): Set<ModuleNode>;
  1015. get clientImportedModules(): Set<ModuleNode>;
  1016. get ssrImportedModules(): Set<ModuleNode>;
  1017. get importedModules(): Set<ModuleNode>;
  1018. get acceptedHmrDeps(): Set<ModuleNode>;
  1019. get acceptedHmrExports(): Set<string> | null;
  1020. get importedBindings(): Map<string, Set<string>> | null;
  1021. get isSelfAccepting(): boolean | undefined;
  1022. get transformResult(): TransformResult | null;
  1023. set transformResult(value: TransformResult | null);
  1024. get ssrTransformResult(): TransformResult | null;
  1025. set ssrTransformResult(value: TransformResult | null);
  1026. get ssrModule(): Record<string, any> | null;
  1027. get ssrError(): Error | null;
  1028. get lastHMRTimestamp(): number;
  1029. set lastHMRTimestamp(value: number);
  1030. get lastInvalidationTimestamp(): number;
  1031. get invalidationState(): TransformResult | "HARD_INVALIDATED" | undefined;
  1032. get ssrInvalidationState(): TransformResult | "HARD_INVALIDATED" | undefined;
  1033. }
  1034. declare class ModuleGraph {
  1035. urlToModuleMap: Map<string, ModuleNode>;
  1036. idToModuleMap: Map<string, ModuleNode>;
  1037. etagToModuleMap: Map<string, ModuleNode>;
  1038. fileToModulesMap: Map<string, Set<ModuleNode>>;
  1039. private moduleNodeCache;
  1040. constructor(moduleGraphs: {
  1041. client: () => EnvironmentModuleGraph;
  1042. ssr: () => EnvironmentModuleGraph;
  1043. });
  1044. getModuleById(id: string): ModuleNode | undefined;
  1045. getModuleByUrl(url: string, _ssr?: boolean): Promise<ModuleNode | undefined>;
  1046. getModulesByFile(file: string): Set<ModuleNode> | undefined;
  1047. onFileChange(file: string): void;
  1048. onFileDelete(file: string): void;
  1049. invalidateModule(mod: ModuleNode, seen?: Set<ModuleNode>, timestamp?: number, isHmr?: boolean, softInvalidate?: boolean): void;
  1050. invalidateAll(): void;
  1051. ensureEntryFromUrl(rawUrl: string, ssr?: boolean, setIsSelfAccepting?: boolean): Promise<ModuleNode>;
  1052. createFileOnlyEntry(file: string): ModuleNode;
  1053. resolveUrl(url: string, ssr?: boolean): Promise<ResolvedUrl>;
  1054. updateModuleTransformResult(mod: ModuleNode, result: TransformResult | null, ssr?: boolean): void;
  1055. getModuleByEtag(etag: string): ModuleNode | undefined;
  1056. getBackwardCompatibleBrowserModuleNode(clientModule: EnvironmentModuleNode): ModuleNode;
  1057. getBackwardCompatibleServerModuleNode(ssrModule: EnvironmentModuleNode): ModuleNode;
  1058. getBackwardCompatibleModuleNode(mod: EnvironmentModuleNode): ModuleNode;
  1059. getBackwardCompatibleModuleNodeDual(clientModule?: EnvironmentModuleNode, ssrModule?: EnvironmentModuleNode): ModuleNode;
  1060. }
  1061. type ModuleSetNames = "acceptedHmrDeps" | "importedModules";
  1062. //#endregion
  1063. //#region src/node/server/hmr.d.ts
  1064. interface HmrOptions {
  1065. protocol?: string;
  1066. host?: string;
  1067. port?: number;
  1068. clientPort?: number;
  1069. path?: string;
  1070. timeout?: number;
  1071. overlay?: boolean;
  1072. server?: HttpServer;
  1073. }
  1074. interface HotUpdateOptions {
  1075. type: "create" | "update" | "delete";
  1076. file: string;
  1077. timestamp: number;
  1078. modules: Array<EnvironmentModuleNode>;
  1079. read: () => string | Promise<string>;
  1080. server: ViteDevServer;
  1081. }
  1082. interface HmrContext {
  1083. file: string;
  1084. timestamp: number;
  1085. modules: Array<ModuleNode>;
  1086. read: () => string | Promise<string>;
  1087. server: ViteDevServer;
  1088. }
  1089. interface HotChannelClient {
  1090. send(payload: hmrPayload_HotPayload): void;
  1091. }
  1092. type HotChannelListener<T$1 extends string = string> = (data: InferCustomEventPayload<T$1>, client: HotChannelClient) => void;
  1093. interface HotChannel<Api = any> {
  1094. /**
  1095. * Broadcast events to all clients
  1096. */
  1097. send?(payload: hmrPayload_HotPayload): void;
  1098. /**
  1099. * Handle custom event emitted by `import.meta.hot.send`
  1100. */
  1101. on?<T$1 extends string>(event: T$1, listener: HotChannelListener<T$1>): void;
  1102. on?(event: "connection", listener: () => void): void;
  1103. /**
  1104. * Unregister event listener
  1105. */
  1106. off?(event: string, listener: Function): void;
  1107. /**
  1108. * Start listening for messages
  1109. */
  1110. listen?(): void;
  1111. /**
  1112. * Disconnect all clients, called when server is closed or restarted.
  1113. */
  1114. close?(): Promise<unknown> | void;
  1115. api?: Api;
  1116. }
  1117. interface NormalizedHotChannelClient {
  1118. /**
  1119. * Send event to the client
  1120. */
  1121. send(payload: hmrPayload_HotPayload): void;
  1122. /**
  1123. * Send custom event
  1124. */
  1125. send(event: string, payload?: hmrPayload_CustomPayload["data"]): void;
  1126. }
  1127. interface NormalizedHotChannel<Api = any> {
  1128. /**
  1129. * Broadcast events to all clients
  1130. */
  1131. send(payload: hmrPayload_HotPayload): void;
  1132. /**
  1133. * Send custom event
  1134. */
  1135. send<T$1 extends string>(event: T$1, payload?: InferCustomEventPayload<T$1>): void;
  1136. /**
  1137. * Handle custom event emitted by `import.meta.hot.send`
  1138. */
  1139. on<T$1 extends string>(event: T$1, listener: (data: InferCustomEventPayload<T$1>, client: NormalizedHotChannelClient) => void): void;
  1140. /**
  1141. * @deprecated use `vite:client:connect` event instead
  1142. */
  1143. on(event: "connection", listener: () => void): void;
  1144. /**
  1145. * Unregister event listener
  1146. */
  1147. off(event: string, listener: Function): void;
  1148. handleInvoke(payload: hmrPayload_HotPayload): Promise<{
  1149. result: any;
  1150. } | {
  1151. error: any;
  1152. }>;
  1153. /**
  1154. * Start listening for messages
  1155. */
  1156. listen(): void;
  1157. /**
  1158. * Disconnect all clients, called when server is closed or restarted.
  1159. */
  1160. close(): Promise<unknown> | void;
  1161. api?: Api;
  1162. }
  1163. type ServerHotChannelApi = {
  1164. innerEmitter: EventEmitter;
  1165. outsideEmitter: EventEmitter;
  1166. };
  1167. type ServerHotChannel = HotChannel<ServerHotChannelApi>;
  1168. type NormalizedServerHotChannel = NormalizedHotChannel<ServerHotChannelApi>;
  1169. declare function createServerHotChannel(): ServerHotChannel;
  1170. //#endregion
  1171. //#region src/types/ws.d.ts
  1172. // WebSocket socket.
  1173. declare class WebSocket extends EventEmitter {
  1174. /** The connection is not yet open. */
  1175. static readonly CONNECTING: 0;
  1176. /** The connection is open and ready to communicate. */
  1177. static readonly OPEN: 1;
  1178. /** The connection is in the process of closing. */
  1179. static readonly CLOSING: 2;
  1180. /** The connection is closed. */
  1181. static readonly CLOSED: 3;
  1182. binaryType: 'nodebuffer' | 'arraybuffer' | 'fragments';
  1183. readonly bufferedAmount: number;
  1184. readonly extensions: string;
  1185. /** Indicates whether the websocket is paused */
  1186. readonly isPaused: boolean;
  1187. readonly protocol: string;
  1188. /** The current state of the connection */
  1189. readonly readyState: typeof WebSocket.CONNECTING | typeof WebSocket.OPEN | typeof WebSocket.CLOSING | typeof WebSocket.CLOSED;
  1190. readonly url: string;
  1191. /** The connection is not yet open. */
  1192. readonly CONNECTING: 0;
  1193. /** The connection is open and ready to communicate. */
  1194. readonly OPEN: 1;
  1195. /** The connection is in the process of closing. */
  1196. readonly CLOSING: 2;
  1197. /** The connection is closed. */
  1198. readonly CLOSED: 3;
  1199. onopen: ((event: WebSocket.Event) => void) | null;
  1200. onerror: ((event: WebSocket.ErrorEvent) => void) | null;
  1201. onclose: ((event: WebSocket.CloseEvent) => void) | null;
  1202. onmessage: ((event: WebSocket.MessageEvent) => void) | null;
  1203. constructor(address: null);
  1204. constructor(address: string | url_URL, options?: WebSocket.ClientOptions | ClientRequestArgs);
  1205. constructor(address: string | url_URL, protocols?: string | string[], options?: WebSocket.ClientOptions | ClientRequestArgs);
  1206. close(code?: number, data?: string | Buffer): void;
  1207. ping(data?: any, mask?: boolean, cb?: (err: Error) => void): void;
  1208. pong(data?: any, mask?: boolean, cb?: (err: Error) => void): void;
  1209. send(data: any, cb?: (err?: Error) => void): void;
  1210. send(data: any, options: {
  1211. mask?: boolean | undefined;
  1212. binary?: boolean | undefined;
  1213. compress?: boolean | undefined;
  1214. fin?: boolean | undefined;
  1215. }, cb?: (err?: Error) => void): void;
  1216. terminate(): void;
  1217. /**
  1218. * Pause the websocket causing it to stop emitting events. Some events can still be
  1219. * emitted after this is called, until all buffered data is consumed. This method
  1220. * is a noop if the ready state is `CONNECTING` or `CLOSED`.
  1221. */
  1222. pause(): void;
  1223. /**
  1224. * Make a paused socket resume emitting events. This method is a noop if the ready
  1225. * state is `CONNECTING` or `CLOSED`.
  1226. */
  1227. resume(): void;
  1228. // HTML5 WebSocket events
  1229. addEventListener(method: 'message', cb: (event: WebSocket.MessageEvent) => void, options?: WebSocket.EventListenerOptions): void;
  1230. addEventListener(method: 'close', cb: (event: WebSocket.CloseEvent) => void, options?: WebSocket.EventListenerOptions): void;
  1231. addEventListener(method: 'error', cb: (event: WebSocket.ErrorEvent) => void, options?: WebSocket.EventListenerOptions): void;
  1232. addEventListener(method: 'open', cb: (event: WebSocket.Event) => void, options?: WebSocket.EventListenerOptions): void;
  1233. removeEventListener(method: 'message', cb: (event: WebSocket.MessageEvent) => void): void;
  1234. removeEventListener(method: 'close', cb: (event: WebSocket.CloseEvent) => void): void;
  1235. removeEventListener(method: 'error', cb: (event: WebSocket.ErrorEvent) => void): void;
  1236. removeEventListener(method: 'open', cb: (event: WebSocket.Event) => void): void;
  1237. // Events
  1238. on(event: 'close', listener: (this: WebSocket, code: number, reason: Buffer) => void): this;
  1239. on(event: 'error', listener: (this: WebSocket, err: Error) => void): this;
  1240. on(event: 'upgrade', listener: (this: WebSocket, request: http.IncomingMessage) => void): this;
  1241. on(event: 'message', listener: (this: WebSocket, data: WebSocket.RawData, isBinary: boolean) => void): this;
  1242. on(event: 'open', listener: (this: WebSocket) => void): this;
  1243. on(event: 'ping' | 'pong', listener: (this: WebSocket, data: Buffer) => void): this;
  1244. on(event: 'unexpected-response', listener: (this: WebSocket, request: ClientRequest, response: http.IncomingMessage) => void): this;
  1245. on(event: string | symbol, listener: (this: WebSocket, ...args: any[]) => void): this;
  1246. once(event: 'close', listener: (this: WebSocket, code: number, reason: Buffer) => void): this;
  1247. once(event: 'error', listener: (this: WebSocket, err: Error) => void): this;
  1248. once(event: 'upgrade', listener: (this: WebSocket, request: http.IncomingMessage) => void): this;
  1249. once(event: 'message', listener: (this: WebSocket, data: WebSocket.RawData, isBinary: boolean) => void): this;
  1250. once(event: 'open', listener: (this: WebSocket) => void): this;
  1251. once(event: 'ping' | 'pong', listener: (this: WebSocket, data: Buffer) => void): this;
  1252. once(event: 'unexpected-response', listener: (this: WebSocket, request: ClientRequest, response: http.IncomingMessage) => void): this;
  1253. once(event: string | symbol, listener: (this: WebSocket, ...args: any[]) => void): this;
  1254. off(event: 'close', listener: (this: WebSocket, code: number, reason: Buffer) => void): this;
  1255. off(event: 'error', listener: (this: WebSocket, err: Error) => void): this;
  1256. off(event: 'upgrade', listener: (this: WebSocket, request: http.IncomingMessage) => void): this;
  1257. off(event: 'message', listener: (this: WebSocket, data: WebSocket.RawData, isBinary: boolean) => void): this;
  1258. off(event: 'open', listener: (this: WebSocket) => void): this;
  1259. off(event: 'ping' | 'pong', listener: (this: WebSocket, data: Buffer) => void): this;
  1260. off(event: 'unexpected-response', listener: (this: WebSocket, request: ClientRequest, response: http.IncomingMessage) => void): this;
  1261. off(event: string | symbol, listener: (this: WebSocket, ...args: any[]) => void): this;
  1262. addListener(event: 'close', listener: (code: number, reason: Buffer) => void): this;
  1263. addListener(event: 'error', listener: (err: Error) => void): this;
  1264. addListener(event: 'upgrade', listener: (request: http.IncomingMessage) => void): this;
  1265. addListener(event: 'message', listener: (data: WebSocket.RawData, isBinary: boolean) => void): this;
  1266. addListener(event: 'open', listener: () => void): this;
  1267. addListener(event: 'ping' | 'pong', listener: (data: Buffer) => void): this;
  1268. addListener(event: 'unexpected-response', listener: (request: ClientRequest, response: http.IncomingMessage) => void): this;
  1269. addListener(event: string | symbol, listener: (...args: any[]) => void): this;
  1270. removeListener(event: 'close', listener: (code: number, reason: Buffer) => void): this;
  1271. removeListener(event: 'error', listener: (err: Error) => void): this;
  1272. removeListener(event: 'upgrade', listener: (request: http.IncomingMessage) => void): this;
  1273. removeListener(event: 'message', listener: (data: WebSocket.RawData, isBinary: boolean) => void): this;
  1274. removeListener(event: 'open', listener: () => void): this;
  1275. removeListener(event: 'ping' | 'pong', listener: (data: Buffer) => void): this;
  1276. removeListener(event: 'unexpected-response', listener: (request: ClientRequest, response: http.IncomingMessage) => void): this;
  1277. removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
  1278. }
  1279. declare const WebSocketAlias: typeof WebSocket;
  1280. interface WebSocketAlias extends WebSocket {}
  1281. declare namespace WebSocket {
  1282. /**
  1283. * Data represents the raw message payload received over the WebSocket.
  1284. */
  1285. type RawData = Buffer | ArrayBuffer | Buffer[];
  1286. /**
  1287. * Data represents the message payload received over the WebSocket.
  1288. */
  1289. type Data = string | Buffer | ArrayBuffer | Buffer[];
  1290. /**
  1291. * CertMeta represents the accepted types for certificate & key data.
  1292. */
  1293. type CertMeta = string | string[] | Buffer | Buffer[];
  1294. /**
  1295. * VerifyClientCallbackSync is a synchronous callback used to inspect the
  1296. * incoming message. The return value (boolean) of the function determines
  1297. * whether or not to accept the handshake.
  1298. */
  1299. type VerifyClientCallbackSync = (info: {
  1300. origin: string;
  1301. secure: boolean;
  1302. req: http.IncomingMessage;
  1303. }) => boolean;
  1304. /**
  1305. * VerifyClientCallbackAsync is an asynchronous callback used to inspect the
  1306. * incoming message. The return value (boolean) of the function determines
  1307. * whether or not to accept the handshake.
  1308. */
  1309. type VerifyClientCallbackAsync = (info: {
  1310. origin: string;
  1311. secure: boolean;
  1312. req: http.IncomingMessage;
  1313. }, callback: (res: boolean, code?: number, message?: string, headers?: OutgoingHttpHeaders) => void) => void;
  1314. interface ClientOptions extends SecureContextOptions {
  1315. protocol?: string | undefined;
  1316. followRedirects?: boolean | undefined;
  1317. generateMask?(mask: Buffer): void;
  1318. handshakeTimeout?: number | undefined;
  1319. maxRedirects?: number | undefined;
  1320. perMessageDeflate?: boolean | PerMessageDeflateOptions | undefined;
  1321. localAddress?: string | undefined;
  1322. protocolVersion?: number | undefined;
  1323. headers?: {
  1324. [key: string]: string;
  1325. } | undefined;
  1326. origin?: string | undefined;
  1327. agent?: Agent | undefined;
  1328. host?: string | undefined;
  1329. family?: number | undefined;
  1330. checkServerIdentity?(servername: string, cert: CertMeta): boolean;
  1331. rejectUnauthorized?: boolean | undefined;
  1332. maxPayload?: number | undefined;
  1333. skipUTF8Validation?: boolean | undefined;
  1334. }
  1335. interface PerMessageDeflateOptions {
  1336. serverNoContextTakeover?: boolean | undefined;
  1337. clientNoContextTakeover?: boolean | undefined;
  1338. serverMaxWindowBits?: number | undefined;
  1339. clientMaxWindowBits?: number | undefined;
  1340. zlibDeflateOptions?: {
  1341. flush?: number | undefined;
  1342. finishFlush?: number | undefined;
  1343. chunkSize?: number | undefined;
  1344. windowBits?: number | undefined;
  1345. level?: number | undefined;
  1346. memLevel?: number | undefined;
  1347. strategy?: number | undefined;
  1348. dictionary?: Buffer | Buffer[] | DataView | undefined;
  1349. info?: boolean | undefined;
  1350. } | undefined;
  1351. zlibInflateOptions?: ZlibOptions | undefined;
  1352. threshold?: number | undefined;
  1353. concurrencyLimit?: number | undefined;
  1354. }
  1355. interface Event {
  1356. type: string;
  1357. target: WebSocket;
  1358. }
  1359. interface ErrorEvent {
  1360. error: any;
  1361. message: string;
  1362. type: string;
  1363. target: WebSocket;
  1364. }
  1365. interface CloseEvent {
  1366. wasClean: boolean;
  1367. code: number;
  1368. reason: string;
  1369. type: string;
  1370. target: WebSocket;
  1371. }
  1372. interface MessageEvent {
  1373. data: Data;
  1374. type: string;
  1375. target: WebSocket;
  1376. }
  1377. interface EventListenerOptions {
  1378. once?: boolean | undefined;
  1379. }
  1380. interface ServerOptions {
  1381. host?: string | undefined;
  1382. port?: number | undefined;
  1383. backlog?: number | undefined;
  1384. server?: http.Server | HttpsServer | undefined;
  1385. verifyClient?: VerifyClientCallbackAsync | VerifyClientCallbackSync | undefined;
  1386. handleProtocols?: (protocols: Set<string>, request: http.IncomingMessage) => string | false;
  1387. path?: string | undefined;
  1388. noServer?: boolean | undefined;
  1389. clientTracking?: boolean | undefined;
  1390. perMessageDeflate?: boolean | PerMessageDeflateOptions | undefined;
  1391. maxPayload?: number | undefined;
  1392. skipUTF8Validation?: boolean | undefined;
  1393. WebSocket?: typeof WebSocket.WebSocket | undefined;
  1394. }
  1395. interface AddressInfo {
  1396. address: string;
  1397. family: string;
  1398. port: number;
  1399. }
  1400. // WebSocket Server
  1401. class Server<T$1 extends WebSocket = WebSocket> extends EventEmitter {
  1402. options: ServerOptions;
  1403. path: string;
  1404. clients: Set<T$1>;
  1405. constructor(options?: ServerOptions, callback?: () => void);
  1406. address(): AddressInfo | string;
  1407. close(cb?: (err?: Error) => void): void;
  1408. handleUpgrade(request: http.IncomingMessage, socket: Duplex, upgradeHead: Buffer, callback: (client: T$1, request: http.IncomingMessage) => void): void;
  1409. shouldHandle(request: http.IncomingMessage): boolean | Promise<boolean>;
  1410. // Events
  1411. on(event: 'connection', cb: (this: Server<T$1>, socket: T$1, request: http.IncomingMessage) => void): this;
  1412. on(event: 'error', cb: (this: Server<T$1>, error: Error) => void): this;
  1413. on(event: 'headers', cb: (this: Server<T$1>, headers: string[], request: http.IncomingMessage) => void): this;
  1414. on(event: 'close' | 'listening', cb: (this: Server<T$1>) => void): this;
  1415. on(event: string | symbol, listener: (this: Server<T$1>, ...args: any[]) => void): this;
  1416. once(event: 'connection', cb: (this: Server<T$1>, socket: T$1, request: http.IncomingMessage) => void): this;
  1417. once(event: 'error', cb: (this: Server<T$1>, error: Error) => void): this;
  1418. once(event: 'headers', cb: (this: Server<T$1>, headers: string[], request: http.IncomingMessage) => void): this;
  1419. once(event: 'close' | 'listening', cb: (this: Server<T$1>) => void): this;
  1420. once(event: string | symbol, listener: (this: Server<T$1>, ...args: any[]) => void): this;
  1421. off(event: 'connection', cb: (this: Server<T$1>, socket: T$1, request: http.IncomingMessage) => void): this;
  1422. off(event: 'error', cb: (this: Server<T$1>, error: Error) => void): this;
  1423. off(event: 'headers', cb: (this: Server<T$1>, headers: string[], request: http.IncomingMessage) => void): this;
  1424. off(event: 'close' | 'listening', cb: (this: Server<T$1>) => void): this;
  1425. off(event: string | symbol, listener: (this: Server<T$1>, ...args: any[]) => void): this;
  1426. addListener(event: 'connection', cb: (client: T$1, request: http.IncomingMessage) => void): this;
  1427. addListener(event: 'error', cb: (err: Error) => void): this;
  1428. addListener(event: 'headers', cb: (headers: string[], request: http.IncomingMessage) => void): this;
  1429. addListener(event: 'close' | 'listening', cb: () => void): this;
  1430. addListener(event: string | symbol, listener: (...args: any[]) => void): this;
  1431. removeListener(event: 'connection', cb: (client: T$1) => void): this;
  1432. removeListener(event: 'error', cb: (err: Error) => void): this;
  1433. removeListener(event: 'headers', cb: (headers: string[], request: http.IncomingMessage) => void): this;
  1434. removeListener(event: 'close' | 'listening', cb: () => void): this;
  1435. removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
  1436. }
  1437. const WebSocketServer: typeof Server;
  1438. interface WebSocketServer extends Server {}
  1439. const WebSocket: typeof WebSocketAlias;
  1440. interface WebSocket extends WebSocketAlias {}
  1441. // WebSocket stream
  1442. function createWebSocketStream(websocket: WebSocket, options?: DuplexOptions): Duplex;
  1443. }
  1444. // export = WebSocket
  1445. //#endregion
  1446. //#region src/node/server/ws.d.ts
  1447. type WebSocketCustomListener<T$1> = (data: T$1, client: WebSocketClient) => void;
  1448. declare const isWebSocketServer: unique symbol;
  1449. interface WebSocketServer extends NormalizedHotChannel {
  1450. /**
  1451. * Handle custom event emitted by `import.meta.hot.send`
  1452. */
  1453. on: WebSocket.Server["on"] & {
  1454. <T$1 extends string>(event: T$1, listener: WebSocketCustomListener<hmrPayload_InferCustomEventPayload<T$1>>): void;
  1455. };
  1456. /**
  1457. * Unregister event listener.
  1458. */
  1459. off: WebSocket.Server["off"] & {
  1460. (event: string, listener: Function): void;
  1461. };
  1462. /**
  1463. * Listen on port and host
  1464. */
  1465. listen(): void;
  1466. /**
  1467. * Disconnect all clients and terminate the server.
  1468. */
  1469. close(): Promise<void>;
  1470. [isWebSocketServer]: true;
  1471. /**
  1472. * Get all connected clients.
  1473. */
  1474. clients: Set<WebSocketClient>;
  1475. }
  1476. interface WebSocketClient extends NormalizedHotChannelClient {
  1477. /**
  1478. * The raw WebSocket instance
  1479. * @advanced
  1480. */
  1481. socket: WebSocket;
  1482. }
  1483. //#endregion
  1484. //#region src/node/server/environment.d.ts
  1485. interface DevEnvironmentContext {
  1486. hot: boolean;
  1487. transport?: HotChannel | WebSocketServer;
  1488. options?: EnvironmentOptions;
  1489. remoteRunner?: {
  1490. inlineSourceMap?: boolean;
  1491. };
  1492. depsOptimizer?: DepsOptimizer;
  1493. }
  1494. declare class DevEnvironment extends BaseEnvironment {
  1495. mode: "dev";
  1496. moduleGraph: EnvironmentModuleGraph;
  1497. depsOptimizer?: DepsOptimizer;
  1498. get pluginContainer(): EnvironmentPluginContainer<DevEnvironment>;
  1499. /**
  1500. * Hot channel for this environment. If not provided or disabled,
  1501. * it will be a noop channel that does nothing.
  1502. *
  1503. * @example
  1504. * environment.hot.send({ type: 'full-reload' })
  1505. */
  1506. hot: NormalizedHotChannel;
  1507. constructor(name: string, config: ResolvedConfig, context: DevEnvironmentContext);
  1508. init(options?: {
  1509. watcher?: FSWatcher;
  1510. /**
  1511. * the previous instance used for the environment with the same name
  1512. *
  1513. * when using, the consumer should check if it's an instance generated from the same class or factory function
  1514. */
  1515. previousInstance?: DevEnvironment;
  1516. }): Promise<void>;
  1517. /**
  1518. * When the dev server is restarted, the methods are called in the following order:
  1519. * - new instance `init`
  1520. * - previous instance `close`
  1521. * - new instance `listen`
  1522. */
  1523. listen(server: ViteDevServer): Promise<void>;
  1524. fetchModule(id: string, importer?: string, options?: FetchFunctionOptions): Promise<moduleRunner_FetchResult>;
  1525. reloadModule(module: EnvironmentModuleNode): Promise<void>;
  1526. transformRequest(url: string, options?: TransformOptionsInternal): Promise<TransformResult | null>;
  1527. warmupRequest(url: string): Promise<void>;
  1528. close(): Promise<void>;
  1529. /**
  1530. * Calling `await environment.waitForRequestsIdle(id)` will wait until all static imports
  1531. * are processed after the first transformRequest call. If called from a load or transform
  1532. * plugin hook, the id needs to be passed as a parameter to avoid deadlocks.
  1533. * Calling this function after the first static imports section of the module graph has been
  1534. * processed will resolve immediately.
  1535. * @experimental
  1536. */
  1537. waitForRequestsIdle(ignoredId?: string): Promise<void>;
  1538. }
  1539. //#endregion
  1540. //#region src/types/commonjs.d.ts
  1541. interface RollupCommonJSOptions {
  1542. /**
  1543. * A minimatch pattern, or array of patterns, which specifies the files in
  1544. * the build the plugin should operate on. By default, all files with
  1545. * extension `".cjs"` or those in `extensions` are included, but you can
  1546. * narrow this list by only including specific files. These files will be
  1547. * analyzed and transpiled if either the analysis does not find ES module
  1548. * specific statements or `transformMixedEsModules` is `true`.
  1549. * @default undefined
  1550. */
  1551. include?: string | RegExp | readonly (string | RegExp)[];
  1552. /**
  1553. * A minimatch pattern, or array of patterns, which specifies the files in
  1554. * the build the plugin should _ignore_. By default, all files with
  1555. * extensions other than those in `extensions` or `".cjs"` are ignored, but you
  1556. * can exclude additional files. See also the `include` option.
  1557. * @default undefined
  1558. */
  1559. exclude?: string | RegExp | readonly (string | RegExp)[];
  1560. /**
  1561. * For extensionless imports, search for extensions other than .js in the
  1562. * order specified. Note that you need to make sure that non-JavaScript files
  1563. * are transpiled by another plugin first.
  1564. * @default [ '.js' ]
  1565. */
  1566. extensions?: ReadonlyArray<string>;
  1567. /**
  1568. * If true then uses of `global` won't be dealt with by this plugin
  1569. * @default false
  1570. */
  1571. ignoreGlobal?: boolean;
  1572. /**
  1573. * If false, skips source map generation for CommonJS modules. This will
  1574. * improve performance.
  1575. * @default true
  1576. */
  1577. sourceMap?: boolean;
  1578. /**
  1579. * Some `require` calls cannot be resolved statically to be translated to
  1580. * imports.
  1581. * When this option is set to `false`, the generated code will either
  1582. * directly throw an error when such a call is encountered or, when
  1583. * `dynamicRequireTargets` is used, when such a call cannot be resolved with a
  1584. * configured dynamic require target.
  1585. * Setting this option to `true` will instead leave the `require` call in the
  1586. * code or use it as a fallback for `dynamicRequireTargets`.
  1587. * @default false
  1588. */
  1589. ignoreDynamicRequires?: boolean;
  1590. /**
  1591. * Instructs the plugin whether to enable mixed module transformations. This
  1592. * is useful in scenarios with modules that contain a mix of ES `import`
  1593. * statements and CommonJS `require` expressions. Set to `true` if `require`
  1594. * calls should be transformed to imports in mixed modules, or `false` if the
  1595. * `require` expressions should survive the transformation. The latter can be
  1596. * important if the code contains environment detection, or you are coding
  1597. * for an environment with special treatment for `require` calls such as
  1598. * ElectronJS. See also the `ignore` option.
  1599. * @default false
  1600. */
  1601. transformMixedEsModules?: boolean;
  1602. /**
  1603. * By default, this plugin will try to hoist `require` statements as imports
  1604. * to the top of each file. While this works well for many code bases and
  1605. * allows for very efficient ESM output, it does not perfectly capture
  1606. * CommonJS semantics as the order of side effects like log statements may
  1607. * change. But it is especially problematic when there are circular `require`
  1608. * calls between CommonJS modules as those often rely on the lazy execution of
  1609. * nested `require` calls.
  1610. *
  1611. * Setting this option to `true` will wrap all CommonJS files in functions
  1612. * which are executed when they are required for the first time, preserving
  1613. * NodeJS semantics. Note that this can have an impact on the size and
  1614. * performance of the generated code.
  1615. *
  1616. * The default value of `"auto"` will only wrap CommonJS files when they are
  1617. * part of a CommonJS dependency cycle, e.g. an index file that is required by
  1618. * many of its dependencies. All other CommonJS files are hoisted. This is the
  1619. * recommended setting for most code bases.
  1620. *
  1621. * `false` will entirely prevent wrapping and hoist all files. This may still
  1622. * work depending on the nature of cyclic dependencies but will often cause
  1623. * problems.
  1624. *
  1625. * You can also provide a minimatch pattern, or array of patterns, to only
  1626. * specify a subset of files which should be wrapped in functions for proper
  1627. * `require` semantics.
  1628. *
  1629. * `"debug"` works like `"auto"` but after bundling, it will display a warning
  1630. * containing a list of ids that have been wrapped which can be used as
  1631. * minimatch pattern for fine-tuning.
  1632. * @default "auto"
  1633. */
  1634. strictRequires?: boolean | string | RegExp | readonly (string | RegExp)[];
  1635. /**
  1636. * Sometimes you have to leave require statements unconverted. Pass an array
  1637. * containing the IDs or a `id => boolean` function.
  1638. * @default []
  1639. */
  1640. ignore?: ReadonlyArray<string> | ((id: string) => boolean);
  1641. /**
  1642. * In most cases, where `require` calls are inside a `try-catch` clause,
  1643. * they should be left unconverted as it requires an optional dependency
  1644. * that may or may not be installed beside the rolled up package.
  1645. * Due to the conversion of `require` to a static `import` - the call is
  1646. * hoisted to the top of the file, outside the `try-catch` clause.
  1647. *
  1648. * - `true`: Default. All `require` calls inside a `try` will be left unconverted.
  1649. * - `false`: All `require` calls inside a `try` will be converted as if the
  1650. * `try-catch` clause is not there.
  1651. * - `remove`: Remove all `require` calls from inside any `try` block.
  1652. * - `string[]`: Pass an array containing the IDs to left unconverted.
  1653. * - `((id: string) => boolean|'remove')`: Pass a function that controls
  1654. * individual IDs.
  1655. *
  1656. * @default true
  1657. */
  1658. ignoreTryCatch?: boolean | 'remove' | ReadonlyArray<string> | ((id: string) => boolean | 'remove');
  1659. /**
  1660. * Controls how to render imports from external dependencies. By default,
  1661. * this plugin assumes that all external dependencies are CommonJS. This
  1662. * means they are rendered as default imports to be compatible with e.g.
  1663. * NodeJS where ES modules can only import a default export from a CommonJS
  1664. * dependency.
  1665. *
  1666. * If you set `esmExternals` to `true`, this plugin assumes that all
  1667. * external dependencies are ES modules and respect the
  1668. * `requireReturnsDefault` option. If that option is not set, they will be
  1669. * rendered as namespace imports.
  1670. *
  1671. * You can also supply an array of ids to be treated as ES modules, or a
  1672. * function that will be passed each external id to determine whether it is
  1673. * an ES module.
  1674. * @default false
  1675. */
  1676. esmExternals?: boolean | ReadonlyArray<string> | ((id: string) => boolean);
  1677. /**
  1678. * Controls what is returned when requiring an ES module from a CommonJS file.
  1679. * When using the `esmExternals` option, this will also apply to external
  1680. * modules. By default, this plugin will render those imports as namespace
  1681. * imports i.e.
  1682. *
  1683. * ```js
  1684. * // input
  1685. * const foo = require('foo');
  1686. *
  1687. * // output
  1688. * import * as foo from 'foo';
  1689. * ```
  1690. *
  1691. * However, there are some situations where this may not be desired.
  1692. * For these situations, you can change Rollup's behaviour either globally or
  1693. * per module. To change it globally, set the `requireReturnsDefault` option
  1694. * to one of the following values:
  1695. *
  1696. * - `false`: This is the default, requiring an ES module returns its
  1697. * namespace. This is the only option that will also add a marker
  1698. * `__esModule: true` to the namespace to support interop patterns in
  1699. * CommonJS modules that are transpiled ES modules.
  1700. * - `"namespace"`: Like `false`, requiring an ES module returns its
  1701. * namespace, but the plugin does not add the `__esModule` marker and thus
  1702. * creates more efficient code. For external dependencies when using
  1703. * `esmExternals: true`, no additional interop code is generated.
  1704. * - `"auto"`: This is complementary to how `output.exports: "auto"` works in
  1705. * Rollup: If a module has a default export and no named exports, requiring
  1706. * that module returns the default export. In all other cases, the namespace
  1707. * is returned. For external dependencies when using `esmExternals: true`, a
  1708. * corresponding interop helper is added.
  1709. * - `"preferred"`: If a module has a default export, requiring that module
  1710. * always returns the default export, no matter whether additional named
  1711. * exports exist. This is similar to how previous versions of this plugin
  1712. * worked. Again for external dependencies when using `esmExternals: true`,
  1713. * an interop helper is added.
  1714. * - `true`: This will always try to return the default export on require
  1715. * without checking if it actually exists. This can throw at build time if
  1716. * there is no default export. This is how external dependencies are handled
  1717. * when `esmExternals` is not used. The advantage over the other options is
  1718. * that, like `false`, this does not add an interop helper for external
  1719. * dependencies, keeping the code lean.
  1720. *
  1721. * To change this for individual modules, you can supply a function for
  1722. * `requireReturnsDefault` instead. This function will then be called once for
  1723. * each required ES module or external dependency with the corresponding id
  1724. * and allows you to return different values for different modules.
  1725. * @default false
  1726. */
  1727. requireReturnsDefault?: boolean | 'auto' | 'preferred' | 'namespace' | ((id: string) => boolean | 'auto' | 'preferred' | 'namespace');
  1728. /**
  1729. * @default "auto"
  1730. */
  1731. defaultIsModuleExports?: boolean | 'auto' | ((id: string) => boolean | 'auto');
  1732. /**
  1733. * Some modules contain dynamic `require` calls, or require modules that
  1734. * contain circular dependencies, which are not handled well by static
  1735. * imports. Including those modules as `dynamicRequireTargets` will simulate a
  1736. * CommonJS (NodeJS-like) environment for them with support for dynamic
  1737. * dependencies. It also enables `strictRequires` for those modules.
  1738. *
  1739. * Note: In extreme cases, this feature may result in some paths being
  1740. * rendered as absolute in the final bundle. The plugin tries to avoid
  1741. * exposing paths from the local machine, but if you are `dynamicRequirePaths`
  1742. * with paths that are far away from your project's folder, that may require
  1743. * replacing strings like `"/Users/John/Desktop/foo-project/"` -\> `"/"`.
  1744. */
  1745. dynamicRequireTargets?: string | ReadonlyArray<string>;
  1746. /**
  1747. * To avoid long paths when using the `dynamicRequireTargets` option, you can use this option to specify a directory
  1748. * that is a common parent for all files that use dynamic require statements. Using a directory higher up such as `/`
  1749. * may lead to unnecessarily long paths in the generated code and may expose directory names on your machine like your
  1750. * home directory name. By default, it uses the current working directory.
  1751. */
  1752. dynamicRequireRoot?: string;
  1753. }
  1754. //#endregion
  1755. //#region src/types/dynamicImportVars.d.ts
  1756. interface RollupDynamicImportVarsOptions {
  1757. /**
  1758. * Files to include in this plugin (default all).
  1759. * @default []
  1760. */
  1761. include?: string | RegExp | (string | RegExp)[];
  1762. /**
  1763. * Files to exclude in this plugin (default none).
  1764. * @default []
  1765. */
  1766. exclude?: string | RegExp | (string | RegExp)[];
  1767. /**
  1768. * By default, the plugin quits the build process when it encounters an error. If you set this option to true, it will throw a warning instead and leave the code untouched.
  1769. * @default false
  1770. */
  1771. warnOnError?: boolean;
  1772. }
  1773. //#endregion
  1774. //#region src/node/plugins/terser.d.ts
  1775. interface TerserOptions extends TerserMinifyOptions {
  1776. /**
  1777. * Vite-specific option to specify the max number of workers to spawn
  1778. * when minifying files with terser.
  1779. *
  1780. * @default number of CPUs minus 1
  1781. */
  1782. maxWorkers?: number;
  1783. }
  1784. //#endregion
  1785. //#region src/node/plugins/resolve.d.ts
  1786. interface EnvironmentResolveOptions {
  1787. /**
  1788. * @default ['browser', 'module', 'jsnext:main', 'jsnext']
  1789. */
  1790. mainFields?: string[];
  1791. conditions?: string[];
  1792. externalConditions?: string[];
  1793. /**
  1794. * @default ['.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx', '.json']
  1795. */
  1796. extensions?: string[];
  1797. dedupe?: string[];
  1798. /**
  1799. * Prevent listed dependencies from being externalized and will get bundled in build.
  1800. * Only works in server environments for now. Previously this was `ssr.noExternal`.
  1801. * @experimental
  1802. */
  1803. noExternal?: string | RegExp | (string | RegExp)[] | true;
  1804. /**
  1805. * Externalize the given dependencies and their transitive dependencies.
  1806. * Only works in server environments for now. Previously this was `ssr.external`.
  1807. * @experimental
  1808. */
  1809. external?: string[] | true;
  1810. /**
  1811. * Array of strings or regular expressions that indicate what modules are builtin for the environment.
  1812. */
  1813. builtins?: (string | RegExp)[];
  1814. }
  1815. interface ResolveOptions extends EnvironmentResolveOptions {
  1816. /**
  1817. * @default false
  1818. */
  1819. preserveSymlinks?: boolean;
  1820. }
  1821. interface ResolvePluginOptions {
  1822. root: string;
  1823. isBuild: boolean;
  1824. isProduction: boolean;
  1825. packageCache?: PackageCache;
  1826. /**
  1827. * src code mode also attempts the following:
  1828. * - resolving /xxx as URLs
  1829. * - resolving bare imports from optimized deps
  1830. */
  1831. asSrc?: boolean;
  1832. tryIndex?: boolean;
  1833. tryPrefix?: string;
  1834. preferRelative?: boolean;
  1835. isRequire?: boolean;
  1836. scan?: boolean;
  1837. }
  1838. interface InternalResolveOptions extends Required<ResolveOptions>, ResolvePluginOptions {}
  1839. //#endregion
  1840. //#region src/node/packages.d.ts
  1841. /** Cache for package.json resolution and package.json contents */
  1842. type PackageCache = Map<string, PackageData>;
  1843. interface PackageData {
  1844. dir: string;
  1845. hasSideEffects: (id: string) => boolean | "no-treeshake" | null;
  1846. setResolvedCache: (key: string, entry: string, options: InternalResolveOptions) => void;
  1847. getResolvedCache: (key: string, options: InternalResolveOptions) => string | undefined;
  1848. data: {
  1849. [field: string]: any;
  1850. name: string;
  1851. type: string;
  1852. version: string;
  1853. main: string;
  1854. module: string;
  1855. browser: string | Record<string, string | false>;
  1856. exports: string | Record<string, any> | string[];
  1857. imports: Record<string, any>;
  1858. dependencies: Record<string, string>;
  1859. };
  1860. }
  1861. //#endregion
  1862. //#region src/node/plugins/license.d.ts
  1863. interface LicenseOptions {
  1864. /**
  1865. * The output file name of the license file relative to the output directory.
  1866. * Specify a path that ends with `.json` to output the raw JSON metadata.
  1867. *
  1868. * @default '.vite/license.md'
  1869. */
  1870. fileName: string;
  1871. }
  1872. //#endregion
  1873. //#region src/node/build.d.ts
  1874. interface BuildEnvironmentOptions {
  1875. /**
  1876. * Compatibility transform target. The transform is performed with esbuild
  1877. * and the lowest supported target is es2015. Note this only handles
  1878. * syntax transformation and does not cover polyfills
  1879. *
  1880. * Default: 'baseline-widely-available' - transpile targeting browsers that
  1881. * are included in the Baseline Widely Available on 2025-05-01.
  1882. * (Chrome 107+, Edge 107+, Firefox 104+, Safari 16+).
  1883. *
  1884. * Another special value is 'esnext' - which only performs minimal transpiling
  1885. * (for minification compat).
  1886. *
  1887. * For custom targets, see https://esbuild.github.io/api/#target and
  1888. * https://esbuild.github.io/content-types/#javascript for more details.
  1889. * @default 'baseline-widely-available'
  1890. */
  1891. target?: "baseline-widely-available" | esbuild_TransformOptions["target"] | false;
  1892. /**
  1893. * whether to inject module preload polyfill.
  1894. * Note: does not apply to library mode.
  1895. * @default true
  1896. * @deprecated use `modulePreload.polyfill` instead
  1897. */
  1898. polyfillModulePreload?: boolean;
  1899. /**
  1900. * Configure module preload
  1901. * Note: does not apply to library mode.
  1902. * @default true
  1903. */
  1904. modulePreload?: boolean | ModulePreloadOptions;
  1905. /**
  1906. * Directory relative from `root` where build output will be placed. If the
  1907. * directory exists, it will be removed before the build.
  1908. * @default 'dist'
  1909. */
  1910. outDir?: string;
  1911. /**
  1912. * Directory relative from `outDir` where the built js/css/image assets will
  1913. * be placed.
  1914. * @default 'assets'
  1915. */
  1916. assetsDir?: string;
  1917. /**
  1918. * Static asset files smaller than this number (in bytes) will be inlined as
  1919. * base64 strings. If a callback is passed, a boolean can be returned to opt-in
  1920. * or opt-out of inlining. If nothing is returned the default logic applies.
  1921. *
  1922. * Default limit is `4096` (4 KiB). Set to `0` to disable.
  1923. * @default 4096
  1924. */
  1925. assetsInlineLimit?: number | ((filePath: string, content: Buffer) => boolean | undefined);
  1926. /**
  1927. * Whether to code-split CSS. When enabled, CSS in async chunks will be
  1928. * inlined as strings in the chunk and inserted via dynamically created
  1929. * style tags when the chunk is loaded.
  1930. * @default true
  1931. */
  1932. cssCodeSplit?: boolean;
  1933. /**
  1934. * An optional separate target for CSS minification.
  1935. * As esbuild only supports configuring targets to mainstream
  1936. * browsers, users may need this option when they are targeting
  1937. * a niche browser that comes with most modern JavaScript features
  1938. * but has poor CSS support, e.g. Android WeChat WebView, which
  1939. * doesn't support the #RGBA syntax.
  1940. * @default target
  1941. */
  1942. cssTarget?: esbuild_TransformOptions["target"] | false;
  1943. /**
  1944. * Override CSS minification specifically instead of defaulting to `build.minify`,
  1945. * so you can configure minification for JS and CSS separately.
  1946. * @default 'esbuild'
  1947. */
  1948. cssMinify?: boolean | "esbuild" | "lightningcss";
  1949. /**
  1950. * If `true`, a separate sourcemap file will be created. If 'inline', the
  1951. * sourcemap will be appended to the resulting output file as data URI.
  1952. * 'hidden' works like `true` except that the corresponding sourcemap
  1953. * comments in the bundled files are suppressed.
  1954. * @default false
  1955. */
  1956. sourcemap?: boolean | "inline" | "hidden";
  1957. /**
  1958. * Set to `false` to disable minification, or specify the minifier to use.
  1959. * Available options are 'terser' or 'esbuild'.
  1960. * @default 'esbuild'
  1961. */
  1962. minify?: boolean | "terser" | "esbuild";
  1963. /**
  1964. * Options for terser
  1965. * https://terser.org/docs/api-reference#minify-options
  1966. *
  1967. * In addition, you can also pass a `maxWorkers: number` option to specify the
  1968. * max number of workers to spawn. Defaults to the number of CPUs minus 1.
  1969. */
  1970. terserOptions?: TerserOptions;
  1971. /**
  1972. * Will be merged with internal rollup options.
  1973. * https://rollupjs.org/configuration-options/
  1974. */
  1975. rollupOptions?: RollupOptions;
  1976. /**
  1977. * Options to pass on to `@rollup/plugin-commonjs`
  1978. */
  1979. commonjsOptions?: RollupCommonJSOptions;
  1980. /**
  1981. * Options to pass on to `@rollup/plugin-dynamic-import-vars`
  1982. */
  1983. dynamicImportVarsOptions?: RollupDynamicImportVarsOptions;
  1984. /**
  1985. * Whether to write bundle to disk
  1986. * @default true
  1987. */
  1988. write?: boolean;
  1989. /**
  1990. * Empty outDir on write.
  1991. * @default true when outDir is a sub directory of project root
  1992. */
  1993. emptyOutDir?: boolean | null;
  1994. /**
  1995. * Copy the public directory to outDir on write.
  1996. * @default true
  1997. */
  1998. copyPublicDir?: boolean;
  1999. /**
  2000. * Whether to emit a `.vite/license.md` file that includes all bundled dependencies'
  2001. * licenses. Pass an object to customize the output file name.
  2002. * @default false
  2003. */
  2004. license?: boolean | LicenseOptions;
  2005. /**
  2006. * Whether to emit a .vite/manifest.json in the output dir to map hash-less filenames
  2007. * to their hashed versions. Useful when you want to generate your own HTML
  2008. * instead of using the one generated by Vite.
  2009. *
  2010. * Example:
  2011. *
  2012. * ```json
  2013. * {
  2014. * "main.js": {
  2015. * "file": "main.68fe3fad.js",
  2016. * "css": "main.e6b63442.css",
  2017. * "imports": [...],
  2018. * "dynamicImports": [...]
  2019. * }
  2020. * }
  2021. * ```
  2022. * @default false
  2023. */
  2024. manifest?: boolean | string;
  2025. /**
  2026. * Build in library mode. The value should be the global name of the lib in
  2027. * UMD mode. This will produce esm + cjs + umd bundle formats with default
  2028. * configurations that are suitable for distributing libraries.
  2029. * @default false
  2030. */
  2031. lib?: LibraryOptions | false;
  2032. /**
  2033. * Produce SSR oriented build. Note this requires specifying SSR entry via
  2034. * `rollupOptions.input`.
  2035. * @default false
  2036. */
  2037. ssr?: boolean | string;
  2038. /**
  2039. * Generate SSR manifest for determining style links and asset preload
  2040. * directives in production.
  2041. * @default false
  2042. */
  2043. ssrManifest?: boolean | string;
  2044. /**
  2045. * Emit assets during SSR.
  2046. * @default false
  2047. */
  2048. ssrEmitAssets?: boolean;
  2049. /**
  2050. * Emit assets during build. Frameworks can set environments.ssr.build.emitAssets
  2051. * By default, it is true for the client and false for other environments.
  2052. */
  2053. emitAssets?: boolean;
  2054. /**
  2055. * Set to false to disable reporting compressed chunk sizes.
  2056. * Can slightly improve build speed.
  2057. * @default true
  2058. */
  2059. reportCompressedSize?: boolean;
  2060. /**
  2061. * Adjust chunk size warning limit (in kB).
  2062. * @default 500
  2063. */
  2064. chunkSizeWarningLimit?: number;
  2065. /**
  2066. * Rollup watch options
  2067. * https://rollupjs.org/configuration-options/#watch
  2068. * @default null
  2069. */
  2070. watch?: WatcherOptions | null;
  2071. /**
  2072. * create the Build Environment instance
  2073. */
  2074. createEnvironment?: (name: string, config: ResolvedConfig) => Promise<BuildEnvironment> | BuildEnvironment;
  2075. }
  2076. type BuildOptions = BuildEnvironmentOptions;
  2077. interface LibraryOptions {
  2078. /**
  2079. * Path of library entry
  2080. */
  2081. entry: InputOption;
  2082. /**
  2083. * The name of the exposed global variable. Required when the `formats` option includes
  2084. * `umd` or `iife`
  2085. */
  2086. name?: string;
  2087. /**
  2088. * Output bundle formats
  2089. * @default ['es', 'umd']
  2090. */
  2091. formats?: LibraryFormats[];
  2092. /**
  2093. * The name of the package file output. The default file name is the name option
  2094. * of the project package.json. It can also be defined as a function taking the
  2095. * format as an argument.
  2096. */
  2097. fileName?: string | ((format: ModuleFormat, entryName: string) => string);
  2098. /**
  2099. * The name of the CSS file output if the library imports CSS. Defaults to the
  2100. * same value as `build.lib.fileName` if it's set a string, otherwise it falls
  2101. * back to the name option of the project package.json.
  2102. */
  2103. cssFileName?: string;
  2104. }
  2105. type LibraryFormats = "es" | "cjs" | "umd" | "iife" | "system";
  2106. interface ModulePreloadOptions {
  2107. /**
  2108. * Whether to inject a module preload polyfill.
  2109. * Note: does not apply to library mode.
  2110. * @default true
  2111. */
  2112. polyfill?: boolean;
  2113. /**
  2114. * Resolve the list of dependencies to preload for a given dynamic import
  2115. * @experimental
  2116. */
  2117. resolveDependencies?: ResolveModulePreloadDependenciesFn;
  2118. }
  2119. interface ResolvedModulePreloadOptions {
  2120. polyfill: boolean;
  2121. resolveDependencies?: ResolveModulePreloadDependenciesFn;
  2122. }
  2123. type ResolveModulePreloadDependenciesFn = (filename: string, deps: string[], context: {
  2124. hostId: string;
  2125. hostType: "html" | "js";
  2126. }) => string[];
  2127. interface ResolvedBuildEnvironmentOptions extends Required<Omit<BuildEnvironmentOptions, "polyfillModulePreload">> {
  2128. modulePreload: false | ResolvedModulePreloadOptions;
  2129. }
  2130. interface ResolvedBuildOptions extends Required<Omit<BuildOptions, "polyfillModulePreload">> {
  2131. modulePreload: false | ResolvedModulePreloadOptions;
  2132. }
  2133. /**
  2134. * Bundles a single environment for production.
  2135. * Returns a Promise containing the build result.
  2136. */
  2137. declare function build(inlineConfig?: InlineConfig): Promise<RollupOutput | RollupOutput[] | RollupWatcher>;
  2138. type RenderBuiltAssetUrl = (filename: string, type: {
  2139. type: "asset" | "public";
  2140. hostId: string;
  2141. hostType: "js" | "css" | "html";
  2142. ssr: boolean;
  2143. }) => string | {
  2144. relative?: boolean;
  2145. runtime?: string;
  2146. } | undefined;
  2147. declare class BuildEnvironment extends BaseEnvironment {
  2148. mode: "build";
  2149. isBuilt: boolean;
  2150. constructor(name: string, config: ResolvedConfig, setup?: {
  2151. options?: EnvironmentOptions;
  2152. });
  2153. init(): Promise<void>;
  2154. }
  2155. interface ViteBuilder {
  2156. environments: Record<string, BuildEnvironment>;
  2157. config: ResolvedConfig;
  2158. buildApp(): Promise<void>;
  2159. build(environment: BuildEnvironment): Promise<RollupOutput | RollupOutput[] | RollupWatcher>;
  2160. }
  2161. interface BuilderOptions {
  2162. /**
  2163. * Whether to share the config instance among environments to align with the behavior of dev server.
  2164. *
  2165. * @default false
  2166. * @experimental
  2167. */
  2168. sharedConfigBuild?: boolean;
  2169. /**
  2170. * Whether to share the plugin instances among environments to align with the behavior of dev server.
  2171. *
  2172. * @default false
  2173. * @experimental
  2174. */
  2175. sharedPlugins?: boolean;
  2176. buildApp?: (builder: ViteBuilder) => Promise<void>;
  2177. }
  2178. type ResolvedBuilderOptions = Required<BuilderOptions>;
  2179. /**
  2180. * Creates a ViteBuilder to orchestrate building multiple environments.
  2181. * @experimental
  2182. */
  2183. declare function createBuilder(inlineConfig?: InlineConfig, useLegacyBuilder?: null | boolean): Promise<ViteBuilder>;
  2184. type BuildAppHook = (this: MinimalPluginContextWithoutEnvironment, builder: ViteBuilder) => Promise<void>;
  2185. //#endregion
  2186. //#region src/node/environment.d.ts
  2187. type Environment = DevEnvironment | BuildEnvironment | ScanEnvironment | UnknownEnvironment;
  2188. /**
  2189. * Creates a function that hides the complexities of a WeakMap with an initial value
  2190. * to implement object metadata. Used by plugins to implement cross hooks per
  2191. * environment metadata
  2192. *
  2193. * @experimental
  2194. */
  2195. declare function perEnvironmentState<State>(initial: (environment: Environment) => State): (context: PluginContext) => State;
  2196. //#endregion
  2197. //#region src/node/server/pluginContainer.d.ts
  2198. type SkipInformation = {
  2199. id: string;
  2200. importer: string | undefined;
  2201. plugin: Plugin;
  2202. called?: boolean;
  2203. };
  2204. declare class EnvironmentPluginContainer<Env extends Environment = Environment> {
  2205. private _pluginContextMap;
  2206. private _resolvedRollupOptions?;
  2207. private _processesing;
  2208. private _seenResolves;
  2209. private _moduleNodeToLoadAddedImports;
  2210. getSortedPluginHooks: PluginHookUtils["getSortedPluginHooks"];
  2211. getSortedPlugins: PluginHookUtils["getSortedPlugins"];
  2212. moduleGraph: EnvironmentModuleGraph | undefined;
  2213. watchFiles: Set<string>;
  2214. minimalContext: MinimalPluginContext$1<Env>;
  2215. private _started;
  2216. private _buildStartPromise;
  2217. private _closed;
  2218. private _updateModuleLoadAddedImports;
  2219. private _getAddedImports;
  2220. getModuleInfo(id: string): ModuleInfo | null;
  2221. private handleHookPromise;
  2222. get options(): InputOptions;
  2223. resolveRollupOptions(): Promise<InputOptions>;
  2224. private _getPluginContext;
  2225. private hookParallel;
  2226. buildStart(_options?: InputOptions): Promise<void>;
  2227. resolveId(rawId: string, importer?: string | undefined, options?: {
  2228. attributes?: Record<string, string>;
  2229. custom?: CustomPluginOptions;
  2230. /** @deprecated use `skipCalls` instead */
  2231. skip?: Set<Plugin>;
  2232. skipCalls?: readonly SkipInformation[];
  2233. isEntry?: boolean;
  2234. }): Promise<PartialResolvedId | null>;
  2235. load(id: string): Promise<LoadResult | null>;
  2236. transform(code: string, id: string, options?: {
  2237. inMap?: SourceDescription["map"];
  2238. }): Promise<{
  2239. code: string;
  2240. map: SourceMap | {
  2241. mappings: "";
  2242. } | null;
  2243. }>;
  2244. watchChange(id: string, change: {
  2245. event: "create" | "update" | "delete";
  2246. }): Promise<void>;
  2247. close(): Promise<void>;
  2248. }
  2249. declare class BasicMinimalPluginContext<Meta = PluginContextMeta> {
  2250. meta: Meta;
  2251. private _logger;
  2252. constructor(meta: Meta, _logger: Logger);
  2253. debug(rawLog: string | RollupLog | (() => string | RollupLog)): void;
  2254. info(rawLog: string | RollupLog | (() => string | RollupLog)): void;
  2255. warn(rawLog: string | RollupLog | (() => string | RollupLog)): void;
  2256. error(e: string | RollupError): never;
  2257. private _normalizeRawLog;
  2258. }
  2259. declare class MinimalPluginContext$1<T$1 extends Environment = Environment> extends BasicMinimalPluginContext implements MinimalPluginContext {
  2260. environment: T$1;
  2261. constructor(meta: PluginContextMeta, environment: T$1);
  2262. }
  2263. declare class PluginContainer {
  2264. private environments;
  2265. constructor(environments: Record<string, Environment>);
  2266. private _getEnvironment;
  2267. private _getPluginContainer;
  2268. getModuleInfo(id: string): ModuleInfo | null;
  2269. get options(): InputOptions;
  2270. buildStart(_options?: InputOptions): Promise<void>;
  2271. watchChange(id: string, change: {
  2272. event: "create" | "update" | "delete";
  2273. }): Promise<void>;
  2274. resolveId(rawId: string, importer?: string, options?: {
  2275. attributes?: Record<string, string>;
  2276. custom?: CustomPluginOptions;
  2277. /** @deprecated use `skipCalls` instead */
  2278. skip?: Set<Plugin>;
  2279. skipCalls?: readonly SkipInformation[];
  2280. ssr?: boolean;
  2281. isEntry?: boolean;
  2282. }): Promise<PartialResolvedId | null>;
  2283. load(id: string, options?: {
  2284. ssr?: boolean;
  2285. }): Promise<LoadResult | null>;
  2286. transform(code: string, id: string, options?: {
  2287. ssr?: boolean;
  2288. environment?: Environment;
  2289. inMap?: SourceDescription["map"];
  2290. }): Promise<{
  2291. code: string;
  2292. map: SourceMap | {
  2293. mappings: "";
  2294. } | null;
  2295. }>;
  2296. close(): Promise<void>;
  2297. }
  2298. /**
  2299. * server.pluginContainer compatibility
  2300. *
  2301. * The default environment is in buildStart, buildEnd, watchChange, and closeBundle hooks,
  2302. * which are called once for all environments, or when no environment is passed in other hooks.
  2303. * The ssrEnvironment is needed for backward compatibility when the ssr flag is passed without
  2304. * an environment. The defaultEnvironment in the main pluginContainer in the server should be
  2305. * the client environment for backward compatibility.
  2306. **/
  2307. //#endregion
  2308. //#region src/node/server/index.d.ts
  2309. interface ServerOptions$1 extends CommonServerOptions {
  2310. /**
  2311. * Configure HMR-specific options (port, host, path & protocol)
  2312. */
  2313. hmr?: HmrOptions | boolean;
  2314. /**
  2315. * Do not start the websocket connection.
  2316. * @experimental
  2317. */
  2318. ws?: false;
  2319. /**
  2320. * Warm-up files to transform and cache the results in advance. This improves the
  2321. * initial page load during server starts and prevents transform waterfalls.
  2322. */
  2323. warmup?: {
  2324. /**
  2325. * The files to be transformed and used on the client-side. Supports glob patterns.
  2326. */
  2327. clientFiles?: string[];
  2328. /**
  2329. * The files to be transformed and used in SSR. Supports glob patterns.
  2330. */
  2331. ssrFiles?: string[];
  2332. };
  2333. /**
  2334. * chokidar watch options or null to disable FS watching
  2335. * https://github.com/paulmillr/chokidar/tree/3.6.0#api
  2336. */
  2337. watch?: WatchOptions | null;
  2338. /**
  2339. * Create Vite dev server to be used as a middleware in an existing server
  2340. * @default false
  2341. */
  2342. middlewareMode?: boolean | {
  2343. /**
  2344. * Parent server instance to attach to
  2345. *
  2346. * This is needed to proxy WebSocket connections to the parent server.
  2347. */
  2348. server: HttpServer;
  2349. };
  2350. /**
  2351. * Options for files served via '/\@fs/'.
  2352. */
  2353. fs?: FileSystemServeOptions;
  2354. /**
  2355. * Origin for the generated asset URLs.
  2356. *
  2357. * @example `http://127.0.0.1:8080`
  2358. */
  2359. origin?: string;
  2360. /**
  2361. * Pre-transform known direct imports
  2362. * @default true
  2363. */
  2364. preTransformRequests?: boolean;
  2365. /**
  2366. * Whether or not to ignore-list source files in the dev server sourcemap, used to populate
  2367. * the [`x_google_ignoreList` source map extension](https://developer.chrome.com/blog/devtools-better-angular-debugging/#the-x_google_ignorelist-source-map-extension).
  2368. *
  2369. * By default, it excludes all paths containing `node_modules`. You can pass `false` to
  2370. * disable this behavior, or, for full control, a function that takes the source path and
  2371. * sourcemap path and returns whether to ignore the source path.
  2372. */
  2373. sourcemapIgnoreList?: false | ((sourcePath: string, sourcemapPath: string) => boolean);
  2374. /**
  2375. * Backward compatibility. The buildStart and buildEnd hooks were called only once for
  2376. * the client environment. This option enables per-environment buildStart and buildEnd hooks.
  2377. * @default false
  2378. * @experimental
  2379. */
  2380. perEnvironmentStartEndDuringDev?: boolean;
  2381. /**
  2382. * Backward compatibility. The watchChange hook was called only once for the client environment.
  2383. * This option enables per-environment watchChange hooks.
  2384. * @default false
  2385. * @experimental
  2386. */
  2387. perEnvironmentWatchChangeDuringDev?: boolean;
  2388. /**
  2389. * Run HMR tasks, by default the HMR propagation is done in parallel for all environments
  2390. * @experimental
  2391. */
  2392. hotUpdateEnvironments?: (server: ViteDevServer, hmr: (environment: DevEnvironment) => Promise<void>) => Promise<void>;
  2393. }
  2394. interface ResolvedServerOptions extends Omit<RequiredExceptFor<ServerOptions$1, "host" | "https" | "proxy" | "hmr" | "ws" | "watch" | "origin" | "hotUpdateEnvironments">, "fs" | "middlewareMode" | "sourcemapIgnoreList"> {
  2395. fs: Required<FileSystemServeOptions>;
  2396. middlewareMode: NonNullable<ServerOptions$1["middlewareMode"]>;
  2397. sourcemapIgnoreList: Exclude<ServerOptions$1["sourcemapIgnoreList"], false | undefined>;
  2398. }
  2399. interface FileSystemServeOptions {
  2400. /**
  2401. * Strictly restrict file accessing outside of allowing paths.
  2402. *
  2403. * Set to `false` to disable the warning
  2404. *
  2405. * @default true
  2406. */
  2407. strict?: boolean;
  2408. /**
  2409. * Restrict accessing files outside the allowed directories.
  2410. *
  2411. * Accepts absolute path or a path relative to project root.
  2412. * Will try to search up for workspace root by default.
  2413. */
  2414. allow?: string[];
  2415. /**
  2416. * Restrict accessing files that matches the patterns.
  2417. *
  2418. * This will have higher priority than `allow`.
  2419. * picomatch patterns are supported.
  2420. *
  2421. * @default ['.env', '.env.*', '*.{crt,pem}', '**\/.git/**']
  2422. */
  2423. deny?: string[];
  2424. }
  2425. type ServerHook = (this: MinimalPluginContextWithoutEnvironment, server: ViteDevServer) => (() => void) | void | Promise<(() => void) | void>;
  2426. type HttpServer = http.Server | Http2SecureServer;
  2427. interface ViteDevServer {
  2428. /**
  2429. * The resolved vite config object
  2430. */
  2431. config: ResolvedConfig;
  2432. /**
  2433. * A connect app instance.
  2434. * - Can be used to attach custom middlewares to the dev server.
  2435. * - Can also be used as the handler function of a custom http server
  2436. * or as a middleware in any connect-style Node.js frameworks
  2437. *
  2438. * https://github.com/senchalabs/connect#use-middleware
  2439. */
  2440. middlewares: Connect.Server;
  2441. /**
  2442. * native Node http server instance
  2443. * will be null in middleware mode
  2444. */
  2445. httpServer: HttpServer | null;
  2446. /**
  2447. * Chokidar watcher instance. If `config.server.watch` is set to `null`,
  2448. * it will not watch any files and calling `add` or `unwatch` will have no effect.
  2449. * https://github.com/paulmillr/chokidar/tree/3.6.0#api
  2450. */
  2451. watcher: FSWatcher;
  2452. /**
  2453. * WebSocket server with `send(payload)` method
  2454. */
  2455. ws: WebSocketServer;
  2456. /**
  2457. * An alias to `server.environments.client.hot`.
  2458. * If you want to interact with all environments, loop over `server.environments`.
  2459. */
  2460. hot: NormalizedHotChannel;
  2461. /**
  2462. * Rollup plugin container that can run plugin hooks on a given file
  2463. */
  2464. pluginContainer: PluginContainer;
  2465. /**
  2466. * Module execution environments attached to the Vite server.
  2467. */
  2468. environments: Record<"client" | "ssr" | (string & {}), DevEnvironment>;
  2469. /**
  2470. * Module graph that tracks the import relationships, url to file mapping
  2471. * and hmr state.
  2472. */
  2473. moduleGraph: ModuleGraph;
  2474. /**
  2475. * The resolved urls Vite prints on the CLI (URL-encoded). Returns `null`
  2476. * in middleware mode or if the server is not listening on any port.
  2477. */
  2478. resolvedUrls: ResolvedServerUrls | null;
  2479. /**
  2480. * Programmatically resolve, load and transform a URL and get the result
  2481. * without going through the http request pipeline.
  2482. */
  2483. transformRequest(url: string, options?: TransformOptions): Promise<TransformResult | null>;
  2484. /**
  2485. * Same as `transformRequest` but only warm up the URLs so the next request
  2486. * will already be cached. The function will never throw as it handles and
  2487. * reports errors internally.
  2488. */
  2489. warmupRequest(url: string, options?: TransformOptions): Promise<void>;
  2490. /**
  2491. * Apply vite built-in HTML transforms and any plugin HTML transforms.
  2492. */
  2493. transformIndexHtml(url: string, html: string, originalUrl?: string): Promise<string>;
  2494. /**
  2495. * Transform module code into SSR format.
  2496. */
  2497. ssrTransform(code: string, inMap: SourceMap | {
  2498. mappings: "";
  2499. } | null, url: string, originalCode?: string): Promise<TransformResult | null>;
  2500. /**
  2501. * Load a given URL as an instantiated module for SSR.
  2502. */
  2503. ssrLoadModule(url: string, opts?: {
  2504. fixStacktrace?: boolean;
  2505. }): Promise<Record<string, any>>;
  2506. /**
  2507. * Returns a fixed version of the given stack
  2508. */
  2509. ssrRewriteStacktrace(stack: string): string;
  2510. /**
  2511. * Mutates the given SSR error by rewriting the stacktrace
  2512. */
  2513. ssrFixStacktrace(e: Error): void;
  2514. /**
  2515. * Triggers HMR for a module in the module graph. You can use the `server.moduleGraph`
  2516. * API to retrieve the module to be reloaded. If `hmr` is false, this is a no-op.
  2517. */
  2518. reloadModule(module: ModuleNode): Promise<void>;
  2519. /**
  2520. * Start the server.
  2521. */
  2522. listen(port?: number, isRestart?: boolean): Promise<ViteDevServer>;
  2523. /**
  2524. * Stop the server.
  2525. */
  2526. close(): Promise<void>;
  2527. /**
  2528. * Print server urls
  2529. */
  2530. printUrls(): void;
  2531. /**
  2532. * Bind CLI shortcuts
  2533. */
  2534. bindCLIShortcuts(options?: BindCLIShortcutsOptions<ViteDevServer>): void;
  2535. /**
  2536. * Restart the server.
  2537. *
  2538. * @param forceOptimize - force the optimizer to re-bundle, same as --force cli flag
  2539. */
  2540. restart(forceOptimize?: boolean): Promise<void>;
  2541. /**
  2542. * Open browser
  2543. */
  2544. openBrowser(): void;
  2545. /**
  2546. * Calling `await server.waitForRequestsIdle(id)` will wait until all static imports
  2547. * are processed. If called from a load or transform plugin hook, the id needs to be
  2548. * passed as a parameter to avoid deadlocks. Calling this function after the first
  2549. * static imports section of the module graph has been processed will resolve immediately.
  2550. */
  2551. waitForRequestsIdle: (ignoredId?: string) => Promise<void>;
  2552. }
  2553. interface ResolvedServerUrls {
  2554. local: string[];
  2555. network: string[];
  2556. }
  2557. declare function createServer(inlineConfig?: InlineConfig | ResolvedConfig): Promise<ViteDevServer>;
  2558. //#endregion
  2559. //#region src/node/plugins/html.d.ts
  2560. interface HtmlTagDescriptor {
  2561. tag: string;
  2562. /**
  2563. * attribute values will be escaped automatically if needed
  2564. */
  2565. attrs?: Record<string, string | boolean | undefined>;
  2566. children?: string | HtmlTagDescriptor[];
  2567. /**
  2568. * default: 'head-prepend'
  2569. */
  2570. injectTo?: "head" | "body" | "head-prepend" | "body-prepend";
  2571. }
  2572. type IndexHtmlTransformResult = string | HtmlTagDescriptor[] | {
  2573. html: string;
  2574. tags: HtmlTagDescriptor[];
  2575. };
  2576. interface IndexHtmlTransformContext {
  2577. /**
  2578. * public path when served
  2579. */
  2580. path: string;
  2581. /**
  2582. * filename on disk
  2583. */
  2584. filename: string;
  2585. server?: ViteDevServer;
  2586. bundle?: OutputBundle;
  2587. chunk?: OutputChunk;
  2588. originalUrl?: string;
  2589. }
  2590. type IndexHtmlTransformHook = (this: MinimalPluginContextWithoutEnvironment, html: string, ctx: IndexHtmlTransformContext) => IndexHtmlTransformResult | void | Promise<IndexHtmlTransformResult | void>;
  2591. type IndexHtmlTransform = IndexHtmlTransformHook | {
  2592. order?: "pre" | "post" | null;
  2593. handler: IndexHtmlTransformHook;
  2594. };
  2595. //#endregion
  2596. //#region src/node/plugins/pluginFilter.d.ts
  2597. type StringFilter<Value = string | RegExp> = Value | Array<Value> | {
  2598. include?: Value | Array<Value>;
  2599. exclude?: Value | Array<Value>;
  2600. };
  2601. //#endregion
  2602. //#region src/node/plugin.d.ts
  2603. /**
  2604. * Vite plugins extends the Rollup plugin interface with a few extra
  2605. * vite-specific options. A valid vite plugin is also a valid Rollup plugin.
  2606. * On the contrary, a Rollup plugin may or may NOT be a valid vite universal
  2607. * plugin, since some Rollup features do not make sense in an unbundled
  2608. * dev server context. That said, as long as a rollup plugin doesn't have strong
  2609. * coupling between its bundle phase and output phase hooks then it should
  2610. * just work (that means, most of them).
  2611. *
  2612. * By default, the plugins are run during both serve and build. When a plugin
  2613. * is applied during serve, it will only run **non output plugin hooks** (see
  2614. * rollup type definition of {@link rollup#PluginHooks}). You can think of the
  2615. * dev server as only running `const bundle = rollup.rollup()` but never calling
  2616. * `bundle.generate()`.
  2617. *
  2618. * A plugin that expects to have different behavior depending on serve/build can
  2619. * export a factory function that receives the command being run via options.
  2620. *
  2621. * If a plugin should be applied only for server or build, a function format
  2622. * config file can be used to conditional determine the plugins to use.
  2623. *
  2624. * The current environment can be accessed from the context for the all non-global
  2625. * hooks (it is not available in config, configResolved, configureServer, etc).
  2626. * It can be a dev, build, or scan environment.
  2627. * Plugins can use this.environment.mode === 'dev' to guard for dev specific APIs.
  2628. */
  2629. interface PluginContextExtension {
  2630. /**
  2631. * Vite-specific environment instance
  2632. */
  2633. environment: Environment;
  2634. }
  2635. interface PluginContextMetaExtension {
  2636. viteVersion: string;
  2637. }
  2638. interface ConfigPluginContext extends Omit<MinimalPluginContext, "meta" | "environment"> {
  2639. meta: Omit<PluginContextMeta, "watchMode">;
  2640. }
  2641. interface MinimalPluginContextWithoutEnvironment extends Omit<MinimalPluginContext, "environment"> {}
  2642. declare module "rollup" {
  2643. interface MinimalPluginContext extends PluginContextExtension {}
  2644. interface PluginContextMeta extends PluginContextMetaExtension {}
  2645. }
  2646. /**
  2647. * There are two types of plugins in Vite. App plugins and environment plugins.
  2648. * Environment Plugins are defined by a constructor function that will be called
  2649. * once per each environment allowing users to have completely different plugins
  2650. * for each of them. The constructor gets the resolved environment after the server
  2651. * and builder has already been created simplifying config access and cache
  2652. * management for for environment specific plugins.
  2653. * Environment Plugins are closer to regular rollup plugins. They can't define
  2654. * app level hooks (like config, configResolved, configureServer, etc).
  2655. */
  2656. interface Plugin<A = any> extends Rollup.Plugin<A> {
  2657. /**
  2658. * Perform custom handling of HMR updates.
  2659. * The handler receives an options containing changed filename, timestamp, a
  2660. * list of modules affected by the file change, and the dev server instance.
  2661. *
  2662. * - The hook can return a filtered list of modules to narrow down the update.
  2663. * e.g. for a Vue SFC, we can narrow down the part to update by comparing
  2664. * the descriptors.
  2665. *
  2666. * - The hook can also return an empty array and then perform custom updates
  2667. * by sending a custom hmr payload via environment.hot.send().
  2668. *
  2669. * - If the hook doesn't return a value, the hmr update will be performed as
  2670. * normal.
  2671. */
  2672. hotUpdate?: ObjectHook<(this: MinimalPluginContext & {
  2673. environment: DevEnvironment;
  2674. }, options: HotUpdateOptions) => Array<EnvironmentModuleNode> | void | Promise<Array<EnvironmentModuleNode> | void>>;
  2675. /**
  2676. * extend hooks with ssr flag
  2677. */
  2678. resolveId?: ObjectHook<(this: PluginContext, source: string, importer: string | undefined, options: {
  2679. attributes: Record<string, string>;
  2680. custom?: CustomPluginOptions;
  2681. ssr?: boolean | undefined;
  2682. isEntry: boolean;
  2683. }) => Promise<ResolveIdResult> | ResolveIdResult, {
  2684. filter?: {
  2685. id?: StringFilter<RegExp>;
  2686. };
  2687. }>;
  2688. load?: ObjectHook<(this: PluginContext, id: string, options?: {
  2689. ssr?: boolean | undefined;
  2690. }) => Promise<LoadResult> | LoadResult, {
  2691. filter?: {
  2692. id?: StringFilter;
  2693. };
  2694. }>;
  2695. transform?: ObjectHook<(this: TransformPluginContext, code: string, id: string, options?: {
  2696. ssr?: boolean | undefined;
  2697. }) => Promise<Rollup.TransformResult> | Rollup.TransformResult, {
  2698. filter?: {
  2699. id?: StringFilter;
  2700. code?: StringFilter;
  2701. };
  2702. }>;
  2703. /**
  2704. * Opt-in this plugin into the shared plugins pipeline.
  2705. * For backward-compatibility, plugins are re-recreated for each environment
  2706. * during `vite build --app`
  2707. * We have an opt-in per plugin, and a general `builder.sharedPlugins`
  2708. * In a future major, we'll flip the default to be shared by default
  2709. * @experimental
  2710. */
  2711. sharedDuringBuild?: boolean;
  2712. /**
  2713. * Opt-in this plugin into per-environment buildStart and buildEnd during dev.
  2714. * For backward-compatibility, the buildStart hook is called only once during
  2715. * dev, for the client environment. Plugins can opt-in to be called
  2716. * per-environment, aligning with the build hook behavior.
  2717. * @experimental
  2718. */
  2719. perEnvironmentStartEndDuringDev?: boolean;
  2720. /**
  2721. * Opt-in this plugin into per-environment watchChange during dev.
  2722. * For backward-compatibility, the watchChange hook is called only once during
  2723. * dev, for the client environment. Plugins can opt-in to be called
  2724. * per-environment, aligning with the watchChange hook behavior.
  2725. * @experimental
  2726. */
  2727. perEnvironmentWatchChangeDuringDev?: boolean;
  2728. /**
  2729. * Enforce plugin invocation tier similar to webpack loaders. Hooks ordering
  2730. * is still subject to the `order` property in the hook object.
  2731. *
  2732. * Plugin invocation order:
  2733. * - alias resolution
  2734. * - `enforce: 'pre'` plugins
  2735. * - vite core plugins
  2736. * - normal plugins
  2737. * - vite build plugins
  2738. * - `enforce: 'post'` plugins
  2739. * - vite build post plugins
  2740. */
  2741. enforce?: "pre" | "post";
  2742. /**
  2743. * Apply the plugin only for serve or build, or on certain conditions.
  2744. */
  2745. apply?: "serve" | "build" | ((this: void, config: UserConfig, env: ConfigEnv) => boolean);
  2746. /**
  2747. * Define environments where this plugin should be active
  2748. * By default, the plugin is active in all environments
  2749. * @experimental
  2750. */
  2751. applyToEnvironment?: (environment: PartialEnvironment) => boolean | Promise<boolean> | PluginOption;
  2752. /**
  2753. * Modify vite config before it's resolved. The hook can either mutate the
  2754. * passed-in config directly, or return a partial config object that will be
  2755. * deeply merged into existing config.
  2756. *
  2757. * Note: User plugins are resolved before running this hook so injecting other
  2758. * plugins inside the `config` hook will have no effect.
  2759. */
  2760. config?: ObjectHook<(this: ConfigPluginContext, config: UserConfig, env: ConfigEnv) => Omit<UserConfig, "plugins"> | null | void | Promise<Omit<UserConfig, "plugins"> | null | void>>;
  2761. /**
  2762. * Modify environment configs before it's resolved. The hook can either mutate the
  2763. * passed-in environment config directly, or return a partial config object that will be
  2764. * deeply merged into existing config.
  2765. * This hook is called for each environment with a partially resolved environment config
  2766. * that already accounts for the default environment config values set at the root level.
  2767. * If plugins need to modify the config of a given environment, they should do it in this
  2768. * hook instead of the config hook. Leaving the config hook only for modifying the root
  2769. * default environment config.
  2770. */
  2771. configEnvironment?: ObjectHook<(this: ConfigPluginContext, name: string, config: EnvironmentOptions, env: ConfigEnv & {
  2772. /**
  2773. * Whether this environment is SSR environment and `ssr.target` is set to `'webworker'`.
  2774. * Only intended to be used for backward compatibility.
  2775. */
  2776. isSsrTargetWebworker?: boolean;
  2777. }) => EnvironmentOptions | null | void | Promise<EnvironmentOptions | null | void>>;
  2778. /**
  2779. * Use this hook to read and store the final resolved vite config.
  2780. */
  2781. configResolved?: ObjectHook<(this: MinimalPluginContextWithoutEnvironment, config: ResolvedConfig) => void | Promise<void>>;
  2782. /**
  2783. * Configure the vite server. The hook receives the {@link ViteDevServer}
  2784. * instance. This can also be used to store a reference to the server
  2785. * for use in other hooks.
  2786. *
  2787. * The hooks will be called before internal middlewares are applied. A hook
  2788. * can return a post hook that will be called after internal middlewares
  2789. * are applied. Hook can be async functions and will be called in series.
  2790. */
  2791. configureServer?: ObjectHook<ServerHook>;
  2792. /**
  2793. * Configure the preview server. The hook receives the {@link PreviewServer}
  2794. * instance. This can also be used to store a reference to the server
  2795. * for use in other hooks.
  2796. *
  2797. * The hooks are called before other middlewares are applied. A hook can
  2798. * return a post hook that will be called after other middlewares are
  2799. * applied. Hooks can be async functions and will be called in series.
  2800. */
  2801. configurePreviewServer?: ObjectHook<PreviewServerHook>;
  2802. /**
  2803. * Transform index.html.
  2804. * The hook receives the following arguments:
  2805. *
  2806. * - html: string
  2807. * - ctx: IndexHtmlTransformContext, which contains:
  2808. * - path: public path when served
  2809. * - filename: filename on disk
  2810. * - server?: ViteDevServer (only present during serve)
  2811. * - bundle?: rollup.OutputBundle (only present during build)
  2812. * - chunk?: rollup.OutputChunk
  2813. * - originalUrl?: string
  2814. *
  2815. * It can either return a transformed string, or a list of html tag
  2816. * descriptors that will be injected into the `<head>` or `<body>`.
  2817. *
  2818. * By default the transform is applied **after** vite's internal html
  2819. * transform. If you need to apply the transform before vite, use an object:
  2820. * `{ order: 'pre', handler: hook }`
  2821. */
  2822. transformIndexHtml?: IndexHtmlTransform;
  2823. /**
  2824. * Build Environments
  2825. *
  2826. * @experimental
  2827. */
  2828. buildApp?: ObjectHook<BuildAppHook>;
  2829. /**
  2830. * Perform custom handling of HMR updates.
  2831. * The handler receives a context containing changed filename, timestamp, a
  2832. * list of modules affected by the file change, and the dev server instance.
  2833. *
  2834. * - The hook can return a filtered list of modules to narrow down the update.
  2835. * e.g. for a Vue SFC, we can narrow down the part to update by comparing
  2836. * the descriptors.
  2837. *
  2838. * - The hook can also return an empty array and then perform custom updates
  2839. * by sending a custom hmr payload via server.ws.send().
  2840. *
  2841. * - If the hook doesn't return a value, the hmr update will be performed as
  2842. * normal.
  2843. */
  2844. handleHotUpdate?: ObjectHook<(this: MinimalPluginContextWithoutEnvironment, ctx: HmrContext) => Array<ModuleNode> | void | Promise<Array<ModuleNode> | void>>;
  2845. }
  2846. type HookHandler<T$1> = T$1 extends ObjectHook<infer H> ? H : T$1;
  2847. type PluginWithRequiredHook<K$1 extends keyof Plugin> = Plugin & { [P in K$1]: NonNullable<Plugin[P]> };
  2848. type Thenable<T$1> = T$1 | Promise<T$1>;
  2849. type FalsyPlugin = false | null | undefined;
  2850. type PluginOption = Thenable<Plugin | FalsyPlugin | PluginOption[]>;
  2851. /**
  2852. * @experimental
  2853. */
  2854. declare function perEnvironmentPlugin(name: string, applyToEnvironment: (environment: PartialEnvironment) => boolean | Promise<boolean> | PluginOption): Plugin;
  2855. //#endregion
  2856. //#region src/node/plugins/css.d.ts
  2857. interface CSSOptions {
  2858. /**
  2859. * Using lightningcss is an experimental option to handle CSS modules,
  2860. * assets and imports via Lightning CSS. It requires to install it as a
  2861. * peer dependency.
  2862. *
  2863. * @default 'postcss'
  2864. * @experimental
  2865. */
  2866. transformer?: "postcss" | "lightningcss";
  2867. /**
  2868. * https://github.com/css-modules/postcss-modules
  2869. */
  2870. modules?: CSSModulesOptions | false;
  2871. /**
  2872. * Options for preprocessors.
  2873. *
  2874. * In addition to options specific to each processors, Vite supports `additionalData` option.
  2875. * The `additionalData` option can be used to inject extra code for each style content.
  2876. */
  2877. preprocessorOptions?: {
  2878. scss?: SassPreprocessorOptions;
  2879. sass?: SassPreprocessorOptions;
  2880. less?: LessPreprocessorOptions;
  2881. styl?: StylusPreprocessorOptions;
  2882. stylus?: StylusPreprocessorOptions;
  2883. };
  2884. /**
  2885. * If this option is set, preprocessors will run in workers when possible.
  2886. * `true` means the number of CPUs minus 1.
  2887. *
  2888. * @default true
  2889. */
  2890. preprocessorMaxWorkers?: number | true;
  2891. postcss?: string | (PostCSS.ProcessOptions & {
  2892. plugins?: PostCSS.AcceptedPlugin[];
  2893. });
  2894. /**
  2895. * Enables css sourcemaps during dev
  2896. * @default false
  2897. * @experimental
  2898. */
  2899. devSourcemap?: boolean;
  2900. /**
  2901. * @experimental
  2902. */
  2903. lightningcss?: lightningcssOptions_LightningCSSOptions;
  2904. }
  2905. interface CSSModulesOptions {
  2906. getJSON?: (cssFileName: string, json: Record<string, string>, outputFileName: string) => void;
  2907. scopeBehaviour?: "global" | "local";
  2908. globalModulePaths?: RegExp[];
  2909. exportGlobals?: boolean;
  2910. generateScopedName?: string | ((name: string, filename: string, css: string) => string);
  2911. hashPrefix?: string;
  2912. /**
  2913. * default: undefined
  2914. */
  2915. localsConvention?: "camelCase" | "camelCaseOnly" | "dashes" | "dashesOnly" | ((originalClassName: string, generatedClassName: string, inputFile: string) => string);
  2916. }
  2917. type ResolvedCSSOptions = Omit<CSSOptions, "lightningcss"> & Required<Pick<CSSOptions, "transformer" | "devSourcemap">> & {
  2918. lightningcss?: lightningcssOptions_LightningCSSOptions;
  2919. };
  2920. interface PreprocessCSSResult {
  2921. code: string;
  2922. map?: SourceMapInput;
  2923. modules?: Record<string, string>;
  2924. deps?: Set<string>;
  2925. }
  2926. /**
  2927. * @experimental
  2928. */
  2929. declare function preprocessCSS(code: string, filename: string, config: ResolvedConfig): Promise<PreprocessCSSResult>;
  2930. declare function formatPostcssSourceMap(rawMap: ExistingRawSourceMap, file: string): Promise<ExistingRawSourceMap>;
  2931. type PreprocessorAdditionalDataResult = string | {
  2932. content: string;
  2933. map?: ExistingRawSourceMap;
  2934. };
  2935. type PreprocessorAdditionalData = string | ((source: string, filename: string) => PreprocessorAdditionalDataResult | Promise<PreprocessorAdditionalDataResult>);
  2936. type SassPreprocessorOptions = {
  2937. additionalData?: PreprocessorAdditionalData;
  2938. } & SassModernPreprocessBaseOptions;
  2939. type LessPreprocessorOptions = {
  2940. additionalData?: PreprocessorAdditionalData;
  2941. } & LessPreprocessorBaseOptions;
  2942. type StylusPreprocessorOptions = {
  2943. additionalData?: PreprocessorAdditionalData;
  2944. } & StylusPreprocessorBaseOptions;
  2945. //#endregion
  2946. //#region src/node/plugins/esbuild.d.ts
  2947. interface ESBuildOptions extends esbuild_TransformOptions {
  2948. include?: string | RegExp | ReadonlyArray<string | RegExp>;
  2949. exclude?: string | RegExp | ReadonlyArray<string | RegExp>;
  2950. jsxInject?: string;
  2951. /**
  2952. * This option is not respected. Use `build.minify` instead.
  2953. */
  2954. minify?: never;
  2955. }
  2956. type ESBuildTransformResult = Omit<esbuild_TransformResult, "map"> & {
  2957. map: SourceMap;
  2958. };
  2959. declare function transformWithEsbuild(code: string, filename: string, options?: esbuild_TransformOptions, inMap?: object, config?: ResolvedConfig, watcher?: FSWatcher): Promise<ESBuildTransformResult>;
  2960. //#endregion
  2961. //#region src/node/plugins/json.d.ts
  2962. interface JsonOptions {
  2963. /**
  2964. * Generate a named export for every property of the JSON object
  2965. * @default true
  2966. */
  2967. namedExports?: boolean;
  2968. /**
  2969. * Generate performant output as JSON.parse("stringified").
  2970. *
  2971. * When set to 'auto', the data will be stringified only if the data is bigger than 10kB.
  2972. * @default 'auto'
  2973. */
  2974. stringify?: boolean | "auto";
  2975. }
  2976. //#endregion
  2977. //#region src/node/ssr/index.d.ts
  2978. type SSRTarget = "node" | "webworker";
  2979. type SsrDepOptimizationConfig = DepOptimizationConfig;
  2980. interface SSROptions {
  2981. noExternal?: string | RegExp | (string | RegExp)[] | true;
  2982. external?: string[] | true;
  2983. /**
  2984. * Define the target for the ssr build. The browser field in package.json
  2985. * is ignored for node but used if webworker is the target
  2986. * This option will be removed in a future major version
  2987. * @default 'node'
  2988. */
  2989. target?: SSRTarget;
  2990. /**
  2991. * Control over which dependencies are optimized during SSR and esbuild options
  2992. * During build:
  2993. * no external CJS dependencies are optimized by default
  2994. * During dev:
  2995. * explicit no external CJS dependencies are optimized by default
  2996. * @experimental
  2997. */
  2998. optimizeDeps?: SsrDepOptimizationConfig;
  2999. resolve?: {
  3000. /**
  3001. * Conditions that are used in the plugin pipeline. The default value is the root config's `resolve.conditions`.
  3002. *
  3003. * Use this to override the default ssr conditions for the ssr build.
  3004. *
  3005. * @default rootConfig.resolve.conditions
  3006. */
  3007. conditions?: string[];
  3008. /**
  3009. * Conditions that are used during ssr import (including `ssrLoadModule`) of externalized dependencies.
  3010. *
  3011. * @default ['node', 'module-sync']
  3012. */
  3013. externalConditions?: string[];
  3014. mainFields?: string[];
  3015. };
  3016. }
  3017. interface ResolvedSSROptions extends SSROptions {
  3018. target: SSRTarget;
  3019. optimizeDeps: SsrDepOptimizationConfig;
  3020. }
  3021. //#endregion
  3022. //#region src/node/config.d.ts
  3023. interface ConfigEnv {
  3024. /**
  3025. * 'serve': during dev (`vite` command)
  3026. * 'build': when building for production (`vite build` command)
  3027. */
  3028. command: "build" | "serve";
  3029. mode: string;
  3030. isSsrBuild?: boolean;
  3031. isPreview?: boolean;
  3032. }
  3033. /**
  3034. * spa: include SPA fallback middleware and configure sirv with `single: true` in preview
  3035. *
  3036. * mpa: only include non-SPA HTML middlewares
  3037. *
  3038. * custom: don't include HTML middlewares
  3039. */
  3040. type AppType = "spa" | "mpa" | "custom";
  3041. type UserConfigFnObject = (env: ConfigEnv) => UserConfig;
  3042. type UserConfigFnPromise = (env: ConfigEnv) => Promise<UserConfig>;
  3043. type UserConfigFn = (env: ConfigEnv) => UserConfig | Promise<UserConfig>;
  3044. type UserConfigExport = UserConfig | Promise<UserConfig> | UserConfigFnObject | UserConfigFnPromise | UserConfigFn;
  3045. /**
  3046. * Type helper to make it easier to use vite.config.ts
  3047. * accepts a direct {@link UserConfig} object, or a function that returns it.
  3048. * The function receives a {@link ConfigEnv} object.
  3049. */
  3050. declare function defineConfig(config: UserConfig): UserConfig;
  3051. declare function defineConfig(config: Promise<UserConfig>): Promise<UserConfig>;
  3052. declare function defineConfig(config: UserConfigFnObject): UserConfigFnObject;
  3053. declare function defineConfig(config: UserConfigFnPromise): UserConfigFnPromise;
  3054. declare function defineConfig(config: UserConfigFn): UserConfigFn;
  3055. declare function defineConfig(config: UserConfigExport): UserConfigExport;
  3056. interface CreateDevEnvironmentContext {
  3057. ws: WebSocketServer;
  3058. }
  3059. interface DevEnvironmentOptions {
  3060. /**
  3061. * Files to be pre-transformed. Supports glob patterns.
  3062. */
  3063. warmup?: string[];
  3064. /**
  3065. * Pre-transform known direct imports
  3066. * defaults to true for the client environment, false for the rest
  3067. */
  3068. preTransformRequests?: boolean;
  3069. /**
  3070. * Enables sourcemaps during dev
  3071. * @default { js: true }
  3072. * @experimental
  3073. */
  3074. sourcemap?: boolean | {
  3075. js?: boolean;
  3076. css?: boolean;
  3077. };
  3078. /**
  3079. * Whether or not to ignore-list source files in the dev server sourcemap, used to populate
  3080. * the [`x_google_ignoreList` source map extension](https://developer.chrome.com/blog/devtools-better-angular-debugging/#the-x_google_ignorelist-source-map-extension).
  3081. *
  3082. * By default, it excludes all paths containing `node_modules`. You can pass `false` to
  3083. * disable this behavior, or, for full control, a function that takes the source path and
  3084. * sourcemap path and returns whether to ignore the source path.
  3085. */
  3086. sourcemapIgnoreList?: false | ((sourcePath: string, sourcemapPath: string) => boolean);
  3087. /**
  3088. * create the Dev Environment instance
  3089. */
  3090. createEnvironment?: (name: string, config: ResolvedConfig, context: CreateDevEnvironmentContext) => Promise<DevEnvironment> | DevEnvironment;
  3091. /**
  3092. * For environments that support a full-reload, like the client, we can short-circuit when
  3093. * restarting the server throwing early to stop processing current files. We avoided this for
  3094. * SSR requests. Maybe this is no longer needed.
  3095. * @experimental
  3096. */
  3097. recoverable?: boolean;
  3098. /**
  3099. * For environments associated with a module runner.
  3100. * By default, it is false for the client environment and true for non-client environments.
  3101. * This option can also be used instead of the removed config.experimental.skipSsrTransform.
  3102. */
  3103. moduleRunnerTransform?: boolean;
  3104. }
  3105. type ResolvedDevEnvironmentOptions = Omit<Required<DevEnvironmentOptions>, "sourcemapIgnoreList"> & {
  3106. sourcemapIgnoreList: Exclude<DevEnvironmentOptions["sourcemapIgnoreList"], false | undefined>;
  3107. };
  3108. type AllResolveOptions = ResolveOptions & {
  3109. alias?: AliasOptions;
  3110. };
  3111. interface SharedEnvironmentOptions {
  3112. /**
  3113. * Define global variable replacements.
  3114. * Entries will be defined on `window` during dev and replaced during build.
  3115. */
  3116. define?: Record<string, any>;
  3117. /**
  3118. * Configure resolver
  3119. */
  3120. resolve?: EnvironmentResolveOptions;
  3121. /**
  3122. * Define if this environment is used for Server-Side Rendering
  3123. * @default 'server' if it isn't the client environment
  3124. */
  3125. consumer?: "client" | "server";
  3126. /**
  3127. * If true, `process.env` referenced in code will be preserved as-is and evaluated in runtime.
  3128. * Otherwise, it is statically replaced as an empty object.
  3129. */
  3130. keepProcessEnv?: boolean;
  3131. /**
  3132. * Optimize deps config
  3133. */
  3134. optimizeDeps?: DepOptimizationOptions;
  3135. }
  3136. interface EnvironmentOptions extends SharedEnvironmentOptions {
  3137. /**
  3138. * Dev specific options
  3139. */
  3140. dev?: DevEnvironmentOptions;
  3141. /**
  3142. * Build specific options
  3143. */
  3144. build?: BuildEnvironmentOptions;
  3145. }
  3146. type ResolvedResolveOptions = Required<ResolveOptions>;
  3147. type ResolvedEnvironmentOptions = {
  3148. define?: Record<string, any>;
  3149. resolve: ResolvedResolveOptions;
  3150. consumer: "client" | "server";
  3151. keepProcessEnv?: boolean;
  3152. optimizeDeps: DepOptimizationOptions;
  3153. dev: ResolvedDevEnvironmentOptions;
  3154. build: ResolvedBuildEnvironmentOptions;
  3155. plugins: readonly Plugin[];
  3156. };
  3157. type DefaultEnvironmentOptions = Omit<EnvironmentOptions, "consumer" | "resolve" | "keepProcessEnv"> & {
  3158. resolve?: AllResolveOptions;
  3159. };
  3160. interface UserConfig extends DefaultEnvironmentOptions {
  3161. /**
  3162. * Project root directory. Can be an absolute path, or a path relative from
  3163. * the location of the config file itself.
  3164. * @default process.cwd()
  3165. */
  3166. root?: string;
  3167. /**
  3168. * Base public path when served in development or production.
  3169. * @default '/'
  3170. */
  3171. base?: string;
  3172. /**
  3173. * Directory to serve as plain static assets. Files in this directory are
  3174. * served and copied to build dist dir as-is without transform. The value
  3175. * can be either an absolute file system path or a path relative to project root.
  3176. *
  3177. * Set to `false` or an empty string to disable copied static assets to build dist dir.
  3178. * @default 'public'
  3179. */
  3180. publicDir?: string | false;
  3181. /**
  3182. * Directory to save cache files. Files in this directory are pre-bundled
  3183. * deps or some other cache files that generated by vite, which can improve
  3184. * the performance. You can use `--force` flag or manually delete the directory
  3185. * to regenerate the cache files. The value can be either an absolute file
  3186. * system path or a path relative to project root.
  3187. * Default to `.vite` when no `package.json` is detected.
  3188. * @default 'node_modules/.vite'
  3189. */
  3190. cacheDir?: string;
  3191. /**
  3192. * Explicitly set a mode to run in. This will override the default mode for
  3193. * each command, and can be overridden by the command line --mode option.
  3194. */
  3195. mode?: string;
  3196. /**
  3197. * Array of vite plugins to use.
  3198. */
  3199. plugins?: PluginOption[];
  3200. /**
  3201. * HTML related options
  3202. */
  3203. html?: HTMLOptions;
  3204. /**
  3205. * CSS related options (preprocessors and CSS modules)
  3206. */
  3207. css?: CSSOptions;
  3208. /**
  3209. * JSON loading options
  3210. */
  3211. json?: JsonOptions;
  3212. /**
  3213. * Transform options to pass to esbuild.
  3214. * Or set to `false` to disable esbuild.
  3215. */
  3216. esbuild?: ESBuildOptions | false;
  3217. /**
  3218. * Specify additional picomatch patterns to be treated as static assets.
  3219. */
  3220. assetsInclude?: string | RegExp | (string | RegExp)[];
  3221. /**
  3222. * Builder specific options
  3223. * @experimental
  3224. */
  3225. builder?: BuilderOptions;
  3226. /**
  3227. * Server specific options, e.g. host, port, https...
  3228. */
  3229. server?: ServerOptions$1;
  3230. /**
  3231. * Preview specific options, e.g. host, port, https...
  3232. */
  3233. preview?: PreviewOptions;
  3234. /**
  3235. * Experimental features
  3236. *
  3237. * Features under this field could change in the future and might NOT follow semver.
  3238. * Please be careful and always pin Vite's version when using them.
  3239. * @experimental
  3240. */
  3241. experimental?: ExperimentalOptions;
  3242. /**
  3243. * Options to opt-in to future behavior
  3244. */
  3245. future?: FutureOptions | "warn";
  3246. /**
  3247. * Legacy options
  3248. *
  3249. * Features under this field only follow semver for patches, they could be removed in a
  3250. * future minor version. Please always pin Vite's version to a minor when using them.
  3251. */
  3252. legacy?: LegacyOptions;
  3253. /**
  3254. * Log level.
  3255. * @default 'info'
  3256. */
  3257. logLevel?: LogLevel;
  3258. /**
  3259. * Custom logger.
  3260. */
  3261. customLogger?: Logger;
  3262. /**
  3263. * @default true
  3264. */
  3265. clearScreen?: boolean;
  3266. /**
  3267. * Environment files directory. Can be an absolute path, or a path relative from
  3268. * root.
  3269. * @default root
  3270. */
  3271. envDir?: string | false;
  3272. /**
  3273. * Env variables starts with `envPrefix` will be exposed to your client source code via import.meta.env.
  3274. * @default 'VITE_'
  3275. */
  3276. envPrefix?: string | string[];
  3277. /**
  3278. * Worker bundle options
  3279. */
  3280. worker?: {
  3281. /**
  3282. * Output format for worker bundle
  3283. * @default 'iife'
  3284. */
  3285. format?: "es" | "iife";
  3286. /**
  3287. * Vite plugins that apply to worker bundle. The plugins returned by this function
  3288. * should be new instances every time it is called, because they are used for each
  3289. * rollup worker bundling process.
  3290. */
  3291. plugins?: () => PluginOption[];
  3292. /**
  3293. * Rollup options to build worker bundle
  3294. */
  3295. rollupOptions?: Omit<RollupOptions, "plugins" | "input" | "onwarn" | "preserveEntrySignatures">;
  3296. };
  3297. /**
  3298. * Dep optimization options
  3299. */
  3300. optimizeDeps?: DepOptimizationOptions;
  3301. /**
  3302. * SSR specific options
  3303. * We could make SSROptions be a EnvironmentOptions if we can abstract
  3304. * external/noExternal for environments in general.
  3305. */
  3306. ssr?: SSROptions;
  3307. /**
  3308. * Environment overrides
  3309. */
  3310. environments?: Record<string, EnvironmentOptions>;
  3311. /**
  3312. * Whether your application is a Single Page Application (SPA),
  3313. * a Multi-Page Application (MPA), or Custom Application (SSR
  3314. * and frameworks with custom HTML handling)
  3315. * @default 'spa'
  3316. */
  3317. appType?: AppType;
  3318. }
  3319. interface HTMLOptions {
  3320. /**
  3321. * A nonce value placeholder that will be used when generating script/style tags.
  3322. *
  3323. * Make sure that this placeholder will be replaced with a unique value for each request by the server.
  3324. */
  3325. cspNonce?: string;
  3326. }
  3327. interface FutureOptions {
  3328. removePluginHookHandleHotUpdate?: "warn";
  3329. removePluginHookSsrArgument?: "warn";
  3330. removeServerModuleGraph?: "warn";
  3331. removeServerReloadModule?: "warn";
  3332. removeServerPluginContainer?: "warn";
  3333. removeServerHot?: "warn";
  3334. removeServerTransformRequest?: "warn";
  3335. removeServerWarmupRequest?: "warn";
  3336. removeSsrLoadModule?: "warn";
  3337. }
  3338. interface ExperimentalOptions {
  3339. /**
  3340. * Append fake `&lang.(ext)` when queries are specified, to preserve the file extension for following plugins to process.
  3341. *
  3342. * @experimental
  3343. * @default false
  3344. */
  3345. importGlobRestoreExtension?: boolean;
  3346. /**
  3347. * Allow finegrain control over assets and public files paths
  3348. *
  3349. * @experimental
  3350. */
  3351. renderBuiltUrl?: RenderBuiltAssetUrl;
  3352. /**
  3353. * Enables support of HMR partial accept via `import.meta.hot.acceptExports`.
  3354. *
  3355. * @experimental
  3356. * @default false
  3357. */
  3358. hmrPartialAccept?: boolean;
  3359. }
  3360. interface LegacyOptions {
  3361. /**
  3362. * In Vite 6.0.8 and below, WebSocket server was able to connect from any web pages. However,
  3363. * that could be exploited by a malicious web page.
  3364. *
  3365. * In Vite 6.0.9+, the WebSocket server now requires a token to connect from a web page.
  3366. * But this may break some plugins and frameworks that connects to the WebSocket server
  3367. * on their own. Enabling this option will make Vite skip the token check.
  3368. *
  3369. * **We do not recommend enabling this option unless you are sure that you are fine with
  3370. * that security weakness.**
  3371. */
  3372. skipWebSocketTokenCheck?: boolean;
  3373. }
  3374. interface ResolvedWorkerOptions {
  3375. format: "es" | "iife";
  3376. plugins: (bundleChain: string[]) => Promise<ResolvedConfig>;
  3377. rollupOptions: RollupOptions;
  3378. }
  3379. interface InlineConfig extends UserConfig {
  3380. configFile?: string | false;
  3381. /** @experimental */
  3382. configLoader?: "bundle" | "runner" | "native";
  3383. /** @deprecated */
  3384. envFile?: false;
  3385. forceOptimizeDeps?: boolean;
  3386. }
  3387. interface ResolvedConfig extends Readonly<Omit<UserConfig, "plugins" | "css" | "json" | "assetsInclude" | "optimizeDeps" | "worker" | "build" | "dev" | "environments" | "experimental" | "future" | "server" | "preview"> & {
  3388. configFile: string | undefined;
  3389. configFileDependencies: string[];
  3390. inlineConfig: InlineConfig;
  3391. root: string;
  3392. base: string;
  3393. publicDir: string;
  3394. cacheDir: string;
  3395. command: "build" | "serve";
  3396. mode: string;
  3397. isWorker: boolean;
  3398. isProduction: boolean;
  3399. envDir: string | false;
  3400. env: Record<string, any>;
  3401. resolve: Required<ResolveOptions> & {
  3402. alias: Alias[];
  3403. };
  3404. plugins: readonly Plugin[];
  3405. css: ResolvedCSSOptions;
  3406. json: Required<JsonOptions>;
  3407. esbuild: ESBuildOptions | false;
  3408. server: ResolvedServerOptions;
  3409. dev: ResolvedDevEnvironmentOptions;
  3410. /** @experimental */
  3411. builder: ResolvedBuilderOptions | undefined;
  3412. build: ResolvedBuildOptions;
  3413. preview: ResolvedPreviewOptions;
  3414. ssr: ResolvedSSROptions;
  3415. assetsInclude: (file: string) => boolean;
  3416. logger: Logger;
  3417. /**
  3418. * Create an internal resolver to be used in special scenarios, e.g.
  3419. * optimizer & handling css `@imports`.
  3420. *
  3421. * This API is deprecated. It only works for the client and ssr
  3422. * environments. The `aliasOnly` option is also not being used anymore.
  3423. * Plugins should move to `createIdResolver(environment.config)` instead.
  3424. *
  3425. * @deprecated Use `createIdResolver` from `vite` instead.
  3426. */
  3427. createResolver: (options?: Partial<InternalResolveOptions>) => ResolveFn;
  3428. optimizeDeps: DepOptimizationOptions;
  3429. worker: ResolvedWorkerOptions;
  3430. appType: AppType;
  3431. experimental: RequiredExceptFor<ExperimentalOptions, "renderBuiltUrl">;
  3432. future: FutureOptions | undefined;
  3433. environments: Record<string, ResolvedEnvironmentOptions>;
  3434. /**
  3435. * The token to connect to the WebSocket server from browsers.
  3436. *
  3437. * We recommend using `import.meta.hot` rather than connecting
  3438. * to the WebSocket server directly.
  3439. * If you have a usecase that requires connecting to the WebSocket
  3440. * server, please create an issue so that we can discuss.
  3441. *
  3442. * @deprecated
  3443. */
  3444. webSocketToken: string;
  3445. } & PluginHookUtils> {}
  3446. interface PluginHookUtils {
  3447. getSortedPlugins: <K$1 extends keyof Plugin>(hookName: K$1) => PluginWithRequiredHook<K$1>[];
  3448. getSortedPluginHooks: <K$1 extends keyof Plugin>(hookName: K$1) => NonNullable<HookHandler<Plugin[K$1]>>[];
  3449. }
  3450. type ResolveFn = (id: string, importer?: string, aliasOnly?: boolean, ssr?: boolean) => Promise<string | undefined>;
  3451. declare function resolveConfig(inlineConfig: InlineConfig, command: "build" | "serve", defaultMode?: string, defaultNodeEnv?: string, isPreview?: boolean, patchConfig?: ((config: ResolvedConfig) => void) | undefined, patchPlugins?: ((resolvedPlugins: Plugin[]) => void) | undefined): Promise<ResolvedConfig>;
  3452. declare function sortUserPlugins(plugins: (Plugin | Plugin[])[] | undefined): [Plugin[], Plugin[], Plugin[]];
  3453. declare function loadConfigFromFile(configEnv: ConfigEnv, configFile?: string, configRoot?: string, logLevel?: LogLevel, customLogger?: Logger, configLoader?: "bundle" | "runner" | "native"): Promise<{
  3454. path: string;
  3455. config: UserConfig;
  3456. dependencies: string[];
  3457. } | null>;
  3458. //#endregion
  3459. //#region src/node/idResolver.d.ts
  3460. type ResolveIdFn = (environment: PartialEnvironment, id: string, importer?: string, aliasOnly?: boolean) => Promise<string | undefined>;
  3461. /**
  3462. * Create an internal resolver to be used in special scenarios, e.g.
  3463. * optimizer and handling css @imports
  3464. */
  3465. declare function createIdResolver(config: ResolvedConfig, options?: Partial<InternalResolveOptions>): ResolveIdFn;
  3466. //#endregion
  3467. //#region src/node/server/middlewares/error.d.ts
  3468. declare function buildErrorMessage(err: RollupError, args?: string[], includeStack?: boolean): string;
  3469. //#endregion
  3470. //#region src/node/ssr/runtime/serverModuleRunner.d.ts
  3471. /**
  3472. * @experimental
  3473. */
  3474. interface ServerModuleRunnerOptions extends Omit<ModuleRunnerOptions, "root" | "fetchModule" | "hmr" | "transport"> {
  3475. /**
  3476. * Disable HMR or configure HMR logger.
  3477. */
  3478. hmr?: false | {
  3479. logger?: ModuleRunnerHmr["logger"];
  3480. };
  3481. /**
  3482. * Provide a custom module evaluator. This controls how the code is executed.
  3483. */
  3484. evaluator?: ModuleEvaluator;
  3485. }
  3486. declare const createServerModuleRunnerTransport: (options: {
  3487. channel: NormalizedServerHotChannel;
  3488. }) => ModuleRunnerTransport;
  3489. /**
  3490. * Create an instance of the Vite SSR runtime that support HMR.
  3491. * @experimental
  3492. */
  3493. declare function createServerModuleRunner(environment: DevEnvironment, options?: ServerModuleRunnerOptions): ModuleRunner;
  3494. //#endregion
  3495. //#region src/node/server/environments/runnableEnvironment.d.ts
  3496. declare function createRunnableDevEnvironment(name: string, config: ResolvedConfig, context?: RunnableDevEnvironmentContext): RunnableDevEnvironment;
  3497. interface RunnableDevEnvironmentContext extends Omit<DevEnvironmentContext, "hot"> {
  3498. runner?: (environment: RunnableDevEnvironment, options?: ServerModuleRunnerOptions) => ModuleRunner;
  3499. runnerOptions?: ServerModuleRunnerOptions;
  3500. hot?: boolean;
  3501. }
  3502. declare function isRunnableDevEnvironment(environment: Environment): environment is RunnableDevEnvironment;
  3503. declare class RunnableDevEnvironment extends DevEnvironment {
  3504. private _runner;
  3505. private _runnerFactory;
  3506. private _runnerOptions;
  3507. constructor(name: string, config: ResolvedConfig, context: RunnableDevEnvironmentContext);
  3508. get runner(): ModuleRunner;
  3509. close(): Promise<void>;
  3510. }
  3511. //#endregion
  3512. //#region src/node/server/environments/fetchableEnvironments.d.ts
  3513. interface FetchableDevEnvironmentContext extends DevEnvironmentContext {
  3514. handleRequest(request: Request): Promise<Response> | Response;
  3515. }
  3516. declare function createFetchableDevEnvironment(name: string, config: ResolvedConfig, context: FetchableDevEnvironmentContext): FetchableDevEnvironment;
  3517. declare function isFetchableDevEnvironment(environment: Environment): environment is FetchableDevEnvironment;
  3518. declare class FetchableDevEnvironment extends DevEnvironment {
  3519. private _handleRequest;
  3520. constructor(name: string, config: ResolvedConfig, context: FetchableDevEnvironmentContext);
  3521. dispatchFetch(request: Request): Promise<Response>;
  3522. }
  3523. //#endregion
  3524. //#region src/node/ssr/runnerImport.d.ts
  3525. interface RunnerImportResult<T$1> {
  3526. module: T$1;
  3527. dependencies: string[];
  3528. }
  3529. /**
  3530. * Import any file using the default Vite environment.
  3531. * @experimental
  3532. */
  3533. declare function runnerImport<T$1>(moduleId: string, inlineConfig?: InlineConfig): Promise<RunnerImportResult<T$1>>;
  3534. //#endregion
  3535. //#region src/node/ssr/fetchModule.d.ts
  3536. interface FetchModuleOptions {
  3537. cached?: boolean;
  3538. inlineSourceMap?: boolean;
  3539. startOffset?: number;
  3540. }
  3541. /**
  3542. * Fetch module information for Vite runner.
  3543. * @experimental
  3544. */
  3545. declare function fetchModule(environment: DevEnvironment, url: string, importer?: string, options?: FetchModuleOptions): Promise<moduleRunner_FetchResult>;
  3546. //#endregion
  3547. //#region src/node/ssr/ssrTransform.d.ts
  3548. interface ModuleRunnerTransformOptions {
  3549. json?: {
  3550. stringify?: boolean;
  3551. };
  3552. }
  3553. declare function ssrTransform(code: string, inMap: SourceMap | {
  3554. mappings: "";
  3555. } | null, url: string, originalCode: string, options?: ModuleRunnerTransformOptions): Promise<TransformResult | null>;
  3556. //#endregion
  3557. //#region src/node/constants.d.ts
  3558. declare const VERSION: string;
  3559. declare const DEFAULT_CLIENT_MAIN_FIELDS: readonly string[];
  3560. declare const DEFAULT_SERVER_MAIN_FIELDS: readonly string[];
  3561. declare const DEFAULT_CLIENT_CONDITIONS: readonly string[];
  3562. declare const DEFAULT_SERVER_CONDITIONS: readonly string[];
  3563. declare const DEFAULT_EXTERNAL_CONDITIONS: readonly string[];
  3564. declare const defaultAllowedOrigins: RegExp;
  3565. //#endregion
  3566. //#region src/node/utils.d.ts
  3567. /**
  3568. * Inlined to keep `@rollup/pluginutils` in devDependencies
  3569. */
  3570. type FilterPattern = ReadonlyArray<string | RegExp> | string | RegExp | null;
  3571. declare const createFilter: (include?: FilterPattern, exclude?: FilterPattern, options?: {
  3572. resolve?: string | false | null;
  3573. }) => (id: string | unknown) => boolean;
  3574. declare const rollupVersion: string;
  3575. declare function normalizePath(id: string): string;
  3576. declare const isCSSRequest: (request: string) => boolean;
  3577. declare function mergeConfig<D extends Record<string, any>, O extends Record<string, any>>(defaults: D extends Function ? never : D, overrides: O extends Function ? never : O, isRoot?: boolean): Record<string, any>;
  3578. declare function mergeAlias(a?: AliasOptions, b?: AliasOptions): AliasOptions | undefined;
  3579. //#endregion
  3580. //#region src/node/server/send.d.ts
  3581. interface SendOptions {
  3582. etag?: string;
  3583. cacheControl?: string;
  3584. headers?: OutgoingHttpHeaders;
  3585. map?: SourceMap | {
  3586. mappings: "";
  3587. } | null;
  3588. }
  3589. declare function send(req: http.IncomingMessage, res: ServerResponse, content: string | Buffer, type: string, options: SendOptions): void;
  3590. //#endregion
  3591. //#region src/node/server/searchRoot.d.ts
  3592. /**
  3593. * Search up for the nearest workspace root
  3594. */
  3595. declare function searchForWorkspaceRoot(current: string, root?: string): string;
  3596. //#endregion
  3597. //#region src/node/server/middlewares/static.d.ts
  3598. /**
  3599. * Check if the url is allowed to be served, via the `server.fs` config.
  3600. * @deprecated Use the `isFileLoadingAllowed` function instead.
  3601. */
  3602. declare function isFileServingAllowed(config: ResolvedConfig, url: string): boolean;
  3603. declare function isFileServingAllowed(url: string, server: ViteDevServer): boolean;
  3604. /**
  3605. * Warning: parameters are not validated, only works with normalized absolute paths
  3606. */
  3607. declare function isFileLoadingAllowed(config: ResolvedConfig, filePath: string): boolean;
  3608. //#endregion
  3609. //#region src/node/env.d.ts
  3610. declare function loadEnv(mode: string, envDir: string | false, prefixes?: string | string[]): Record<string, string>;
  3611. declare function resolveEnvPrefix({
  3612. envPrefix
  3613. }: UserConfig): string[];
  3614. //#endregion
  3615. //#region src/node/plugins/manifest.d.ts
  3616. type Manifest = Record<string, ManifestChunk>;
  3617. interface ManifestChunk {
  3618. /**
  3619. * The input file name of this chunk / asset if known
  3620. */
  3621. src?: string;
  3622. /**
  3623. * The output file name of this chunk / asset
  3624. */
  3625. file: string;
  3626. /**
  3627. * The list of CSS files imported by this chunk
  3628. *
  3629. * This field is only present in JS chunks.
  3630. */
  3631. css?: string[];
  3632. /**
  3633. * The list of asset files imported by this chunk, excluding CSS files
  3634. *
  3635. * This field is only present in JS chunks.
  3636. */
  3637. assets?: string[];
  3638. /**
  3639. * Whether this chunk or asset is an entry point
  3640. */
  3641. isEntry?: boolean;
  3642. /**
  3643. * The name of this chunk / asset if known
  3644. */
  3645. name?: string;
  3646. /**
  3647. * Whether this chunk is a dynamic entry point
  3648. *
  3649. * This field is only present in JS chunks.
  3650. */
  3651. isDynamicEntry?: boolean;
  3652. /**
  3653. * The list of statically imported chunks by this chunk
  3654. *
  3655. * The values are the keys of the manifest. This field is only present in JS chunks.
  3656. */
  3657. imports?: string[];
  3658. /**
  3659. * The list of dynamically imported chunks by this chunk
  3660. *
  3661. * The values are the keys of the manifest. This field is only present in JS chunks.
  3662. */
  3663. dynamicImports?: string[];
  3664. }
  3665. //#endregion
  3666. export { type Alias, type AliasOptions, type AnymatchFn, type AnymatchPattern, type AppType, type BindCLIShortcutsOptions, type BuildAppHook, BuildEnvironment, type BuildEnvironmentOptions, type BuildOptions, type BuilderOptions, type CLIShortcut, type CSSModulesOptions, type CSSOptions, type ChunkMetadata, type CommonServerOptions, type ConfigEnv, type ConfigPluginContext, type Connect, type ConnectedPayload, type CorsOptions, type CorsOrigin, type CustomEventMap, type CustomPayload, type CustomPluginOptionsVite, type DepOptimizationConfig, type DepOptimizationMetadata, type DepOptimizationOptions, DevEnvironment, type DevEnvironmentContext, type DevEnvironmentOptions, type ESBuildOptions, type ESBuildTransformResult, type Environment, type EnvironmentModuleGraph, type EnvironmentModuleNode, type EnvironmentOptions, type ErrorPayload, type EsbuildTransformOptions, type ExperimentalOptions, type ExportsData, type FSWatcher, type FetchFunction, type FetchModuleOptions, type FetchResult, type FetchableDevEnvironment, type FetchableDevEnvironmentContext, type FileSystemServeOptions, type FilterPattern, type FullReloadPayload, type GeneralImportGlobOptions, type HMRPayload, type HTMLOptions, type HmrContext, type HmrOptions, type HookHandler, type HotChannel, type HotChannelClient, type HotChannelListener, type HotPayload, type HotUpdateOptions, type HtmlTagDescriptor, type index_d_exports as HttpProxy, type HttpServer, type ImportGlobFunction, type ImportGlobOptions, type IndexHtmlTransform, type IndexHtmlTransformContext, type IndexHtmlTransformHook, type IndexHtmlTransformResult, type InferCustomEventPayload, type InlineConfig, type InternalResolveOptions, type InvalidatePayload, type JsonOptions, type KnownAsTypeMap, type LegacyOptions, type LessPreprocessorOptions, type LibraryFormats, type LibraryOptions, type LightningCSSOptions, type LogErrorOptions, type LogLevel, type LogOptions, type LogType, type Logger, type LoggerOptions, type Manifest, type ManifestChunk, type MapToFunction, type AnymatchMatcher as Matcher, type MinimalPluginContextWithoutEnvironment, type ModuleGraph, type ModuleNode, type ModulePreloadOptions, type ModuleRunnerTransformOptions, type NormalizedHotChannel, type NormalizedHotChannelClient, type NormalizedServerHotChannel, type OptimizedDepInfo, type Plugin, type PluginContainer, type PluginHookUtils, type PluginOption, type PreprocessCSSResult, type PreviewOptions, type PreviewServer, type PreviewServerHook, type ProxyOptions, type PrunePayload, type RenderBuiltAssetUrl, type ResolveFn, type ResolveModulePreloadDependenciesFn, type ResolveOptions, type ResolvedBuildEnvironmentOptions, type ResolvedBuildOptions, type ResolvedCSSOptions, type ResolvedConfig, type ResolvedDevEnvironmentOptions, type ResolvedModulePreloadOptions, type ResolvedPreviewOptions, type ResolvedSSROptions, type ResolvedServerOptions, type ResolvedServerUrls, type ResolvedUrl, type ResolvedWorkerOptions, type ResolverFunction, type ResolverObject, type Rollup, type RollupCommonJSOptions, type RollupDynamicImportVarsOptions, type RunnableDevEnvironment, type RunnableDevEnvironmentContext, type SSROptions, type SSRTarget, type SassPreprocessorOptions, type SendOptions, type ServerHook, type ServerHotChannel, type ServerModuleRunnerOptions, type ServerOptions$1 as ServerOptions, type SkipInformation, type SsrDepOptimizationConfig, type StylusPreprocessorOptions, type Terser, type TerserOptions, type TransformOptions, type TransformResult, type Update, type UpdatePayload, type UserConfig, type UserConfigExport, type UserConfigFn, type UserConfigFnObject, type UserConfigFnPromise, type ViteBuilder, type ViteDevServer, type WatchOptions, type WebSocket, type WebSocketAlias, type WebSocketClient, type WebSocketCustomListener, type WebSocketServer, build, buildErrorMessage, createBuilder, createFetchableDevEnvironment, createFilter, createIdResolver, createLogger, createRunnableDevEnvironment, createServer, createServerHotChannel, createServerModuleRunner, createServerModuleRunnerTransport, defaultAllowedOrigins, DEFAULT_CLIENT_CONDITIONS as defaultClientConditions, DEFAULT_CLIENT_MAIN_FIELDS as defaultClientMainFields, DEFAULT_EXTERNAL_CONDITIONS as defaultExternalConditions, DEFAULT_SERVER_CONDITIONS as defaultServerConditions, DEFAULT_SERVER_MAIN_FIELDS as defaultServerMainFields, defineConfig, esbuildVersion, fetchModule, formatPostcssSourceMap, isCSSRequest, isFetchableDevEnvironment, isFileLoadingAllowed, isFileServingAllowed, isRunnableDevEnvironment, loadConfigFromFile, loadEnv, mergeAlias, mergeConfig, ssrTransform as moduleRunnerTransform, normalizePath, optimizeDeps, parseAst, parseAstAsync, perEnvironmentPlugin, perEnvironmentState, preprocessCSS, preview, resolveConfig, resolveEnvPrefix, rollupVersion, runnerImport, searchForWorkspaceRoot, send, sortUserPlugins, transformWithEsbuild, VERSION as version };