index.d.ts 112 KB

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