index.d.ts 119 KB

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