b4c4943aa639981078bb69b2b411bfc9c75fe9753274c5677505c038a20b580eac0daecca9e8b952b724a73836ac2498215f18de6b0fbfa89a0998226a7216 118 KB

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