index.d.ts 121 KB

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