index.d.ts 118 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545
  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. /**
  1186. * Check if the url is allowed to be served, via the `server.fs` config.
  1187. */
  1188. export declare function isFileServingAllowed(url: string, server: ViteDevServer): boolean;
  1189. export declare interface JsonOptions {
  1190. /**
  1191. * Generate a named export for every property of the JSON object
  1192. * @default true
  1193. */
  1194. namedExports?: boolean;
  1195. /**
  1196. * Generate performant output as JSON.parse("stringified").
  1197. * Enabling this will disable namedExports.
  1198. * @default false
  1199. */
  1200. stringify?: boolean;
  1201. }
  1202. export { KnownAsTypeMap }
  1203. export declare interface LegacyOptions {
  1204. /**
  1205. * Revert vite build --ssr to the v2.9 strategy. Use CJS SSR build and v2.9 externalization heuristics
  1206. *
  1207. * @experimental
  1208. * @deprecated
  1209. * @default false
  1210. */
  1211. buildSsrCjsExternalHeuristics?: boolean;
  1212. /**
  1213. * In Vite 6.0.8 / 5.4.11 / 4.5.5 and below, WebSocket server was able to connect from any web pages. However,
  1214. * that could be exploited by a malicious web page.
  1215. *
  1216. * In Vite 6.0.9+ / 5.4.12+ / 4.5.6+ the WebSocket server now requires a token to connect from a web page.
  1217. * But this may break some plugins and frameworks that connects to the WebSocket server
  1218. * on their own. Enabling this option will make Vite skip the token check.
  1219. *
  1220. * **We do not recommend enabling this option unless you are sure that you are fine with
  1221. * that security weakness.**
  1222. */
  1223. skipWebSocketTokenCheck?: boolean;
  1224. }
  1225. export declare type LibraryFormats = 'es' | 'cjs' | 'umd' | 'iife';
  1226. export declare interface LibraryOptions {
  1227. /**
  1228. * Path of library entry
  1229. */
  1230. entry: InputOption;
  1231. /**
  1232. * The name of the exposed global variable. Required when the `formats` option includes
  1233. * `umd` or `iife`
  1234. */
  1235. name?: string;
  1236. /**
  1237. * Output bundle formats
  1238. * @default ['es', 'umd']
  1239. */
  1240. formats?: LibraryFormats[];
  1241. /**
  1242. * The name of the package file output. The default file name is the name option
  1243. * of the project package.json. It can also be defined as a function taking the
  1244. * format as an argument.
  1245. */
  1246. fileName?: string | ((format: ModuleFormat, entryName: string) => string);
  1247. }
  1248. /**
  1249. * Options are spread, so you can also use options that are not typed here like
  1250. * visitor (not exposed because it would impact too much the bundle size)
  1251. */
  1252. export declare type LightningCSSOptions = {
  1253. targets?: Targets
  1254. include?: Features
  1255. exclude?: Features
  1256. drafts?: Drafts
  1257. nonStandard?: NonStandard
  1258. pseudoClasses?: PseudoClasses
  1259. unusedSymbols?: string[]
  1260. cssModules?: CSSModulesConfig
  1261. }
  1262. export declare function loadConfigFromFile(configEnv: ConfigEnv, configFile?: string, configRoot?: string, logLevel?: LogLevel): Promise<{
  1263. path: string;
  1264. config: UserConfig;
  1265. dependencies: string[];
  1266. } | null>;
  1267. export declare function loadEnv(mode: string, envDir: string, prefixes?: string | string[]): Record<string, string>;
  1268. export declare interface LogErrorOptions extends LogOptions {
  1269. error?: Error | RollupError | null;
  1270. }
  1271. export declare interface Logger {
  1272. info(msg: string, options?: LogOptions): void;
  1273. warn(msg: string, options?: LogOptions): void;
  1274. warnOnce(msg: string, options?: LogOptions): void;
  1275. error(msg: string, options?: LogErrorOptions): void;
  1276. clearScreen(type: LogType): void;
  1277. hasErrorLogged(error: Error | RollupError): boolean;
  1278. hasWarned: boolean;
  1279. }
  1280. export declare interface LoggerOptions {
  1281. prefix?: string;
  1282. allowClearScreen?: boolean;
  1283. customLogger?: Logger;
  1284. }
  1285. export declare type LogLevel = LogType | 'silent';
  1286. export declare interface LogOptions {
  1287. clear?: boolean;
  1288. timestamp?: boolean;
  1289. }
  1290. export declare type LogType = 'error' | 'warn' | 'info';
  1291. export declare type Manifest = Record<string, ManifestChunk>;
  1292. export declare interface ManifestChunk {
  1293. src?: string;
  1294. file: string;
  1295. css?: string[];
  1296. assets?: string[];
  1297. isEntry?: boolean;
  1298. isDynamicEntry?: boolean;
  1299. imports?: string[];
  1300. dynamicImports?: string[];
  1301. }
  1302. export declare type MapToFunction<T> = T extends Function ? T : never
  1303. export declare type Matcher = AnymatchPattern | AnymatchPattern[]
  1304. export declare function mergeAlias(a?: AliasOptions, b?: AliasOptions): AliasOptions | undefined;
  1305. 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>;
  1306. export declare class ModuleGraph {
  1307. private resolveId;
  1308. urlToModuleMap: Map<string, ModuleNode>;
  1309. idToModuleMap: Map<string, ModuleNode>;
  1310. fileToModulesMap: Map<string, Set<ModuleNode>>;
  1311. safeModulesPath: Set<string>;
  1312. /* Excluded from this release type: _unresolvedUrlToModuleMap */
  1313. /* Excluded from this release type: _ssrUnresolvedUrlToModuleMap */
  1314. constructor(resolveId: (url: string, ssr: boolean) => Promise<PartialResolvedId | null>);
  1315. getModuleByUrl(rawUrl: string, ssr?: boolean): Promise<ModuleNode | undefined>;
  1316. getModuleById(id: string): ModuleNode | undefined;
  1317. getModulesByFile(file: string): Set<ModuleNode> | undefined;
  1318. onFileChange(file: string): void;
  1319. invalidateModule(mod: ModuleNode, seen?: Set<ModuleNode>, timestamp?: number, isHmr?: boolean, hmrBoundaries?: ModuleNode[]): void;
  1320. invalidateAll(): void;
  1321. /**
  1322. * Update the module graph based on a module's updated imports information
  1323. * If there are dependencies that no longer have any importers, they are
  1324. * returned as a Set.
  1325. */
  1326. 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>;
  1327. ensureEntryFromUrl(rawUrl: string, ssr?: boolean, setIsSelfAccepting?: boolean): Promise<ModuleNode>;
  1328. /* Excluded from this release type: _ensureEntryFromUrl */
  1329. createFileOnlyEntry(file: string): ModuleNode;
  1330. resolveUrl(url: string, ssr?: boolean): Promise<ResolvedUrl>;
  1331. /* Excluded from this release type: _getUnresolvedUrlToModule */
  1332. /* Excluded from this release type: _setUnresolvedUrlToModule */
  1333. /* Excluded from this release type: _resolveUrl */
  1334. }
  1335. export declare class ModuleNode {
  1336. /**
  1337. * Public served url path, starts with /
  1338. */
  1339. url: string;
  1340. /**
  1341. * Resolved file system path + query
  1342. */
  1343. id: string | null;
  1344. file: string | null;
  1345. type: 'js' | 'css';
  1346. info?: ModuleInfo;
  1347. meta?: Record<string, any>;
  1348. importers: Set<ModuleNode>;
  1349. clientImportedModules: Set<ModuleNode>;
  1350. ssrImportedModules: Set<ModuleNode>;
  1351. acceptedHmrDeps: Set<ModuleNode>;
  1352. acceptedHmrExports: Set<string> | null;
  1353. importedBindings: Map<string, Set<string>> | null;
  1354. isSelfAccepting?: boolean;
  1355. transformResult: TransformResult | null;
  1356. ssrTransformResult: TransformResult | null;
  1357. ssrModule: Record<string, any> | null;
  1358. ssrError: Error | null;
  1359. lastHMRTimestamp: number;
  1360. lastInvalidationTimestamp: number;
  1361. /**
  1362. * @param setIsSelfAccepting - set `false` to set `isSelfAccepting` later. e.g. #7870
  1363. */
  1364. constructor(url: string, setIsSelfAccepting?: boolean);
  1365. get importedModules(): Set<ModuleNode>;
  1366. }
  1367. export declare interface ModulePreloadOptions {
  1368. /**
  1369. * Whether to inject a module preload polyfill.
  1370. * Note: does not apply to library mode.
  1371. * @default true
  1372. */
  1373. polyfill?: boolean;
  1374. /**
  1375. * Resolve the list of dependencies to preload for a given dynamic import
  1376. * @experimental
  1377. */
  1378. resolveDependencies?: ResolveModulePreloadDependenciesFn;
  1379. }
  1380. declare interface NonStandard {
  1381. /** Whether to enable the non-standard >>> and /deep/ selector combinators used by Angular and Vue. */
  1382. deepSelectorCombinator?: boolean
  1383. }
  1384. export declare function normalizePath(id: string): string;
  1385. export declare interface OptimizedDepInfo {
  1386. id: string;
  1387. file: string;
  1388. src?: string;
  1389. needsInterop?: boolean;
  1390. browserHash?: string;
  1391. fileHash?: string;
  1392. /**
  1393. * During optimization, ids can still be resolved to their final location
  1394. * but the bundles may not yet be saved to disk
  1395. */
  1396. processing?: Promise<void>;
  1397. /**
  1398. * ExportData cache, discovered deps will parse the src entry to get exports
  1399. * data used both to define if interop is needed and when pre-bundling
  1400. */
  1401. exportsData?: Promise<ExportsData>;
  1402. }
  1403. /**
  1404. * Scan and optimize dependencies within a project.
  1405. * Used by Vite CLI when running `vite optimize`.
  1406. */
  1407. export declare function optimizeDeps(config: ResolvedConfig, force?: boolean | undefined, asCommand?: boolean): Promise<DepOptimizationMetadata>;
  1408. /** Cache for package.json resolution and package.json contents */
  1409. export declare type PackageCache = Map<string, PackageData>;
  1410. export declare interface PackageData {
  1411. dir: string;
  1412. hasSideEffects: (id: string) => boolean | 'no-treeshake';
  1413. webResolvedImports: Record<string, string | undefined>;
  1414. nodeResolvedImports: Record<string, string | undefined>;
  1415. setResolvedCache: (key: string, entry: string, targetWeb: boolean) => void;
  1416. getResolvedCache: (key: string, targetWeb: boolean) => string | undefined;
  1417. data: {
  1418. [field: string]: any;
  1419. name: string;
  1420. type: string;
  1421. version: string;
  1422. main: string;
  1423. module: string;
  1424. browser: string | Record<string, string | false>;
  1425. exports: string | Record<string, any> | string[];
  1426. imports: Record<string, any>;
  1427. dependencies: Record<string, string>;
  1428. };
  1429. }
  1430. /**
  1431. * Vite plugins extends the Rollup plugin interface with a few extra
  1432. * vite-specific options. A valid vite plugin is also a valid Rollup plugin.
  1433. * On the contrary, a Rollup plugin may or may NOT be a valid vite universal
  1434. * plugin, since some Rollup features do not make sense in an unbundled
  1435. * dev server context. That said, as long as a rollup plugin doesn't have strong
  1436. * coupling between its bundle phase and output phase hooks then it should
  1437. * just work (that means, most of them).
  1438. *
  1439. * By default, the plugins are run during both serve and build. When a plugin
  1440. * is applied during serve, it will only run **non output plugin hooks** (see
  1441. * rollup type definition of {@link rollup#PluginHooks}). You can think of the
  1442. * dev server as only running `const bundle = rollup.rollup()` but never calling
  1443. * `bundle.generate()`.
  1444. *
  1445. * A plugin that expects to have different behavior depending on serve/build can
  1446. * export a factory function that receives the command being run via options.
  1447. *
  1448. * If a plugin should be applied only for server or build, a function format
  1449. * config file can be used to conditional determine the plugins to use.
  1450. */
  1451. declare interface Plugin_2 extends Plugin_3 {
  1452. /**
  1453. * Enforce plugin invocation tier similar to webpack loaders.
  1454. *
  1455. * Plugin invocation order:
  1456. * - alias resolution
  1457. * - `enforce: 'pre'` plugins
  1458. * - vite core plugins
  1459. * - normal plugins
  1460. * - vite build plugins
  1461. * - `enforce: 'post'` plugins
  1462. * - vite build post plugins
  1463. */
  1464. enforce?: 'pre' | 'post';
  1465. /**
  1466. * Apply the plugin only for serve or build, or on certain conditions.
  1467. */
  1468. apply?: 'serve' | 'build' | ((this: void, config: UserConfig, env: ConfigEnv) => boolean);
  1469. /**
  1470. * Modify vite config before it's resolved. The hook can either mutate the
  1471. * passed-in config directly, or return a partial config object that will be
  1472. * deeply merged into existing config.
  1473. *
  1474. * Note: User plugins are resolved before running this hook so injecting other
  1475. * plugins inside the `config` hook will have no effect.
  1476. */
  1477. config?: ObjectHook<(this: void, config: UserConfig, env: ConfigEnv) => UserConfig | null | void | Promise<UserConfig | null | void>>;
  1478. /**
  1479. * Use this hook to read and store the final resolved vite config.
  1480. */
  1481. configResolved?: ObjectHook<(this: void, config: ResolvedConfig) => void | Promise<void>>;
  1482. /**
  1483. * Configure the vite server. The hook receives the {@link ViteDevServer}
  1484. * instance. This can also be used to store a reference to the server
  1485. * for use in other hooks.
  1486. *
  1487. * The hooks will be called before internal middlewares are applied. A hook
  1488. * can return a post hook that will be called after internal middlewares
  1489. * are applied. Hook can be async functions and will be called in series.
  1490. */
  1491. configureServer?: ObjectHook<ServerHook>;
  1492. /**
  1493. * Configure the preview server. The hook receives the {@link PreviewServerForHook}
  1494. * instance. This can also be used to store a reference to the server
  1495. * for use in other hooks.
  1496. *
  1497. * The hooks are called before other middlewares are applied. A hook can
  1498. * return a post hook that will be called after other middlewares are
  1499. * applied. Hooks can be async functions and will be called in series.
  1500. */
  1501. configurePreviewServer?: ObjectHook<PreviewServerHook>;
  1502. /**
  1503. * Transform index.html.
  1504. * The hook receives the following arguments:
  1505. *
  1506. * - html: string
  1507. * - ctx?: vite.ServerContext (only present during serve)
  1508. * - bundle?: rollup.OutputBundle (only present during build)
  1509. *
  1510. * It can either return a transformed string, or a list of html tag
  1511. * descriptors that will be injected into the `<head>` or `<body>`.
  1512. *
  1513. * By default the transform is applied **after** vite's internal html
  1514. * transform. If you need to apply the transform before vite, use an object:
  1515. * `{ order: 'pre', handler: hook }`
  1516. */
  1517. transformIndexHtml?: IndexHtmlTransform;
  1518. /**
  1519. * Perform custom handling of HMR updates.
  1520. * The handler receives a context containing changed filename, timestamp, a
  1521. * list of modules affected by the file change, and the dev server instance.
  1522. *
  1523. * - The hook can return a filtered list of modules to narrow down the update.
  1524. * e.g. for a Vue SFC, we can narrow down the part to update by comparing
  1525. * the descriptors.
  1526. *
  1527. * - The hook can also return an empty array and then perform custom updates
  1528. * by sending a custom hmr payload via server.ws.send().
  1529. *
  1530. * - If the hook doesn't return a value, the hmr update will be performed as
  1531. * normal.
  1532. */
  1533. handleHotUpdate?: ObjectHook<(this: void, ctx: HmrContext) => Array<ModuleNode> | void | Promise<Array<ModuleNode> | void>>;
  1534. /**
  1535. * extend hooks with ssr flag
  1536. */
  1537. resolveId?: ObjectHook<(this: PluginContext, source: string, importer: string | undefined, options: {
  1538. assertions: Record<string, string>;
  1539. custom?: CustomPluginOptions;
  1540. ssr?: boolean;
  1541. /* Excluded from this release type: scan */
  1542. isEntry: boolean;
  1543. }) => Promise<ResolveIdResult> | ResolveIdResult>;
  1544. load?: ObjectHook<(this: PluginContext, id: string, options?: {
  1545. ssr?: boolean;
  1546. }) => Promise<LoadResult> | LoadResult>;
  1547. transform?: ObjectHook<(this: TransformPluginContext, code: string, id: string, options?: {
  1548. ssr?: boolean;
  1549. }) => Promise<TransformResult_2> | TransformResult_2>;
  1550. }
  1551. export { Plugin_2 as Plugin }
  1552. export declare interface PluginContainer {
  1553. options: InputOptions;
  1554. getModuleInfo(id: string): ModuleInfo | null;
  1555. buildStart(options: InputOptions): Promise<void>;
  1556. resolveId(id: string, importer?: string, options?: {
  1557. assertions?: Record<string, string>;
  1558. custom?: CustomPluginOptions;
  1559. skip?: Set<Plugin_2>;
  1560. ssr?: boolean;
  1561. /* Excluded from this release type: scan */
  1562. isEntry?: boolean;
  1563. }): Promise<PartialResolvedId | null>;
  1564. transform(code: string, id: string, options?: {
  1565. inMap?: SourceDescription['map'];
  1566. ssr?: boolean;
  1567. }): Promise<{
  1568. code: string;
  1569. map: SourceMap | null;
  1570. }>;
  1571. load(id: string, options?: {
  1572. ssr?: boolean;
  1573. }): Promise<LoadResult | null>;
  1574. close(): Promise<void>;
  1575. }
  1576. export declare interface PluginHookUtils {
  1577. getSortedPlugins: (hookName: keyof Plugin_2) => Plugin_2[];
  1578. getSortedPluginHooks: <K extends keyof Plugin_2>(hookName: K) => NonNullable<HookHandler<Plugin_2[K]>>[];
  1579. }
  1580. export declare type PluginOption = Plugin_2 | false | null | undefined | PluginOption[] | Promise<Plugin_2 | false | null | undefined | PluginOption[]>;
  1581. /**
  1582. * @experimental
  1583. */
  1584. export declare function preprocessCSS(code: string, filename: string, config: ResolvedConfig): Promise<PreprocessCSSResult>;
  1585. export declare interface PreprocessCSSResult {
  1586. code: string;
  1587. map?: SourceMapInput;
  1588. modules?: Record<string, string>;
  1589. deps?: Set<string>;
  1590. }
  1591. /**
  1592. * Starts the Vite server in preview mode, to simulate a production deployment
  1593. */
  1594. export declare function preview(inlineConfig?: InlineConfig): Promise<PreviewServer>;
  1595. export declare interface PreviewOptions extends CommonServerOptions {
  1596. }
  1597. export declare interface PreviewServer extends PreviewServerForHook {
  1598. resolvedUrls: ResolvedServerUrls;
  1599. }
  1600. export declare interface PreviewServerForHook {
  1601. /**
  1602. * The resolved vite config object
  1603. */
  1604. config: ResolvedConfig;
  1605. /**
  1606. * A connect app instance.
  1607. * - Can be used to attach custom middlewares to the preview server.
  1608. * - Can also be used as the handler function of a custom http server
  1609. * or as a middleware in any connect-style Node.js frameworks
  1610. *
  1611. * https://github.com/senchalabs/connect#use-middleware
  1612. */
  1613. middlewares: Connect.Server;
  1614. /**
  1615. * native Node http server instance
  1616. */
  1617. httpServer: http.Server;
  1618. /**
  1619. * The resolved urls Vite prints on the CLI
  1620. */
  1621. resolvedUrls: ResolvedServerUrls | null;
  1622. /**
  1623. * Print server urls
  1624. */
  1625. printUrls(): void;
  1626. }
  1627. export declare type PreviewServerHook = (this: void, server: PreviewServerForHook) => (() => void) | void | Promise<(() => void) | void>;
  1628. export declare interface ProxyOptions extends HttpProxy.ServerOptions {
  1629. /**
  1630. * rewrite path
  1631. */
  1632. rewrite?: (path: string) => string;
  1633. /**
  1634. * configure the proxy server (e.g. listen to events)
  1635. */
  1636. configure?: (proxy: HttpProxy.Server, options: ProxyOptions) => void;
  1637. /**
  1638. * webpack-dev-server style bypass function
  1639. */
  1640. bypass?: (req: http.IncomingMessage, res: http.ServerResponse, options: ProxyOptions) => void | null | undefined | false | string;
  1641. }
  1642. export { PrunePayload }
  1643. declare interface PseudoClasses {
  1644. hover?: string,
  1645. active?: string,
  1646. focus?: string,
  1647. focusVisible?: string,
  1648. focusWithin?: string
  1649. }
  1650. export declare type RenderBuiltAssetUrl = (filename: string, type: {
  1651. type: 'asset' | 'public';
  1652. hostId: string;
  1653. hostType: 'js' | 'css' | 'html';
  1654. ssr: boolean;
  1655. }) => string | {
  1656. relative?: boolean;
  1657. runtime?: string;
  1658. } | undefined;
  1659. /**
  1660. * Resolve base url. Note that some users use Vite to build for non-web targets like
  1661. * electron or expects to deploy
  1662. */
  1663. export declare function resolveBaseUrl(base: string | undefined, isBuild: boolean, logger: Logger): string;
  1664. export declare function resolveConfig(inlineConfig: InlineConfig, command: 'build' | 'serve', defaultMode?: string, defaultNodeEnv?: string): Promise<ResolvedConfig>;
  1665. export declare interface ResolvedBuildOptions extends Required<Omit<BuildOptions, 'polyfillModulePreload'>> {
  1666. modulePreload: false | ResolvedModulePreloadOptions;
  1667. }
  1668. export declare type ResolvedConfig = Readonly<Omit<UserConfig, 'plugins' | 'css' | 'assetsInclude' | 'optimizeDeps' | 'worker' | 'build'> & {
  1669. configFile: string | undefined;
  1670. configFileDependencies: string[];
  1671. inlineConfig: InlineConfig;
  1672. root: string;
  1673. base: string;
  1674. /* Excluded from this release type: rawBase */
  1675. publicDir: string;
  1676. cacheDir: string;
  1677. command: 'build' | 'serve';
  1678. mode: string;
  1679. isWorker: boolean;
  1680. /* Excluded from this release type: mainConfig */
  1681. isProduction: boolean;
  1682. envDir: string;
  1683. env: Record<string, any>;
  1684. resolve: Required<ResolveOptions> & {
  1685. alias: Alias[];
  1686. };
  1687. plugins: readonly Plugin_2[];
  1688. css: ResolvedCSSOptions | undefined;
  1689. esbuild: ESBuildOptions | false;
  1690. server: ResolvedServerOptions;
  1691. build: ResolvedBuildOptions;
  1692. preview: ResolvedPreviewOptions;
  1693. ssr: ResolvedSSROptions;
  1694. assetsInclude: (file: string) => boolean;
  1695. logger: Logger;
  1696. createResolver: (options?: Partial<InternalResolveOptions>) => ResolveFn;
  1697. optimizeDeps: DepOptimizationOptions;
  1698. /* Excluded from this release type: packageCache */
  1699. worker: ResolveWorkerOptions;
  1700. appType: AppType;
  1701. experimental: ExperimentalOptions;
  1702. /**
  1703. * The token to connect to the WebSocket server from browsers.
  1704. *
  1705. * We recommend using `import.meta.hot` rather than connecting
  1706. * to the WebSocket server directly.
  1707. * If you have a usecase that requires connecting to the WebSocket
  1708. * server, please create an issue so that we can discuss.
  1709. *
  1710. * @deprecated use `import.meta.hot`
  1711. */
  1712. webSocketToken: string;
  1713. /* Excluded from this release type: additionalAllowedHosts */
  1714. } & PluginHookUtils>;
  1715. export declare type ResolvedCSSOptions = Omit<CSSOptions, 'lightningcss'> & {
  1716. lightningcss?: LightningCSSOptions & {
  1717. targets: LightningCSSOptions['targets'];
  1718. };
  1719. };
  1720. export declare interface ResolvedModulePreloadOptions {
  1721. polyfill: boolean;
  1722. resolveDependencies?: ResolveModulePreloadDependenciesFn;
  1723. }
  1724. export declare interface ResolvedPreviewOptions extends PreviewOptions {
  1725. }
  1726. export declare interface ResolvedServerOptions extends ServerOptions {
  1727. fs: Required<FileSystemServeOptions>;
  1728. middlewareMode: boolean;
  1729. sourcemapIgnoreList: Exclude<ServerOptions['sourcemapIgnoreList'], false | undefined>;
  1730. }
  1731. export declare interface ResolvedServerUrls {
  1732. local: string[];
  1733. network: string[];
  1734. }
  1735. export declare interface ResolvedSSROptions extends SSROptions {
  1736. target: SSRTarget;
  1737. format: SSRFormat;
  1738. optimizeDeps: SsrDepOptimizationOptions;
  1739. }
  1740. export declare type ResolvedUrl = [
  1741. url: string,
  1742. resolvedId: string,
  1743. meta: object | null | undefined
  1744. ];
  1745. export declare function resolveEnvPrefix({ envPrefix, }: UserConfig): string[];
  1746. export declare type ResolveFn = (id: string, importer?: string, aliasOnly?: boolean, ssr?: boolean) => Promise<string | undefined>;
  1747. export declare type ResolveModulePreloadDependenciesFn = (filename: string, deps: string[], context: {
  1748. hostId: string;
  1749. hostType: 'html' | 'js';
  1750. }) => string[];
  1751. export declare interface ResolveOptions {
  1752. /**
  1753. * @default ['module', 'jsnext:main', 'jsnext']
  1754. */
  1755. mainFields?: string[];
  1756. /**
  1757. * @deprecated In future, `mainFields` should be used instead.
  1758. * @default true
  1759. */
  1760. browserField?: boolean;
  1761. conditions?: string[];
  1762. /**
  1763. * @default ['.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx', '.json']
  1764. */
  1765. extensions?: string[];
  1766. dedupe?: string[];
  1767. /**
  1768. * @default false
  1769. */
  1770. preserveSymlinks?: boolean;
  1771. }
  1772. export declare function resolvePackageData(pkgName: string, basedir: string, preserveSymlinks?: boolean, packageCache?: PackageCache): PackageData | null;
  1773. export declare function resolvePackageEntry(id: string, { dir, data, setResolvedCache, getResolvedCache }: PackageData, targetWeb: boolean, options: InternalResolveOptions): string | undefined;
  1774. export declare type ResolverFunction = MapToFunction<PluginHooks['resolveId']>
  1775. export declare interface ResolverObject {
  1776. buildStart?: PluginHooks['buildStart']
  1777. resolveId: ResolverFunction
  1778. }
  1779. export declare interface ResolveWorkerOptions extends PluginHookUtils {
  1780. format: 'es' | 'iife';
  1781. plugins: Plugin_2[];
  1782. rollupOptions: RollupOptions;
  1783. }
  1784. export { Rollup }
  1785. /**
  1786. * https://github.com/rollup/plugins/blob/master/packages/commonjs/types/index.d.ts
  1787. *
  1788. * This source code is licensed under the MIT license found in the
  1789. * LICENSE file at
  1790. * https://github.com/rollup/plugins/blob/master/LICENSE
  1791. */
  1792. export declare interface RollupCommonJSOptions {
  1793. /**
  1794. * A minimatch pattern, or array of patterns, which specifies the files in
  1795. * the build the plugin should operate on. By default, all files with
  1796. * extension `".cjs"` or those in `extensions` are included, but you can
  1797. * narrow this list by only including specific files. These files will be
  1798. * analyzed and transpiled if either the analysis does not find ES module
  1799. * specific statements or `transformMixedEsModules` is `true`.
  1800. * @default undefined
  1801. */
  1802. include?: string | RegExp | readonly (string | RegExp)[]
  1803. /**
  1804. * A minimatch pattern, or array of patterns, which specifies the files in
  1805. * the build the plugin should _ignore_. By default, all files with
  1806. * extensions other than those in `extensions` or `".cjs"` are ignored, but you
  1807. * can exclude additional files. See also the `include` option.
  1808. * @default undefined
  1809. */
  1810. exclude?: string | RegExp | readonly (string | RegExp)[]
  1811. /**
  1812. * For extensionless imports, search for extensions other than .js in the
  1813. * order specified. Note that you need to make sure that non-JavaScript files
  1814. * are transpiled by another plugin first.
  1815. * @default [ '.js' ]
  1816. */
  1817. extensions?: ReadonlyArray<string>
  1818. /**
  1819. * If true then uses of `global` won't be dealt with by this plugin
  1820. * @default false
  1821. */
  1822. ignoreGlobal?: boolean
  1823. /**
  1824. * If false, skips source map generation for CommonJS modules. This will
  1825. * improve performance.
  1826. * @default true
  1827. */
  1828. sourceMap?: boolean
  1829. /**
  1830. * Some `require` calls cannot be resolved statically to be translated to
  1831. * imports.
  1832. * When this option is set to `false`, the generated code will either
  1833. * directly throw an error when such a call is encountered or, when
  1834. * `dynamicRequireTargets` is used, when such a call cannot be resolved with a
  1835. * configured dynamic require target.
  1836. * Setting this option to `true` will instead leave the `require` call in the
  1837. * code or use it as a fallback for `dynamicRequireTargets`.
  1838. * @default false
  1839. */
  1840. ignoreDynamicRequires?: boolean
  1841. /**
  1842. * Instructs the plugin whether to enable mixed module transformations. This
  1843. * is useful in scenarios with modules that contain a mix of ES `import`
  1844. * statements and CommonJS `require` expressions. Set to `true` if `require`
  1845. * calls should be transformed to imports in mixed modules, or `false` if the
  1846. * `require` expressions should survive the transformation. The latter can be
  1847. * important if the code contains environment detection, or you are coding
  1848. * for an environment with special treatment for `require` calls such as
  1849. * ElectronJS. See also the `ignore` option.
  1850. * @default false
  1851. */
  1852. transformMixedEsModules?: boolean
  1853. /**
  1854. * By default, this plugin will try to hoist `require` statements as imports
  1855. * to the top of each file. While this works well for many code bases and
  1856. * allows for very efficient ESM output, it does not perfectly capture
  1857. * CommonJS semantics as the order of side effects like log statements may
  1858. * change. But it is especially problematic when there are circular `require`
  1859. * calls between CommonJS modules as those often rely on the lazy execution of
  1860. * nested `require` calls.
  1861. *
  1862. * Setting this option to `true` will wrap all CommonJS files in functions
  1863. * which are executed when they are required for the first time, preserving
  1864. * NodeJS semantics. Note that this can have an impact on the size and
  1865. * performance of the generated code.
  1866. *
  1867. * The default value of `"auto"` will only wrap CommonJS files when they are
  1868. * part of a CommonJS dependency cycle, e.g. an index file that is required by
  1869. * many of its dependencies. All other CommonJS files are hoisted. This is the
  1870. * recommended setting for most code bases.
  1871. *
  1872. * `false` will entirely prevent wrapping and hoist all files. This may still
  1873. * work depending on the nature of cyclic dependencies but will often cause
  1874. * problems.
  1875. *
  1876. * You can also provide a minimatch pattern, or array of patterns, to only
  1877. * specify a subset of files which should be wrapped in functions for proper
  1878. * `require` semantics.
  1879. *
  1880. * `"debug"` works like `"auto"` but after bundling, it will display a warning
  1881. * containing a list of ids that have been wrapped which can be used as
  1882. * minimatch pattern for fine-tuning.
  1883. * @default "auto"
  1884. */
  1885. strictRequires?: boolean | string | RegExp | readonly (string | RegExp)[]
  1886. /**
  1887. * Sometimes you have to leave require statements unconverted. Pass an array
  1888. * containing the IDs or a `id => boolean` function.
  1889. * @default []
  1890. */
  1891. ignore?: ReadonlyArray<string> | ((id: string) => boolean)
  1892. /**
  1893. * In most cases, where `require` calls are inside a `try-catch` clause,
  1894. * they should be left unconverted as it requires an optional dependency
  1895. * that may or may not be installed beside the rolled up package.
  1896. * Due to the conversion of `require` to a static `import` - the call is
  1897. * hoisted to the top of the file, outside the `try-catch` clause.
  1898. *
  1899. * - `true`: Default. All `require` calls inside a `try` will be left unconverted.
  1900. * - `false`: All `require` calls inside a `try` will be converted as if the
  1901. * `try-catch` clause is not there.
  1902. * - `remove`: Remove all `require` calls from inside any `try` block.
  1903. * - `string[]`: Pass an array containing the IDs to left unconverted.
  1904. * - `((id: string) => boolean|'remove')`: Pass a function that controls
  1905. * individual IDs.
  1906. *
  1907. * @default true
  1908. */
  1909. ignoreTryCatch?:
  1910. | boolean
  1911. | 'remove'
  1912. | ReadonlyArray<string>
  1913. | ((id: string) => boolean | 'remove')
  1914. /**
  1915. * Controls how to render imports from external dependencies. By default,
  1916. * this plugin assumes that all external dependencies are CommonJS. This
  1917. * means they are rendered as default imports to be compatible with e.g.
  1918. * NodeJS where ES modules can only import a default export from a CommonJS
  1919. * dependency.
  1920. *
  1921. * If you set `esmExternals` to `true`, this plugin assumes that all
  1922. * external dependencies are ES modules and respect the
  1923. * `requireReturnsDefault` option. If that option is not set, they will be
  1924. * rendered as namespace imports.
  1925. *
  1926. * You can also supply an array of ids to be treated as ES modules, or a
  1927. * function that will be passed each external id to determine whether it is
  1928. * an ES module.
  1929. * @default false
  1930. */
  1931. esmExternals?: boolean | ReadonlyArray<string> | ((id: string) => boolean)
  1932. /**
  1933. * Controls what is returned when requiring an ES module from a CommonJS file.
  1934. * When using the `esmExternals` option, this will also apply to external
  1935. * modules. By default, this plugin will render those imports as namespace
  1936. * imports i.e.
  1937. *
  1938. * ```js
  1939. * // input
  1940. * const foo = require('foo');
  1941. *
  1942. * // output
  1943. * import * as foo from 'foo';
  1944. * ```
  1945. *
  1946. * However, there are some situations where this may not be desired.
  1947. * For these situations, you can change Rollup's behaviour either globally or
  1948. * per module. To change it globally, set the `requireReturnsDefault` option
  1949. * to one of the following values:
  1950. *
  1951. * - `false`: This is the default, requiring an ES module returns its
  1952. * namespace. This is the only option that will also add a marker
  1953. * `__esModule: true` to the namespace to support interop patterns in
  1954. * CommonJS modules that are transpiled ES modules.
  1955. * - `"namespace"`: Like `false`, requiring an ES module returns its
  1956. * namespace, but the plugin does not add the `__esModule` marker and thus
  1957. * creates more efficient code. For external dependencies when using
  1958. * `esmExternals: true`, no additional interop code is generated.
  1959. * - `"auto"`: This is complementary to how `output.exports: "auto"` works in
  1960. * Rollup: If a module has a default export and no named exports, requiring
  1961. * that module returns the default export. In all other cases, the namespace
  1962. * is returned. For external dependencies when using `esmExternals: true`, a
  1963. * corresponding interop helper is added.
  1964. * - `"preferred"`: If a module has a default export, requiring that module
  1965. * always returns the default export, no matter whether additional named
  1966. * exports exist. This is similar to how previous versions of this plugin
  1967. * worked. Again for external dependencies when using `esmExternals: true`,
  1968. * an interop helper is added.
  1969. * - `true`: This will always try to return the default export on require
  1970. * without checking if it actually exists. This can throw at build time if
  1971. * there is no default export. This is how external dependencies are handled
  1972. * when `esmExternals` is not used. The advantage over the other options is
  1973. * that, like `false`, this does not add an interop helper for external
  1974. * dependencies, keeping the code lean.
  1975. *
  1976. * To change this for individual modules, you can supply a function for
  1977. * `requireReturnsDefault` instead. This function will then be called once for
  1978. * each required ES module or external dependency with the corresponding id
  1979. * and allows you to return different values for different modules.
  1980. * @default false
  1981. */
  1982. requireReturnsDefault?:
  1983. | boolean
  1984. | 'auto'
  1985. | 'preferred'
  1986. | 'namespace'
  1987. | ((id: string) => boolean | 'auto' | 'preferred' | 'namespace')
  1988. /**
  1989. * @default "auto"
  1990. */
  1991. defaultIsModuleExports?: boolean | 'auto' | ((id: string) => boolean | 'auto')
  1992. /**
  1993. * Some modules contain dynamic `require` calls, or require modules that
  1994. * contain circular dependencies, which are not handled well by static
  1995. * imports. Including those modules as `dynamicRequireTargets` will simulate a
  1996. * CommonJS (NodeJS-like) environment for them with support for dynamic
  1997. * dependencies. It also enables `strictRequires` for those modules.
  1998. *
  1999. * Note: In extreme cases, this feature may result in some paths being
  2000. * rendered as absolute in the final bundle. The plugin tries to avoid
  2001. * exposing paths from the local machine, but if you are `dynamicRequirePaths`
  2002. * with paths that are far away from your project's folder, that may require
  2003. * replacing strings like `"/Users/John/Desktop/foo-project/"` -\> `"/"`.
  2004. */
  2005. dynamicRequireTargets?: string | ReadonlyArray<string>
  2006. /**
  2007. * To avoid long paths when using the `dynamicRequireTargets` option, you can use this option to specify a directory
  2008. * that is a common parent for all files that use dynamic require statements. Using a directory higher up such as `/`
  2009. * may lead to unnecessarily long paths in the generated code and may expose directory names on your machine like your
  2010. * home directory name. By default, it uses the current working directory.
  2011. */
  2012. dynamicRequireRoot?: string
  2013. }
  2014. export declare interface RollupDynamicImportVarsOptions {
  2015. /**
  2016. * Files to include in this plugin (default all).
  2017. * @default []
  2018. */
  2019. include?: string | RegExp | (string | RegExp)[]
  2020. /**
  2021. * Files to exclude in this plugin (default none).
  2022. * @default []
  2023. */
  2024. exclude?: string | RegExp | (string | RegExp)[]
  2025. /**
  2026. * 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.
  2027. * @default false
  2028. */
  2029. warnOnError?: boolean
  2030. }
  2031. export { rollupVersion }
  2032. /**
  2033. * Search up for the nearest workspace root
  2034. */
  2035. export declare function searchForWorkspaceRoot(current: string, root?: string): string;
  2036. export declare function send(req: IncomingMessage, res: ServerResponse, content: string | Buffer, type: string, options: SendOptions): void;
  2037. export declare interface SendOptions {
  2038. etag?: string;
  2039. cacheControl?: string;
  2040. headers?: OutgoingHttpHeaders;
  2041. map?: SourceMap | null;
  2042. }
  2043. export declare type ServerHook = (this: void, server: ViteDevServer) => (() => void) | void | Promise<(() => void) | void>;
  2044. export declare interface ServerOptions extends CommonServerOptions {
  2045. /**
  2046. * Configure HMR-specific options (port, host, path & protocol)
  2047. */
  2048. hmr?: HmrOptions | boolean;
  2049. /**
  2050. * chokidar watch options
  2051. * https://github.com/paulmillr/chokidar#api
  2052. */
  2053. watch?: WatchOptions;
  2054. /**
  2055. * Create Vite dev server to be used as a middleware in an existing server
  2056. * @default false
  2057. */
  2058. middlewareMode?: boolean | 'html' | 'ssr';
  2059. /**
  2060. * Options for files served via '/\@fs/'.
  2061. */
  2062. fs?: FileSystemServeOptions;
  2063. /**
  2064. * Origin for the generated asset URLs.
  2065. *
  2066. * @example `http://127.0.0.1:8080`
  2067. */
  2068. origin?: string;
  2069. /**
  2070. * Pre-transform known direct imports
  2071. * @default true
  2072. */
  2073. preTransformRequests?: boolean;
  2074. /**
  2075. * Whether or not to ignore-list source files in the dev server sourcemap, used to populate
  2076. * the [`x_google_ignoreList` source map extension](https://developer.chrome.com/blog/devtools-better-angular-debugging/#the-x_google_ignorelist-source-map-extension).
  2077. *
  2078. * By default, it excludes all paths containing `node_modules`. You can pass `false` to
  2079. * disable this behavior, or, for full control, a function that takes the source path and
  2080. * sourcemap path and returns whether to ignore the source path.
  2081. */
  2082. sourcemapIgnoreList?: false | ((sourcePath: string, sourcemapPath: string) => boolean);
  2083. /**
  2084. * Force dep pre-optimization regardless of whether deps have changed.
  2085. *
  2086. * @deprecated Use optimizeDeps.force instead, this option may be removed
  2087. * in a future minor version without following semver
  2088. */
  2089. force?: boolean;
  2090. }
  2091. export declare function sortUserPlugins(plugins: (Plugin_2 | Plugin_2[])[] | undefined): [Plugin_2[], Plugin_2[], Plugin_2[]];
  2092. export declare function splitVendorChunk(options?: {
  2093. cache?: SplitVendorChunkCache;
  2094. }): GetManualChunk;
  2095. export declare class SplitVendorChunkCache {
  2096. cache: Map<string, boolean>;
  2097. constructor();
  2098. reset(): void;
  2099. }
  2100. export declare function splitVendorChunkPlugin(): Plugin_2;
  2101. export declare type SsrDepOptimizationOptions = DepOptimizationConfig;
  2102. export declare type SSRFormat = 'esm' | 'cjs';
  2103. export declare interface SSROptions {
  2104. noExternal?: string | RegExp | (string | RegExp)[] | true;
  2105. external?: string[];
  2106. /**
  2107. * Define the target for the ssr build. The browser field in package.json
  2108. * is ignored for node but used if webworker is the target
  2109. * @default 'node'
  2110. */
  2111. target?: SSRTarget;
  2112. /**
  2113. * Define the format for the ssr build. Since Vite v3 the SSR build generates ESM by default.
  2114. * `'cjs'` can be selected to generate a CJS build, but it isn't recommended. This option is
  2115. * left marked as experimental to give users more time to update to ESM. CJS builds requires
  2116. * complex externalization heuristics that aren't present in the ESM format.
  2117. * @experimental
  2118. * @deprecated
  2119. * @default 'esm'
  2120. */
  2121. format?: SSRFormat;
  2122. /**
  2123. * Control over which dependencies are optimized during SSR and esbuild options
  2124. * During build:
  2125. * no external CJS dependencies are optimized by default
  2126. * During dev:
  2127. * explicit no external CJS dependencies are optimized by default
  2128. * @experimental
  2129. */
  2130. optimizeDeps?: SsrDepOptimizationOptions;
  2131. resolve?: {
  2132. /**
  2133. * Conditions that are used in the plugin pipeline. The default value is the root config's `resolve.conditions`.
  2134. *
  2135. * Use this to override the default ssr conditions for the ssr build.
  2136. *
  2137. * @default rootConfig.resolve.conditions
  2138. */
  2139. conditions?: string[];
  2140. /**
  2141. * Conditions that are used during ssr import (including `ssrLoadModule`) of externalized dependencies.
  2142. *
  2143. * @default []
  2144. */
  2145. externalConditions?: string[];
  2146. };
  2147. }
  2148. export declare type SSRTarget = 'node' | 'webworker';
  2149. declare interface Targets {
  2150. android?: number,
  2151. chrome?: number,
  2152. edge?: number,
  2153. firefox?: number,
  2154. ie?: number,
  2155. ios_saf?: number,
  2156. opera?: number,
  2157. safari?: number,
  2158. samsung?: number
  2159. }
  2160. export declare namespace Terser {
  2161. export type ECMA = 5 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020
  2162. export interface ParseOptions {
  2163. bare_returns?: boolean
  2164. /** @deprecated legacy option. Currently, all supported EcmaScript is valid to parse. */
  2165. ecma?: ECMA
  2166. html5_comments?: boolean
  2167. shebang?: boolean
  2168. }
  2169. export interface CompressOptions {
  2170. arguments?: boolean
  2171. arrows?: boolean
  2172. booleans_as_integers?: boolean
  2173. booleans?: boolean
  2174. collapse_vars?: boolean
  2175. comparisons?: boolean
  2176. computed_props?: boolean
  2177. conditionals?: boolean
  2178. dead_code?: boolean
  2179. defaults?: boolean
  2180. directives?: boolean
  2181. drop_console?: boolean
  2182. drop_debugger?: boolean
  2183. ecma?: ECMA
  2184. evaluate?: boolean
  2185. expression?: boolean
  2186. global_defs?: object
  2187. hoist_funs?: boolean
  2188. hoist_props?: boolean
  2189. hoist_vars?: boolean
  2190. ie8?: boolean
  2191. if_return?: boolean
  2192. inline?: boolean | InlineFunctions
  2193. join_vars?: boolean
  2194. keep_classnames?: boolean | RegExp
  2195. keep_fargs?: boolean
  2196. keep_fnames?: boolean | RegExp
  2197. keep_infinity?: boolean
  2198. loops?: boolean
  2199. module?: boolean
  2200. negate_iife?: boolean
  2201. passes?: number
  2202. properties?: boolean
  2203. pure_funcs?: string[]
  2204. pure_getters?: boolean | 'strict'
  2205. reduce_funcs?: boolean
  2206. reduce_vars?: boolean
  2207. sequences?: boolean | number
  2208. side_effects?: boolean
  2209. switches?: boolean
  2210. toplevel?: boolean
  2211. top_retain?: null | string | string[] | RegExp
  2212. typeofs?: boolean
  2213. unsafe_arrows?: boolean
  2214. unsafe?: boolean
  2215. unsafe_comps?: boolean
  2216. unsafe_Function?: boolean
  2217. unsafe_math?: boolean
  2218. unsafe_symbols?: boolean
  2219. unsafe_methods?: boolean
  2220. unsafe_proto?: boolean
  2221. unsafe_regexp?: boolean
  2222. unsafe_undefined?: boolean
  2223. unused?: boolean
  2224. }
  2225. export enum InlineFunctions {
  2226. Disabled = 0,
  2227. SimpleFunctions = 1,
  2228. WithArguments = 2,
  2229. WithArgumentsAndVariables = 3,
  2230. }
  2231. export interface MangleOptions {
  2232. eval?: boolean
  2233. keep_classnames?: boolean | RegExp
  2234. keep_fnames?: boolean | RegExp
  2235. module?: boolean
  2236. nth_identifier?: SimpleIdentifierMangler | WeightedIdentifierMangler
  2237. properties?: boolean | ManglePropertiesOptions
  2238. reserved?: string[]
  2239. safari10?: boolean
  2240. toplevel?: boolean
  2241. }
  2242. /**
  2243. * An identifier mangler for which the output is invariant with respect to the source code.
  2244. */
  2245. export interface SimpleIdentifierMangler {
  2246. /**
  2247. * Obtains the nth most favored (usually shortest) identifier to rename a variable to.
  2248. * The mangler will increment n and retry until the return value is not in use in scope, and is not a reserved word.
  2249. * This function is expected to be stable; Evaluating get(n) === get(n) should always return true.
  2250. * @param n - The ordinal of the identifier.
  2251. */
  2252. get(n: number): string
  2253. }
  2254. /**
  2255. * An identifier mangler that leverages character frequency analysis to determine identifier precedence.
  2256. */
  2257. export interface WeightedIdentifierMangler extends SimpleIdentifierMangler {
  2258. /**
  2259. * Modifies the internal weighting of the input characters by the specified delta.
  2260. * Will be invoked on the entire printed AST, and then deduct mangleable identifiers.
  2261. * @param chars - The characters to modify the weighting of.
  2262. * @param delta - The numeric weight to add to the characters.
  2263. */
  2264. consider(chars: string, delta: number): number
  2265. /**
  2266. * Resets character weights.
  2267. */
  2268. reset(): void
  2269. /**
  2270. * Sorts identifiers by character frequency, in preparation for calls to get(n).
  2271. */
  2272. sort(): void
  2273. }
  2274. export interface ManglePropertiesOptions {
  2275. builtins?: boolean
  2276. debug?: boolean
  2277. keep_quoted?: boolean | 'strict'
  2278. nth_identifier?: SimpleIdentifierMangler | WeightedIdentifierMangler
  2279. regex?: RegExp | string
  2280. reserved?: string[]
  2281. }
  2282. export interface FormatOptions {
  2283. ascii_only?: boolean
  2284. /** @deprecated Not implemented anymore */
  2285. beautify?: boolean
  2286. braces?: boolean
  2287. comments?:
  2288. | boolean
  2289. | 'all'
  2290. | 'some'
  2291. | RegExp
  2292. | ((
  2293. node: any,
  2294. comment: {
  2295. value: string
  2296. type: 'comment1' | 'comment2' | 'comment3' | 'comment4'
  2297. pos: number
  2298. line: number
  2299. col: number
  2300. },
  2301. ) => boolean)
  2302. ecma?: ECMA
  2303. ie8?: boolean
  2304. keep_numbers?: boolean
  2305. indent_level?: number
  2306. indent_start?: number
  2307. inline_script?: boolean
  2308. keep_quoted_props?: boolean
  2309. max_line_len?: number | false
  2310. preamble?: string
  2311. preserve_annotations?: boolean
  2312. quote_keys?: boolean
  2313. quote_style?: OutputQuoteStyle
  2314. safari10?: boolean
  2315. semicolons?: boolean
  2316. shebang?: boolean
  2317. shorthand?: boolean
  2318. source_map?: SourceMapOptions
  2319. webkit?: boolean
  2320. width?: number
  2321. wrap_iife?: boolean
  2322. wrap_func_args?: boolean
  2323. }
  2324. export enum OutputQuoteStyle {
  2325. PreferDouble = 0,
  2326. AlwaysSingle = 1,
  2327. AlwaysDouble = 2,
  2328. AlwaysOriginal = 3,
  2329. }
  2330. export interface MinifyOptions {
  2331. compress?: boolean | CompressOptions
  2332. ecma?: ECMA
  2333. enclose?: boolean | string
  2334. ie8?: boolean
  2335. keep_classnames?: boolean | RegExp
  2336. keep_fnames?: boolean | RegExp
  2337. mangle?: boolean | MangleOptions
  2338. module?: boolean
  2339. nameCache?: object
  2340. format?: FormatOptions
  2341. /** @deprecated deprecated */
  2342. output?: FormatOptions
  2343. parse?: ParseOptions
  2344. safari10?: boolean
  2345. sourceMap?: boolean | SourceMapOptions
  2346. toplevel?: boolean
  2347. }
  2348. export interface MinifyOutput {
  2349. code?: string
  2350. map?: object | string
  2351. decoded_map?: object | null
  2352. }
  2353. export interface SourceMapOptions {
  2354. /** Source map object, 'inline' or source map file content */
  2355. content?: object | string
  2356. includeSources?: boolean
  2357. filename?: string
  2358. root?: string
  2359. url?: string | 'inline'
  2360. }
  2361. }
  2362. export declare interface TransformOptions {
  2363. ssr?: boolean;
  2364. html?: boolean;
  2365. /* Excluded from this release type: allowId */
  2366. }
  2367. export declare interface TransformResult {
  2368. code: string;
  2369. map: SourceMap | null;
  2370. etag?: string;
  2371. deps?: string[];
  2372. dynamicDeps?: string[];
  2373. }
  2374. export declare function transformWithEsbuild(code: string, filename: string, options?: EsbuildTransformOptions, inMap?: object): Promise<ESBuildTransformResult>;
  2375. export { Update }
  2376. export { UpdatePayload }
  2377. export declare interface UserConfig {
  2378. /**
  2379. * Project root directory. Can be an absolute path, or a path relative from
  2380. * the location of the config file itself.
  2381. * @default process.cwd()
  2382. */
  2383. root?: string;
  2384. /**
  2385. * Base public path when served in development or production.
  2386. * @default '/'
  2387. */
  2388. base?: string;
  2389. /**
  2390. * Directory to serve as plain static assets. Files in this directory are
  2391. * served and copied to build dist dir as-is without transform. The value
  2392. * can be either an absolute file system path or a path relative to project root.
  2393. *
  2394. * Set to `false` or an empty string to disable copied static assets to build dist dir.
  2395. * @default 'public'
  2396. */
  2397. publicDir?: string | false;
  2398. /**
  2399. * Directory to save cache files. Files in this directory are pre-bundled
  2400. * deps or some other cache files that generated by vite, which can improve
  2401. * the performance. You can use `--force` flag or manually delete the directory
  2402. * to regenerate the cache files. The value can be either an absolute file
  2403. * system path or a path relative to project root.
  2404. * Default to `.vite` when no `package.json` is detected.
  2405. * @default 'node_modules/.vite'
  2406. */
  2407. cacheDir?: string;
  2408. /**
  2409. * Explicitly set a mode to run in. This will override the default mode for
  2410. * each command, and can be overridden by the command line --mode option.
  2411. */
  2412. mode?: string;
  2413. /**
  2414. * Define global variable replacements.
  2415. * Entries will be defined on `window` during dev and replaced during build.
  2416. */
  2417. define?: Record<string, any>;
  2418. /**
  2419. * Array of vite plugins to use.
  2420. */
  2421. plugins?: PluginOption[];
  2422. /**
  2423. * Configure resolver
  2424. */
  2425. resolve?: ResolveOptions & {
  2426. alias?: AliasOptions;
  2427. };
  2428. /**
  2429. * CSS related options (preprocessors and CSS modules)
  2430. */
  2431. css?: CSSOptions;
  2432. /**
  2433. * JSON loading options
  2434. */
  2435. json?: JsonOptions;
  2436. /**
  2437. * Transform options to pass to esbuild.
  2438. * Or set to `false` to disable esbuild.
  2439. */
  2440. esbuild?: ESBuildOptions | false;
  2441. /**
  2442. * Specify additional picomatch patterns to be treated as static assets.
  2443. */
  2444. assetsInclude?: string | RegExp | (string | RegExp)[];
  2445. /**
  2446. * Server specific options, e.g. host, port, https...
  2447. */
  2448. server?: ServerOptions;
  2449. /**
  2450. * Build specific options
  2451. */
  2452. build?: BuildOptions;
  2453. /**
  2454. * Preview specific options, e.g. host, port, https...
  2455. */
  2456. preview?: PreviewOptions;
  2457. /**
  2458. * Dep optimization options
  2459. */
  2460. optimizeDeps?: DepOptimizationOptions;
  2461. /**
  2462. * SSR specific options
  2463. */
  2464. ssr?: SSROptions;
  2465. /**
  2466. * Experimental features
  2467. *
  2468. * Features under this field could change in the future and might NOT follow semver.
  2469. * Please be careful and always pin Vite's version when using them.
  2470. * @experimental
  2471. */
  2472. experimental?: ExperimentalOptions;
  2473. /**
  2474. * Legacy options
  2475. *
  2476. * Features under this field only follow semver for patches, they could be removed in a
  2477. * future minor version. Please always pin Vite's version to a minor when using them.
  2478. */
  2479. legacy?: LegacyOptions;
  2480. /**
  2481. * Log level.
  2482. * @default 'info'
  2483. */
  2484. logLevel?: LogLevel;
  2485. /**
  2486. * Custom logger.
  2487. */
  2488. customLogger?: Logger;
  2489. /**
  2490. * @default true
  2491. */
  2492. clearScreen?: boolean;
  2493. /**
  2494. * Environment files directory. Can be an absolute path, or a path relative from
  2495. * root.
  2496. * @default root
  2497. */
  2498. envDir?: string;
  2499. /**
  2500. * Env variables starts with `envPrefix` will be exposed to your client source code via import.meta.env.
  2501. * @default 'VITE_'
  2502. */
  2503. envPrefix?: string | string[];
  2504. /**
  2505. * Worker bundle options
  2506. */
  2507. worker?: {
  2508. /**
  2509. * Output format for worker bundle
  2510. * @default 'iife'
  2511. */
  2512. format?: 'es' | 'iife';
  2513. /**
  2514. * Vite plugins that apply to worker bundle
  2515. */
  2516. plugins?: PluginOption[];
  2517. /**
  2518. * Rollup options to build worker bundle
  2519. */
  2520. rollupOptions?: Omit<RollupOptions, 'plugins' | 'input' | 'onwarn' | 'preserveEntrySignatures'>;
  2521. };
  2522. /**
  2523. * Whether your application is a Single Page Application (SPA),
  2524. * a Multi-Page Application (MPA), or Custom Application (SSR
  2525. * and frameworks with custom HTML handling)
  2526. * @default 'spa'
  2527. */
  2528. appType?: AppType;
  2529. }
  2530. export declare type UserConfigExport = UserConfig | Promise<UserConfig> | UserConfigFnObject | UserConfigFnPromise | UserConfigFn;
  2531. export declare type UserConfigFn = (env: ConfigEnv) => UserConfig | Promise<UserConfig>;
  2532. export declare type UserConfigFnObject = (env: ConfigEnv) => UserConfig;
  2533. export declare type UserConfigFnPromise = (env: ConfigEnv) => Promise<UserConfig>;
  2534. export declare const version: string;
  2535. export declare interface ViteDevServer {
  2536. /**
  2537. * The resolved vite config object
  2538. */
  2539. config: ResolvedConfig;
  2540. /**
  2541. * A connect app instance.
  2542. * - Can be used to attach custom middlewares to the dev server.
  2543. * - Can also be used as the handler function of a custom http server
  2544. * or as a middleware in any connect-style Node.js frameworks
  2545. *
  2546. * https://github.com/senchalabs/connect#use-middleware
  2547. */
  2548. middlewares: Connect.Server;
  2549. /**
  2550. * native Node http server instance
  2551. * will be null in middleware mode
  2552. */
  2553. httpServer: http.Server | null;
  2554. /**
  2555. * chokidar watcher instance
  2556. * https://github.com/paulmillr/chokidar#api
  2557. */
  2558. watcher: FSWatcher;
  2559. /**
  2560. * web socket server with `send(payload)` method
  2561. */
  2562. ws: WebSocketServer;
  2563. /**
  2564. * Rollup plugin container that can run plugin hooks on a given file
  2565. */
  2566. pluginContainer: PluginContainer;
  2567. /**
  2568. * Module graph that tracks the import relationships, url to file mapping
  2569. * and hmr state.
  2570. */
  2571. moduleGraph: ModuleGraph;
  2572. /**
  2573. * The resolved urls Vite prints on the CLI. null in middleware mode or
  2574. * before `server.listen` is called.
  2575. */
  2576. resolvedUrls: ResolvedServerUrls | null;
  2577. /**
  2578. * Programmatically resolve, load and transform a URL and get the result
  2579. * without going through the http request pipeline.
  2580. */
  2581. transformRequest(url: string, options?: TransformOptions): Promise<TransformResult | null>;
  2582. /**
  2583. * Apply vite built-in HTML transforms and any plugin HTML transforms.
  2584. */
  2585. transformIndexHtml(url: string, html: string, originalUrl?: string): Promise<string>;
  2586. /**
  2587. * Transform module code into SSR format.
  2588. */
  2589. ssrTransform(code: string, inMap: SourceMap | null, url: string, originalCode?: string): Promise<TransformResult | null>;
  2590. /**
  2591. * Load a given URL as an instantiated module for SSR.
  2592. */
  2593. ssrLoadModule(url: string, opts?: {
  2594. fixStacktrace?: boolean;
  2595. }): Promise<Record<string, any>>;
  2596. /**
  2597. * Returns a fixed version of the given stack
  2598. */
  2599. ssrRewriteStacktrace(stack: string): string;
  2600. /**
  2601. * Mutates the given SSR error by rewriting the stacktrace
  2602. */
  2603. ssrFixStacktrace(e: Error): void;
  2604. /**
  2605. * Triggers HMR for a module in the module graph. You can use the `server.moduleGraph`
  2606. * API to retrieve the module to be reloaded. If `hmr` is false, this is a no-op.
  2607. */
  2608. reloadModule(module: ModuleNode): Promise<void>;
  2609. /**
  2610. * Start the server.
  2611. */
  2612. listen(port?: number, isRestart?: boolean): Promise<ViteDevServer>;
  2613. /**
  2614. * Stop the server.
  2615. */
  2616. close(): Promise<void>;
  2617. /**
  2618. * Print server urls
  2619. */
  2620. printUrls(): void;
  2621. /**
  2622. * Restart the server.
  2623. *
  2624. * @param forceOptimize - force the optimizer to re-bundle, same as --force cli flag
  2625. */
  2626. restart(forceOptimize?: boolean): Promise<void>;
  2627. /**
  2628. * Open browser
  2629. */
  2630. openBrowser(): void;
  2631. /* Excluded from this release type: _importGlobMap */
  2632. /* Excluded from this release type: _ssrExternals */
  2633. /* Excluded from this release type: _restartPromise */
  2634. /* Excluded from this release type: _forceOptimizeOnRestart */
  2635. /* Excluded from this release type: _pendingRequests */
  2636. /* Excluded from this release type: _fsDenyGlob */
  2637. /* Excluded from this release type: _shortcutsOptions */
  2638. }
  2639. export declare interface WatchOptions {
  2640. /**
  2641. * Indicates whether the process should continue to run as long as files are being watched. If
  2642. * set to `false` when using `fsevents` to watch, no more events will be emitted after `ready`,
  2643. * even if the process continues to run.
  2644. */
  2645. persistent?: boolean
  2646. /**
  2647. * ([anymatch](https://github.com/micromatch/anymatch)-compatible definition) Defines files/paths to
  2648. * be ignored. The whole relative or absolute path is tested, not just filename. If a function
  2649. * with two arguments is provided, it gets called twice per path - once with a single argument
  2650. * (the path), second time with two arguments (the path and the
  2651. * [`fs.Stats`](https://nodejs.org/api/fs.html#fs_class_fs_stats) object of that path).
  2652. */
  2653. ignored?: Matcher
  2654. /**
  2655. * If set to `false` then `add`/`addDir` events are also emitted for matching paths while
  2656. * instantiating the watching as chokidar discovers these file paths (before the `ready` event).
  2657. */
  2658. ignoreInitial?: boolean
  2659. /**
  2660. * When `false`, only the symlinks themselves will be watched for changes instead of following
  2661. * the link references and bubbling events through the link's path.
  2662. */
  2663. followSymlinks?: boolean
  2664. /**
  2665. * The base directory from which watch `paths` are to be derived. Paths emitted with events will
  2666. * be relative to this.
  2667. */
  2668. cwd?: string
  2669. /**
  2670. * If set to true then the strings passed to .watch() and .add() are treated as literal path
  2671. * names, even if they look like globs.
  2672. *
  2673. * @default false
  2674. */
  2675. disableGlobbing?: boolean
  2676. /**
  2677. * Whether to use fs.watchFile (backed by polling), or fs.watch. If polling leads to high CPU
  2678. * utilization, consider setting this to `false`. It is typically necessary to **set this to
  2679. * `true` to successfully watch files over a network**, and it may be necessary to successfully
  2680. * watch files in other non-standard situations. Setting to `true` explicitly on OS X overrides
  2681. * the `useFsEvents` default.
  2682. */
  2683. usePolling?: boolean
  2684. /**
  2685. * Whether to use the `fsevents` watching interface if available. When set to `true` explicitly
  2686. * and `fsevents` is available this supersedes the `usePolling` setting. When set to `false` on
  2687. * OS X, `usePolling: true` becomes the default.
  2688. */
  2689. useFsEvents?: boolean
  2690. /**
  2691. * If relying upon the [`fs.Stats`](https://nodejs.org/api/fs.html#fs_class_fs_stats) object that
  2692. * may get passed with `add`, `addDir`, and `change` events, set this to `true` to ensure it is
  2693. * provided even in cases where it wasn't already available from the underlying watch events.
  2694. */
  2695. alwaysStat?: boolean
  2696. /**
  2697. * If set, limits how many levels of subdirectories will be traversed.
  2698. */
  2699. depth?: number
  2700. /**
  2701. * Interval of file system polling.
  2702. */
  2703. interval?: number
  2704. /**
  2705. * Interval of file system polling for binary files. ([see list of binary extensions](https://gi
  2706. * thub.com/sindresorhus/binary-extensions/blob/master/binary-extensions.json))
  2707. */
  2708. binaryInterval?: number
  2709. /**
  2710. * Indicates whether to watch files that don't have read permissions if possible. If watching
  2711. * fails due to `EPERM` or `EACCES` with this set to `true`, the errors will be suppressed
  2712. * silently.
  2713. */
  2714. ignorePermissionErrors?: boolean
  2715. /**
  2716. * `true` if `useFsEvents` and `usePolling` are `false`. Automatically filters out artifacts
  2717. * that occur when using editors that use "atomic writes" instead of writing directly to the
  2718. * source file. If a file is re-added within 100 ms of being deleted, Chokidar emits a `change`
  2719. * event rather than `unlink` then `add`. If the default of 100 ms does not work well for you,
  2720. * you can override it by setting `atomic` to a custom value, in milliseconds.
  2721. */
  2722. atomic?: boolean | number
  2723. /**
  2724. * can be set to an object in order to adjust timing params:
  2725. */
  2726. awaitWriteFinish?: AwaitWriteFinishOptions | boolean
  2727. }
  2728. declare class WebSocket_2 extends EventEmitter {
  2729. /** The connection is not yet open. */
  2730. static readonly CONNECTING: 0
  2731. /** The connection is open and ready to communicate. */
  2732. static readonly OPEN: 1
  2733. /** The connection is in the process of closing. */
  2734. static readonly CLOSING: 2
  2735. /** The connection is closed. */
  2736. static readonly CLOSED: 3
  2737. binaryType: 'nodebuffer' | 'arraybuffer' | 'fragments'
  2738. readonly bufferedAmount: number
  2739. readonly extensions: string
  2740. /** Indicates whether the websocket is paused */
  2741. readonly isPaused: boolean
  2742. readonly protocol: string
  2743. /** The current state of the connection */
  2744. readonly readyState:
  2745. | typeof WebSocket_2.CONNECTING
  2746. | typeof WebSocket_2.OPEN
  2747. | typeof WebSocket_2.CLOSING
  2748. | typeof WebSocket_2.CLOSED
  2749. readonly url: string
  2750. /** The connection is not yet open. */
  2751. readonly CONNECTING: 0
  2752. /** The connection is open and ready to communicate. */
  2753. readonly OPEN: 1
  2754. /** The connection is in the process of closing. */
  2755. readonly CLOSING: 2
  2756. /** The connection is closed. */
  2757. readonly CLOSED: 3
  2758. onopen: ((event: WebSocket_2.Event) => void) | null
  2759. onerror: ((event: WebSocket_2.ErrorEvent) => void) | null
  2760. onclose: ((event: WebSocket_2.CloseEvent) => void) | null
  2761. onmessage: ((event: WebSocket_2.MessageEvent) => void) | null
  2762. constructor(address: null)
  2763. constructor(
  2764. address: string | URL_2,
  2765. options?: WebSocket_2.ClientOptions | ClientRequestArgs,
  2766. )
  2767. constructor(
  2768. address: string | URL_2,
  2769. protocols?: string | string[],
  2770. options?: WebSocket_2.ClientOptions | ClientRequestArgs,
  2771. )
  2772. close(code?: number, data?: string | Buffer): void
  2773. ping(data?: any, mask?: boolean, cb?: (err: Error) => void): void
  2774. pong(data?: any, mask?: boolean, cb?: (err: Error) => void): void
  2775. send(data: any, cb?: (err?: Error) => void): void
  2776. send(
  2777. data: any,
  2778. options: {
  2779. mask?: boolean | undefined
  2780. binary?: boolean | undefined
  2781. compress?: boolean | undefined
  2782. fin?: boolean | undefined
  2783. },
  2784. cb?: (err?: Error) => void,
  2785. ): void
  2786. terminate(): void
  2787. /**
  2788. * Pause the websocket causing it to stop emitting events. Some events can still be
  2789. * emitted after this is called, until all buffered data is consumed. This method
  2790. * is a noop if the ready state is `CONNECTING` or `CLOSED`.
  2791. */
  2792. pause(): void
  2793. /**
  2794. * Make a paused socket resume emitting events. This method is a noop if the ready
  2795. * state is `CONNECTING` or `CLOSED`.
  2796. */
  2797. resume(): void
  2798. // HTML5 WebSocket events
  2799. addEventListener(
  2800. method: 'message',
  2801. cb: (event: WebSocket_2.MessageEvent) => void,
  2802. options?: WebSocket_2.EventListenerOptions,
  2803. ): void
  2804. addEventListener(
  2805. method: 'close',
  2806. cb: (event: WebSocket_2.CloseEvent) => void,
  2807. options?: WebSocket_2.EventListenerOptions,
  2808. ): void
  2809. addEventListener(
  2810. method: 'error',
  2811. cb: (event: WebSocket_2.ErrorEvent) => void,
  2812. options?: WebSocket_2.EventListenerOptions,
  2813. ): void
  2814. addEventListener(
  2815. method: 'open',
  2816. cb: (event: WebSocket_2.Event) => void,
  2817. options?: WebSocket_2.EventListenerOptions,
  2818. ): void
  2819. removeEventListener(
  2820. method: 'message',
  2821. cb: (event: WebSocket_2.MessageEvent) => void,
  2822. ): void
  2823. removeEventListener(
  2824. method: 'close',
  2825. cb: (event: WebSocket_2.CloseEvent) => void,
  2826. ): void
  2827. removeEventListener(
  2828. method: 'error',
  2829. cb: (event: WebSocket_2.ErrorEvent) => void,
  2830. ): void
  2831. removeEventListener(
  2832. method: 'open',
  2833. cb: (event: WebSocket_2.Event) => void,
  2834. ): void
  2835. // Events
  2836. on(
  2837. event: 'close',
  2838. listener: (this: WebSocket_2, code: number, reason: Buffer) => void,
  2839. ): this
  2840. on(event: 'error', listener: (this: WebSocket_2, err: Error) => void): this
  2841. on(
  2842. event: 'upgrade',
  2843. listener: (this: WebSocket_2, request: IncomingMessage) => void,
  2844. ): this
  2845. on(
  2846. event: 'message',
  2847. listener: (
  2848. this: WebSocket_2,
  2849. data: WebSocket_2.RawData,
  2850. isBinary: boolean,
  2851. ) => void,
  2852. ): this
  2853. on(event: 'open', listener: (this: WebSocket_2) => void): this
  2854. on(
  2855. event: 'ping' | 'pong',
  2856. listener: (this: WebSocket_2, data: Buffer) => void,
  2857. ): this
  2858. on(
  2859. event: 'unexpected-response',
  2860. listener: (
  2861. this: WebSocket_2,
  2862. request: ClientRequest,
  2863. response: IncomingMessage,
  2864. ) => void,
  2865. ): this
  2866. on(
  2867. event: string | symbol,
  2868. listener: (this: WebSocket_2, ...args: any[]) => void,
  2869. ): this
  2870. once(
  2871. event: 'close',
  2872. listener: (this: WebSocket_2, code: number, reason: Buffer) => void,
  2873. ): this
  2874. once(event: 'error', listener: (this: WebSocket_2, err: Error) => void): this
  2875. once(
  2876. event: 'upgrade',
  2877. listener: (this: WebSocket_2, request: IncomingMessage) => void,
  2878. ): this
  2879. once(
  2880. event: 'message',
  2881. listener: (
  2882. this: WebSocket_2,
  2883. data: WebSocket_2.RawData,
  2884. isBinary: boolean,
  2885. ) => void,
  2886. ): this
  2887. once(event: 'open', listener: (this: WebSocket_2) => void): this
  2888. once(
  2889. event: 'ping' | 'pong',
  2890. listener: (this: WebSocket_2, data: Buffer) => void,
  2891. ): this
  2892. once(
  2893. event: 'unexpected-response',
  2894. listener: (
  2895. this: WebSocket_2,
  2896. request: ClientRequest,
  2897. response: IncomingMessage,
  2898. ) => void,
  2899. ): this
  2900. once(
  2901. event: string | symbol,
  2902. listener: (this: WebSocket_2, ...args: any[]) => void,
  2903. ): this
  2904. off(
  2905. event: 'close',
  2906. listener: (this: WebSocket_2, code: number, reason: Buffer) => void,
  2907. ): this
  2908. off(event: 'error', listener: (this: WebSocket_2, err: Error) => void): this
  2909. off(
  2910. event: 'upgrade',
  2911. listener: (this: WebSocket_2, request: IncomingMessage) => void,
  2912. ): this
  2913. off(
  2914. event: 'message',
  2915. listener: (
  2916. this: WebSocket_2,
  2917. data: WebSocket_2.RawData,
  2918. isBinary: boolean,
  2919. ) => void,
  2920. ): this
  2921. off(event: 'open', listener: (this: WebSocket_2) => void): this
  2922. off(
  2923. event: 'ping' | 'pong',
  2924. listener: (this: WebSocket_2, data: Buffer) => void,
  2925. ): this
  2926. off(
  2927. event: 'unexpected-response',
  2928. listener: (
  2929. this: WebSocket_2,
  2930. request: ClientRequest,
  2931. response: IncomingMessage,
  2932. ) => void,
  2933. ): this
  2934. off(
  2935. event: string | symbol,
  2936. listener: (this: WebSocket_2, ...args: any[]) => void,
  2937. ): this
  2938. addListener(
  2939. event: 'close',
  2940. listener: (code: number, reason: Buffer) => void,
  2941. ): this
  2942. addListener(event: 'error', listener: (err: Error) => void): this
  2943. addListener(
  2944. event: 'upgrade',
  2945. listener: (request: IncomingMessage) => void,
  2946. ): this
  2947. addListener(
  2948. event: 'message',
  2949. listener: (data: WebSocket_2.RawData, isBinary: boolean) => void,
  2950. ): this
  2951. addListener(event: 'open', listener: () => void): this
  2952. addListener(event: 'ping' | 'pong', listener: (data: Buffer) => void): this
  2953. addListener(
  2954. event: 'unexpected-response',
  2955. listener: (request: ClientRequest, response: IncomingMessage) => void,
  2956. ): this
  2957. addListener(event: string | symbol, listener: (...args: any[]) => void): this
  2958. removeListener(
  2959. event: 'close',
  2960. listener: (code: number, reason: Buffer) => void,
  2961. ): this
  2962. removeListener(event: 'error', listener: (err: Error) => void): this
  2963. removeListener(
  2964. event: 'upgrade',
  2965. listener: (request: IncomingMessage) => void,
  2966. ): this
  2967. removeListener(
  2968. event: 'message',
  2969. listener: (data: WebSocket_2.RawData, isBinary: boolean) => void,
  2970. ): this
  2971. removeListener(event: 'open', listener: () => void): this
  2972. removeListener(event: 'ping' | 'pong', listener: (data: Buffer) => void): this
  2973. removeListener(
  2974. event: 'unexpected-response',
  2975. listener: (request: ClientRequest, response: IncomingMessage) => void,
  2976. ): this
  2977. removeListener(
  2978. event: string | symbol,
  2979. listener: (...args: any[]) => void,
  2980. ): this
  2981. }
  2982. declare namespace WebSocket_2 {
  2983. /**
  2984. * Data represents the raw message payload received over the WebSocket.
  2985. */
  2986. type RawData = Buffer | ArrayBuffer | Buffer[]
  2987. /**
  2988. * Data represents the message payload received over the WebSocket.
  2989. */
  2990. type Data = string | Buffer | ArrayBuffer | Buffer[]
  2991. /**
  2992. * CertMeta represents the accepted types for certificate & key data.
  2993. */
  2994. type CertMeta = string | string[] | Buffer | Buffer[]
  2995. /**
  2996. * VerifyClientCallbackSync is a synchronous callback used to inspect the
  2997. * incoming message. The return value (boolean) of the function determines
  2998. * whether or not to accept the handshake.
  2999. */
  3000. type VerifyClientCallbackSync = (info: {
  3001. origin: string
  3002. secure: boolean
  3003. req: IncomingMessage
  3004. }) => boolean
  3005. /**
  3006. * VerifyClientCallbackAsync is an asynchronous callback used to inspect the
  3007. * incoming message. The return value (boolean) of the function determines
  3008. * whether or not to accept the handshake.
  3009. */
  3010. type VerifyClientCallbackAsync = (
  3011. info: { origin: string; secure: boolean; req: IncomingMessage },
  3012. callback: (
  3013. res: boolean,
  3014. code?: number,
  3015. message?: string,
  3016. headers?: OutgoingHttpHeaders,
  3017. ) => void,
  3018. ) => void
  3019. interface ClientOptions extends SecureContextOptions {
  3020. protocol?: string | undefined
  3021. followRedirects?: boolean | undefined
  3022. generateMask?(mask: Buffer): void
  3023. handshakeTimeout?: number | undefined
  3024. maxRedirects?: number | undefined
  3025. perMessageDeflate?: boolean | PerMessageDeflateOptions | undefined
  3026. localAddress?: string | undefined
  3027. protocolVersion?: number | undefined
  3028. headers?: { [key: string]: string } | undefined
  3029. origin?: string | undefined
  3030. agent?: Agent | undefined
  3031. host?: string | undefined
  3032. family?: number | undefined
  3033. checkServerIdentity?(servername: string, cert: CertMeta): boolean
  3034. rejectUnauthorized?: boolean | undefined
  3035. maxPayload?: number | undefined
  3036. skipUTF8Validation?: boolean | undefined
  3037. }
  3038. interface PerMessageDeflateOptions {
  3039. serverNoContextTakeover?: boolean | undefined
  3040. clientNoContextTakeover?: boolean | undefined
  3041. serverMaxWindowBits?: number | undefined
  3042. clientMaxWindowBits?: number | undefined
  3043. zlibDeflateOptions?:
  3044. | {
  3045. flush?: number | undefined
  3046. finishFlush?: number | undefined
  3047. chunkSize?: number | undefined
  3048. windowBits?: number | undefined
  3049. level?: number | undefined
  3050. memLevel?: number | undefined
  3051. strategy?: number | undefined
  3052. dictionary?: Buffer | Buffer[] | DataView | undefined
  3053. info?: boolean | undefined
  3054. }
  3055. | undefined
  3056. zlibInflateOptions?: ZlibOptions | undefined
  3057. threshold?: number | undefined
  3058. concurrencyLimit?: number | undefined
  3059. }
  3060. interface Event {
  3061. type: string
  3062. target: WebSocket
  3063. }
  3064. interface ErrorEvent {
  3065. error: any
  3066. message: string
  3067. type: string
  3068. target: WebSocket
  3069. }
  3070. interface CloseEvent {
  3071. wasClean: boolean
  3072. code: number
  3073. reason: string
  3074. type: string
  3075. target: WebSocket
  3076. }
  3077. interface MessageEvent {
  3078. data: Data
  3079. type: string
  3080. target: WebSocket
  3081. }
  3082. interface EventListenerOptions {
  3083. once?: boolean | undefined
  3084. }
  3085. interface ServerOptions {
  3086. host?: string | undefined
  3087. port?: number | undefined
  3088. backlog?: number | undefined
  3089. server?: Server | Server_2 | undefined
  3090. verifyClient?:
  3091. | VerifyClientCallbackAsync
  3092. | VerifyClientCallbackSync
  3093. | undefined
  3094. handleProtocols?: (
  3095. protocols: Set<string>,
  3096. request: IncomingMessage,
  3097. ) => string | false
  3098. path?: string | undefined
  3099. noServer?: boolean | undefined
  3100. clientTracking?: boolean | undefined
  3101. perMessageDeflate?: boolean | PerMessageDeflateOptions | undefined
  3102. maxPayload?: number | undefined
  3103. skipUTF8Validation?: boolean | undefined
  3104. WebSocket?: typeof WebSocket.WebSocket | undefined
  3105. }
  3106. interface AddressInfo {
  3107. address: string
  3108. family: string
  3109. port: number
  3110. }
  3111. // WebSocket Server
  3112. class Server<T extends WebSocket = WebSocket> extends EventEmitter {
  3113. options: ServerOptions
  3114. path: string
  3115. clients: Set<T>
  3116. constructor(options?: ServerOptions, callback?: () => void)
  3117. address(): AddressInfo | string
  3118. close(cb?: (err?: Error) => void): void
  3119. handleUpgrade(
  3120. request: IncomingMessage,
  3121. socket: Duplex,
  3122. upgradeHead: Buffer,
  3123. callback: (client: T, request: IncomingMessage) => void,
  3124. ): void
  3125. shouldHandle(request: IncomingMessage): boolean | Promise<boolean>
  3126. // Events
  3127. on(
  3128. event: 'connection',
  3129. cb: (this: Server<T>, socket: T, request: IncomingMessage) => void,
  3130. ): this
  3131. on(event: 'error', cb: (this: Server<T>, error: Error) => void): this
  3132. on(
  3133. event: 'headers',
  3134. cb: (
  3135. this: Server<T>,
  3136. headers: string[],
  3137. request: IncomingMessage,
  3138. ) => void,
  3139. ): this
  3140. on(event: 'close' | 'listening', cb: (this: Server<T>) => void): this
  3141. on(
  3142. event: string | symbol,
  3143. listener: (this: Server<T>, ...args: any[]) => void,
  3144. ): this
  3145. once(
  3146. event: 'connection',
  3147. cb: (this: Server<T>, socket: T, request: IncomingMessage) => void,
  3148. ): this
  3149. once(event: 'error', cb: (this: Server<T>, error: Error) => void): this
  3150. once(
  3151. event: 'headers',
  3152. cb: (
  3153. this: Server<T>,
  3154. headers: string[],
  3155. request: IncomingMessage,
  3156. ) => void,
  3157. ): this
  3158. once(event: 'close' | 'listening', cb: (this: Server<T>) => void): this
  3159. once(
  3160. event: string | symbol,
  3161. listener: (this: Server<T>, ...args: any[]) => void,
  3162. ): this
  3163. off(
  3164. event: 'connection',
  3165. cb: (this: Server<T>, socket: T, request: IncomingMessage) => void,
  3166. ): this
  3167. off(event: 'error', cb: (this: Server<T>, error: Error) => void): this
  3168. off(
  3169. event: 'headers',
  3170. cb: (
  3171. this: Server<T>,
  3172. headers: string[],
  3173. request: IncomingMessage,
  3174. ) => void,
  3175. ): this
  3176. off(event: 'close' | 'listening', cb: (this: Server<T>) => void): this
  3177. off(
  3178. event: string | symbol,
  3179. listener: (this: Server<T>, ...args: any[]) => void,
  3180. ): this
  3181. addListener(
  3182. event: 'connection',
  3183. cb: (client: T, request: IncomingMessage) => void,
  3184. ): this
  3185. addListener(event: 'error', cb: (err: Error) => void): this
  3186. addListener(
  3187. event: 'headers',
  3188. cb: (headers: string[], request: IncomingMessage) => void,
  3189. ): this
  3190. addListener(event: 'close' | 'listening', cb: () => void): this
  3191. addListener(
  3192. event: string | symbol,
  3193. listener: (...args: any[]) => void,
  3194. ): this
  3195. removeListener(event: 'connection', cb: (client: T) => void): this
  3196. removeListener(event: 'error', cb: (err: Error) => void): this
  3197. removeListener(
  3198. event: 'headers',
  3199. cb: (headers: string[], request: IncomingMessage) => void,
  3200. ): this
  3201. removeListener(event: 'close' | 'listening', cb: () => void): this
  3202. removeListener(
  3203. event: string | symbol,
  3204. listener: (...args: any[]) => void,
  3205. ): this
  3206. }
  3207. const WebSocketServer: typeof Server
  3208. interface WebSocketServer extends Server {} // tslint:disable-line no-empty-interface
  3209. const WebSocket: typeof WebSocketAlias
  3210. interface WebSocket extends WebSocketAlias {} // tslint:disable-line no-empty-interface
  3211. // WebSocket stream
  3212. function createWebSocketStream(
  3213. websocket: WebSocket,
  3214. options?: DuplexOptions,
  3215. ): Duplex
  3216. }
  3217. export { WebSocket_2 as WebSocket }
  3218. export declare const WebSocketAlias: typeof WebSocket_2;
  3219. export declare interface WebSocketAlias extends WebSocket_2 {}
  3220. export declare interface WebSocketClient {
  3221. /**
  3222. * Send event to the client
  3223. */
  3224. send(payload: HMRPayload): void;
  3225. /**
  3226. * Send custom event
  3227. */
  3228. send(event: string, payload?: CustomPayload['data']): void;
  3229. /**
  3230. * The raw WebSocket instance
  3231. * @advanced
  3232. */
  3233. socket: WebSocket_2;
  3234. }
  3235. export declare type WebSocketCustomListener<T> = (data: T, client: WebSocketClient) => void;
  3236. export declare interface WebSocketServer {
  3237. /**
  3238. * Listen on port and host
  3239. */
  3240. listen(): void;
  3241. /**
  3242. * Get all connected clients.
  3243. */
  3244. clients: Set<WebSocketClient>;
  3245. /**
  3246. * Broadcast events to all clients
  3247. */
  3248. send(payload: HMRPayload): void;
  3249. /**
  3250. * Send custom event
  3251. */
  3252. send<T extends string>(event: T, payload?: InferCustomEventPayload<T>): void;
  3253. /**
  3254. * Disconnect all clients and terminate the server.
  3255. */
  3256. close(): Promise<void>;
  3257. /**
  3258. * Handle custom event emitted by `import.meta.hot.send`
  3259. */
  3260. on: WebSocket_2.Server['on'] & {
  3261. <T extends string>(event: T, listener: WebSocketCustomListener<InferCustomEventPayload<T>>): void;
  3262. };
  3263. /**
  3264. * Unregister event listener.
  3265. */
  3266. off: WebSocket_2.Server['off'] & {
  3267. (event: string, listener: Function): void;
  3268. };
  3269. }
  3270. export { }