index.d.ts 115 KB

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