index.d.ts 112 KB

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