index.d.ts 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412
  1. /// <reference types="node" />
  2. import { ChangeEvent } from 'rollup';
  3. import { CustomPluginOptions } from 'rollup';
  4. import * as events from 'events';
  5. import * as fs from 'fs';
  6. import * as http from 'http';
  7. import * as https from 'https';
  8. import { IncomingMessage } from 'http';
  9. import { InputOptions } from 'rollup';
  10. import { LoadResult } from 'rollup';
  11. import * as net from 'net';
  12. import { OutputBundle } from 'rollup';
  13. import { OutputChunk } from 'rollup';
  14. import { PartialResolvedId } from 'rollup';
  15. import { Plugin as Plugin_2 } from 'rollup';
  16. import { PluginContext } from 'rollup';
  17. import { PluginHooks } from 'rollup';
  18. import * as Postcss from 'postcss';
  19. import { RequestOptions } from 'http';
  20. import { RequestOptions as RequestOptions_2 } from 'https';
  21. import { ResolveIdResult } from 'rollup';
  22. import { RollupOptions } from 'rollup';
  23. import { RollupOutput } from 'rollup';
  24. import { ServerResponse } from 'http';
  25. import { SourceDescription } from 'rollup';
  26. import { SourceMap } from 'rollup';
  27. import * as stream from 'stream';
  28. import { TransformOptions as TransformOptions_2 } from 'esbuild';
  29. import { TransformPluginContext } from 'rollup';
  30. import { TransformResult as TransformResult_2 } from 'rollup';
  31. import { TransformResult as TransformResult_3 } from 'esbuild';
  32. import * as url from 'url';
  33. export declare 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. /**
  44. * Specifies an `Object`, or an `Array` of `Object`,
  45. * which defines aliases used to replace values in `import` or `require` statements.
  46. * With either format, the order of the entries is important,
  47. * in that the first defined rules are applied first.
  48. *
  49. * This is passed to \@rollup/plugin-alias as the "entries" field
  50. * https://github.com/rollup/plugins/tree/master/packages/alias#entries
  51. */
  52. export declare type AliasOptions = readonly Alias[] | { [find: string]: string }
  53. /**
  54. * Bundles the app for production.
  55. * Returns a Promise containing the build result.
  56. */
  57. export declare function build(inlineConfig?: InlineConfig): Promise<RollupOutput | RollupOutput[]>;
  58. export declare interface BuildOptions {
  59. /**
  60. * Base public path when served in production.
  61. * @deprecated `base` is now a root-level config option.
  62. */
  63. base?: string;
  64. /**
  65. * Compatibility transform target. The transform is performed with esbuild
  66. * and the lowest supported target is es2015/es6. Note this only handles
  67. * syntax transformation and does not cover polyfills (except for dynamic
  68. * import)
  69. *
  70. * Default: 'modules' - Similar to `@babel/preset-env`'s targets.esmodules,
  71. * transpile targeting browsers that natively support es module imports. Also
  72. * injects a light-weight dynamic import polyfill.
  73. * https://caniuse.com/es6-module
  74. *
  75. * Another special value is 'esnext' - which only performs minimal trasnpiling
  76. * (for minification compat) and assumes native dynamic imports support.
  77. *
  78. * For custom targets, see https://esbuild.github.io/api/#target and
  79. * https://esbuild.github.io/content-types/#javascript for more details.
  80. */
  81. target?: 'modules' | TransformOptions_2['target'] | false;
  82. /**
  83. * Whether to inject dynamic import polyfill. Defaults to `true`, unless
  84. * `target` is `'esnext'`.
  85. * Note: does not apply to library mode.
  86. */
  87. polyfillDynamicImport?: boolean;
  88. /**
  89. * Directory relative from `root` where build output will be placed. If the
  90. * directory exists, it will be removed before the build.
  91. * @default 'dist'
  92. */
  93. outDir?: string;
  94. /**
  95. * Directory relative from `outDir` where the built js/css/image assets will
  96. * be placed.
  97. * @default 'assets'
  98. */
  99. assetsDir?: string;
  100. /**
  101. * Static asset files smaller than this number (in bytes) will be inlined as
  102. * base64 strings. Default limit is `4096` (4kb). Set to `0` to disable.
  103. * @default 4096
  104. */
  105. assetsInlineLimit?: number;
  106. /**
  107. * Whether to code-split CSS. When enabled, CSS in async chunks will be
  108. * inlined as strings in the chunk and inserted via dynamically created
  109. * style tags when the chunk is loaded.
  110. * @default true
  111. */
  112. cssCodeSplit?: boolean;
  113. /**
  114. * Whether to generate sourcemap
  115. * @default false
  116. */
  117. sourcemap?: boolean | 'inline';
  118. /**
  119. * Set to `false` to disable minification, or specify the minifier to use.
  120. * Available options are 'terser' or 'esbuild'.
  121. * @default 'terser'
  122. */
  123. minify?: boolean | 'terser' | 'esbuild';
  124. /**
  125. * Options for terser
  126. * https://terser.org/docs/api-reference#minify-options
  127. */
  128. terserOptions?: Terser.MinifyOptions;
  129. /**
  130. * Options for clean-css
  131. * https://github.com/jakubpawlowicz/clean-css#constructor-options
  132. */
  133. cleanCssOptions?: CleanCSS.Options;
  134. /**
  135. * Will be merged with internal rollup options.
  136. * https://rollupjs.org/guide/en/#big-list-of-options
  137. */
  138. rollupOptions?: RollupOptions;
  139. /**
  140. * Options to pass on to `@rollup/plugin-commonjs`
  141. */
  142. commonjsOptions?: RollupCommonJSOptions;
  143. /**
  144. * Whether to write bundle to disk
  145. * @default true
  146. */
  147. write?: boolean;
  148. /**
  149. * Empty outDir on write.
  150. * @default true when outDir is a sub directory of project root
  151. */
  152. emptyOutDir?: boolean | null;
  153. /**
  154. * Whether to emit a manifest.json under assets dir to map hash-less filenames
  155. * to their hashed versions. Useful when you want to generate your own HTML
  156. * instead of using the one generated by Vite.
  157. *
  158. * Example:
  159. *
  160. * ```json
  161. * {
  162. * "main.js": {
  163. * "file": "main.68fe3fad.js",
  164. * "css": "main.e6b63442.css",
  165. * "imports": [...],
  166. * "dynamicImports": [...]
  167. * }
  168. * }
  169. * ```
  170. * @default false
  171. */
  172. manifest?: boolean;
  173. /**
  174. * Build in library mode. The value should be the global name of the lib in
  175. * UMD mode. This will produce esm + cjs + umd bundle formats with default
  176. * configurations that are suitable for distributing libraries.
  177. */
  178. lib?: LibraryOptions | false;
  179. /**
  180. * Produce SSR oriented build. Note this requires specifying SSR entry via
  181. * `rollupOptions.input`.
  182. */
  183. ssr?: boolean | string;
  184. /**
  185. * Generate SSR manifest for determining style links and asset preload
  186. * directives in production.
  187. */
  188. ssrManifest?: boolean;
  189. /**
  190. * Set to false to disable brotli compressed size reporting for build.
  191. * Can slightly improve build speed.
  192. */
  193. brotliSize?: boolean;
  194. /**
  195. * Adjust chunk size warning limit (in kbs).
  196. * @default 500
  197. */
  198. chunkSizeWarningLimit?: number;
  199. }
  200. export declare namespace CleanCSS {
  201. /**
  202. * Shared options passed when initializing a new instance of CleanCSS that returns either a promise or output
  203. */
  204. export interface OptionsBase {
  205. /**
  206. * Controls compatibility mode used; defaults to ie10+ using `'*'`.
  207. * Compatibility hash exposes the following properties: `colors`, `properties`, `selectors`, and `units`
  208. */
  209. compatibility?: '*' | 'ie9' | 'ie8' | 'ie7' | CompatibilityOptions
  210. /**
  211. * Controls a function for handling remote requests; Defaults to the build in `loadRemoteResource` function
  212. */
  213. fetch?: (
  214. uri: string,
  215. inlineRequest: RequestOptions | RequestOptions_2,
  216. inlineTimeout: number,
  217. done: (message: string | number, body: string) => void
  218. ) => void
  219. /**
  220. * Controls output CSS formatting; defaults to `false`.
  221. * Format hash exposes the following properties: `breaks`, `breakWith`, `indentBy`, `indentWith`, `spaces`, and `wrapAt`.
  222. */
  223. format?: 'beautify' | 'keep-breaks' | FormatOptions | false
  224. /**
  225. * inline option whitelists which @import rules will be processed. Defaults to `'local'`
  226. * Accepts the following values:
  227. * 'local': enables local inlining;
  228. * 'remote': enables remote inlining;
  229. * 'none': disables all inlining;
  230. * 'all': enables all inlining, same as ['local', 'remote'];
  231. * '[uri]': enables remote inlining from the specified uri;
  232. * '![url]': disables remote inlining from the specified uri;
  233. */
  234. inline?: ReadonlyArray<string> | false
  235. /**
  236. * Controls extra options for inlining remote @import rules
  237. */
  238. inlineRequest?: RequestOptions | RequestOptions_2
  239. /**
  240. * Controls number of milliseconds after which inlining a remote @import fails; defaults to `5000`;
  241. */
  242. inlineTimeout?: number
  243. /**
  244. * Controls optimization level used; defaults to `1`.
  245. * Level hash exposes `1`, and `2`.
  246. */
  247. level?: 0 | 1 | 2 | OptimizationsOptions
  248. /**
  249. * Controls URL rebasing; defaults to `true`;
  250. */
  251. rebase?: boolean
  252. /**
  253. * controls a directory to which all URLs are rebased, most likely the directory under which the output file
  254. * will live; defaults to the current directory;
  255. */
  256. rebaseTo?: string
  257. /**
  258. * Controls whether an output source map is built; defaults to `false`
  259. */
  260. sourceMap?: boolean
  261. /**
  262. * Controls embedding sources inside a source map's `sourcesContent` field; defaults to `false`
  263. */
  264. sourceMapInlineSources?: boolean
  265. }
  266. /**
  267. * Fine grained configuration for compatibility option
  268. */
  269. export interface CompatibilityOptions {
  270. /**
  271. * A hash of compatibility options related to color
  272. */
  273. colors?: {
  274. /**
  275. * Controls `rgba()` / `hsla()` color support; defaults to `true`
  276. */
  277. opacity?: boolean
  278. }
  279. /**
  280. * A hash of properties that can be set with compatibility
  281. */
  282. properties?: {
  283. /**
  284. * Controls background-clip merging into shorthand; defaults to `true`
  285. */
  286. backgroundClipMerging?: boolean
  287. /**
  288. * Controls background-origin merging into shorthand; defaults to `true`
  289. */
  290. backgroundOriginMerging?: boolean
  291. /**
  292. * Controls background-size merging into shorthand; defaults to `true`
  293. */
  294. backgroundSizeMerging?: boolean
  295. /**
  296. * controls color optimizations; defaults to `true`
  297. */
  298. colors?: boolean
  299. /**
  300. * Controls keeping IE bang hack; defaults to `false`
  301. */
  302. ieBangHack?: boolean
  303. /**
  304. * Controls keeping IE `filter` / `-ms-filter`; defaults to `false`
  305. */
  306. ieFilters?: boolean
  307. /**
  308. * Controls keeping IE prefix hack; defaults to `false`
  309. */
  310. iePrefixHack?: boolean
  311. /**
  312. * Controls keeping IE suffix hack; defaults to `false`
  313. */
  314. ieSuffixHack?: boolean
  315. /**
  316. * Controls property merging based on understandably; defaults to `true`
  317. */
  318. merging?: boolean
  319. /**
  320. * Controls shortening pixel units into `pc`, `pt`, or `in` units; defaults to `false`
  321. */
  322. shorterLengthUnits?: false
  323. /**
  324. * Controls keeping space after closing brace - `url() no-repeat` into `url()no-repeat`; defaults to `true`
  325. */
  326. spaceAfterClosingBrace?: true
  327. /**
  328. * Controls keeping quoting inside `url()`; defaults to `false`
  329. */
  330. urlQuotes?: boolean
  331. /**
  332. * Controls removal of units `0` value; defaults to `true`
  333. */
  334. zeroUnits?: boolean
  335. }
  336. /**
  337. * A hash of options related to compatibility of selectors
  338. */
  339. selectors?: {
  340. /**
  341. * Controls extra space before `nav` element; defaults to `false`
  342. */
  343. adjacentSpace?: boolean
  344. /**
  345. * Controls removal of IE7 selector hacks, e.g. `*+html...`; defaults to `true`
  346. */
  347. ie7Hack?: boolean
  348. /**
  349. * Controls a whitelist of mergeable pseudo classes; defaults to `[':active', ...]`
  350. */
  351. mergeablePseudoClasses?: ReadonlyArray<string>
  352. /**
  353. * Controls a whitelist of mergeable pseudo elements; defaults to `['::after', ...]`
  354. */
  355. mergeablePseudoElements: ReadonlyArray<string>
  356. /**
  357. * Controls maximum number of selectors in a single rule (since 4.1.0); defaults to `8191`
  358. */
  359. mergeLimit: number
  360. /**
  361. * Controls merging of rules with multiple pseudo classes / elements (since 4.1.0); defaults to `true`
  362. */
  363. multiplePseudoMerging: boolean
  364. }
  365. /**
  366. * A hash of options related to comparability of supported units
  367. */
  368. units?: {
  369. /**
  370. * Controls treating `ch` as a supported unit; defaults to `true`
  371. */
  372. ch?: boolean
  373. /**
  374. * Controls treating `in` as a supported unit; defaults to `true`
  375. */
  376. in?: boolean
  377. /**
  378. * Controls treating `pc` as a supported unit; defaults to `true`
  379. */
  380. pc?: boolean
  381. /**
  382. * Controls treating `pt` as a supported unit; defaults to `true`
  383. */
  384. pt?: boolean
  385. /**
  386. * Controls treating `rem` as a supported unit; defaults to `true`
  387. */
  388. rem?: boolean
  389. /**
  390. * Controls treating `vh` as a supported unit; defaults to `true`
  391. */
  392. vh?: boolean
  393. /**
  394. * Controls treating `vm` as a supported unit; defaults to `true`
  395. */
  396. vm?: boolean
  397. /**
  398. * Controls treating `vmax` as a supported unit; defaults to `true`
  399. */
  400. vmax?: boolean
  401. /**
  402. * Controls treating `vmin` as a supported unit; defaults to `true`
  403. */
  404. vmin?: boolean
  405. }
  406. }
  407. /**
  408. * Fine grained options for configuring the CSS formatting
  409. */
  410. export interface FormatOptions {
  411. /**
  412. * Controls where to insert breaks
  413. */
  414. breaks?: {
  415. /**
  416. * Controls if a line break comes after an at-rule; e.g. `@charset`; defaults to `false`
  417. */
  418. afterAtRule?: boolean
  419. /**
  420. * Controls if a line break comes after a block begins; e.g. `@media`; defaults to `false`
  421. */
  422. afterBlockBegins?: boolean
  423. /**
  424. * Controls if a line break comes after a block ends, defaults to `false`
  425. */
  426. afterBlockEnds?: boolean
  427. /**
  428. * Controls if a line break comes after a comment; defaults to `false`
  429. */
  430. afterComment?: boolean
  431. /**
  432. * Controls if a line break comes after a property; defaults to `false`
  433. */
  434. afterProperty?: boolean
  435. /**
  436. * Controls if a line break comes after a rule begins; defaults to `false`
  437. */
  438. afterRuleBegins?: boolean
  439. /**
  440. * Controls if a line break comes after a rule ends; defaults to `false`
  441. */
  442. afterRuleEnds?: boolean
  443. /**
  444. * Controls if a line break comes before a block ends; defaults to `false`
  445. */
  446. beforeBlockEnds?: boolean
  447. /**
  448. * Controls if a line break comes between selectors; defaults to `false`
  449. */
  450. betweenSelectors?: boolean
  451. }
  452. /**
  453. * Controls the new line character, can be `'\r\n'` or `'\n'`(aliased as `'windows'` and `'unix'`
  454. * or `'crlf'` and `'lf'`); defaults to system one, so former on Windows and latter on Unix
  455. */
  456. breakWith?: string
  457. /**
  458. * Controls number of characters to indent with; defaults to `0`
  459. */
  460. indentBy?: number
  461. /**
  462. * Controls a character to indent with, can be `'space'` or `'tab'`; defaults to `'space'`
  463. */
  464. indentWith?: 'space' | 'tab'
  465. /**
  466. * Controls where to insert spaces
  467. */
  468. spaces?: {
  469. /**
  470. * Controls if spaces come around selector relations; e.g. `div > a`; defaults to `false`
  471. */
  472. aroundSelectorRelation?: boolean
  473. /**
  474. * Controls if a space comes before a block begins; e.g. `.block {`; defaults to `false`
  475. */
  476. beforeBlockBegins?: boolean
  477. /**
  478. * Controls if a space comes before a value; e.g. `width: 1rem`; defaults to `false`
  479. */
  480. beforeValue?: boolean
  481. }
  482. /**
  483. * Controls maximum line length; defaults to `false`
  484. */
  485. wrapAt?: false | number
  486. /**
  487. * Controls removing trailing semicolons in rule; defaults to `false` - means remove
  488. */
  489. semicolonAfterLastProperty?: boolean
  490. }
  491. /**
  492. * Fine grained options for configuring optimizations
  493. */
  494. export interface OptimizationsOptions {
  495. 1?: {
  496. /**
  497. * Sets all optimizations at this level unless otherwise specified
  498. */
  499. all?: boolean
  500. /**
  501. * Controls `@charset` moving to the front of a stylesheet; defaults to `true`
  502. */
  503. cleanupCharsets?: boolean
  504. /**
  505. * Controls URL normalization; defaults to `true`
  506. */
  507. normalizeUrls?: boolean
  508. /**
  509. * Controls `background` property optimizations; defaults to `true`
  510. */
  511. optimizeBackground?: boolean
  512. /**
  513. * Controls `border-radius` property optimizations; defaults to `true`
  514. */
  515. optimizeBorderRadius?: boolean
  516. /**
  517. * Controls `filter` property optimizations; defaults to `true`
  518. */
  519. optimizeFilter?: boolean
  520. /**
  521. * Controls `font` property optimizations; defaults to `true`
  522. */
  523. optimizeFont?: boolean
  524. /**
  525. * Controls `font-weight` property optimizations; defaults to `true`
  526. */
  527. optimizeFontWeight?: boolean
  528. /**
  529. * Controls `outline` property optimizations; defaults to `true`
  530. */
  531. optimizeOutline?: boolean
  532. /**
  533. * Controls removing empty rules and nested blocks; defaults to `true`
  534. */
  535. removeEmpty?: boolean
  536. /**
  537. * Controls removing negative paddings; defaults to `true`
  538. */
  539. removeNegativePaddings?: boolean
  540. /**
  541. * Controls removing quotes when unnecessary; defaults to `true`
  542. */
  543. removeQuotes?: boolean
  544. /**
  545. * Controls removing unused whitespace; defaults to `true`
  546. */
  547. removeWhitespace?: boolean
  548. /**
  549. * Contols removing redundant zeros; defaults to `true`
  550. */
  551. replaceMultipleZeros?: boolean
  552. /**
  553. * Controls replacing time units with shorter values; defaults to `true`
  554. */
  555. replaceTimeUnits?: boolean
  556. /**
  557. * Controls replacing zero values with units; defaults to `true`
  558. */
  559. replaceZeroUnits?: boolean
  560. /**
  561. * Rounds pixel values to `N` decimal places; `false` disables rounding; defaults to `false`
  562. */
  563. roundingPrecision?: boolean
  564. /**
  565. * denotes selector sorting method; can be `'natural'` or `'standard'`, `'none'`, or false (the last two
  566. * since 4.1.0); defaults to `'standard'`
  567. */
  568. selectorsSortingMethod?: 'standard' | 'natural' | 'none'
  569. /**
  570. * denotes a number of /*! ... * / comments preserved; defaults to `all`
  571. */
  572. specialComments?: string
  573. /**
  574. * Controls at-rules (e.g. `@charset`, `@import`) optimizing; defaults to `true`
  575. */
  576. tidyAtRules?: boolean
  577. /**
  578. * Controls block scopes (e.g. `@media`) optimizing; defaults to `true`
  579. */
  580. tidyBlockScopes?: boolean
  581. /**
  582. * Controls selectors optimizing; defaults to `true`
  583. */
  584. tidySelectors?: boolean
  585. /**
  586. * Defines a callback for fine-grained property optimization; defaults to no-op
  587. */
  588. transform?: (
  589. propertyName: string,
  590. propertyValue: string,
  591. selector?: string
  592. ) => string
  593. }
  594. 2?: {
  595. /**
  596. * Sets all optimizations at this level unless otherwise specified
  597. */
  598. all?: boolean
  599. /**
  600. * Controls adjacent rules merging; defaults to true
  601. */
  602. mergeAdjacentRules?: boolean
  603. /**
  604. * Controls merging properties into shorthands; defaults to true
  605. */
  606. mergeIntoShorthands?: boolean
  607. /**
  608. * Controls `@media` merging; defaults to true
  609. */
  610. mergeMedia?: boolean
  611. /**
  612. * Controls non-adjacent rule merging; defaults to true
  613. */
  614. mergeNonAdjacentRules?: boolean
  615. /**
  616. * Controls semantic merging; defaults to false
  617. */
  618. mergeSemantically?: boolean
  619. /**
  620. * Controls property overriding based on understandably; defaults to true
  621. */
  622. overrideProperties?: boolean
  623. /**
  624. * Controls removing empty rules and nested blocks; defaults to `true`
  625. */
  626. removeEmpty?: boolean
  627. /**
  628. * Controls non-adjacent rule reducing; defaults to true
  629. */
  630. reduceNonAdjacentRules?: boolean
  631. /**
  632. * Controls duplicate `@font-face` removing; defaults to true
  633. */
  634. removeDuplicateFontRules?: boolean
  635. /**
  636. * Controls duplicate `@media` removing; defaults to true
  637. */
  638. removeDuplicateMediaBlocks?: boolean
  639. /**
  640. * Controls duplicate rules removing; defaults to true
  641. */
  642. removeDuplicateRules?: boolean
  643. /**
  644. * Controls unused at rule removing; defaults to false (available since 4.1.0)
  645. */
  646. removeUnusedAtRules?: boolean
  647. /**
  648. * Controls rule restructuring; defaults to false
  649. */
  650. restructureRules?: boolean
  651. /**
  652. * Controls which properties won't be optimized, defaults to `[]` which means all will be optimized (since 4.1.0)
  653. */
  654. skipProperties?: ReadonlyArray<string>
  655. }
  656. }
  657. /**
  658. * Options when returning a promise
  659. */
  660. export type OptionsPromise = OptionsBase & {
  661. /**
  662. * If you prefer clean-css to return a Promise object then you need to explicitly ask for it; defaults to `false`
  663. */
  664. returnPromise: true
  665. }
  666. /**
  667. * Options when returning an output
  668. */
  669. export type OptionsOutput = OptionsBase & {
  670. /**
  671. * If you prefer clean-css to return a Promise object then you need to explicitly ask for it; defaults to `false`
  672. */
  673. returnPromise?: false
  674. }
  675. /**
  676. * Discriminant union of both sets of options types. If you initialize without setting `returnPromise: true`
  677. * and want to return a promise, you will need to cast to the correct options type so that TypeScript
  678. * knows what the expected return type will be:
  679. * `(options = options as CleanCSS.OptionsPromise).returnPromise = true`
  680. */
  681. export type Options = OptionsPromise | OptionsOutput
  682. }
  683. export declare interface ConfigEnv {
  684. command: 'build' | 'serve';
  685. mode: string;
  686. }
  687. export declare namespace Connect {
  688. export type ServerHandle = HandleFunction | http.Server
  689. export class IncomingMessage extends http.IncomingMessage {
  690. originalUrl?: http.IncomingMessage['url']
  691. }
  692. export type NextFunction = (err?: any) => void
  693. export type SimpleHandleFunction = (
  694. req: IncomingMessage,
  695. res: http.ServerResponse
  696. ) => void
  697. export type NextHandleFunction = (
  698. req: IncomingMessage,
  699. res: http.ServerResponse,
  700. next: NextFunction
  701. ) => void
  702. export type ErrorHandleFunction = (
  703. err: any,
  704. req: IncomingMessage,
  705. res: http.ServerResponse,
  706. next: NextFunction
  707. ) => void
  708. export type HandleFunction =
  709. | SimpleHandleFunction
  710. | NextHandleFunction
  711. | ErrorHandleFunction
  712. export interface ServerStackItem {
  713. route: string
  714. handle: ServerHandle
  715. }
  716. export interface Server extends NodeJS.EventEmitter {
  717. (req: http.IncomingMessage, res: http.ServerResponse, next?: Function): void
  718. route: string
  719. stack: ServerStackItem[]
  720. /**
  721. * Utilize the given middleware `handle` to the given `route`,
  722. * defaulting to _/_. This "route" is the mount-point for the
  723. * middleware, when given a value other than _/_ the middleware
  724. * is only effective when that segment is present in the request's
  725. * pathname.
  726. *
  727. * For example if we were to mount a function at _/admin_, it would
  728. * be invoked on _/admin_, and _/admin/settings_, however it would
  729. * not be invoked for _/_, or _/posts_.
  730. */
  731. use(fn: NextHandleFunction): Server
  732. use(fn: HandleFunction): Server
  733. use(route: string, fn: NextHandleFunction): Server
  734. use(route: string, fn: HandleFunction): Server
  735. /**
  736. * Handle server requests, punting them down
  737. * the middleware stack.
  738. */
  739. handle(
  740. req: http.IncomingMessage,
  741. res: http.ServerResponse,
  742. next: Function
  743. ): void
  744. /**
  745. * Listen for connections.
  746. *
  747. * This method takes the same arguments
  748. * as node's `http.Server#listen()`.
  749. *
  750. * HTTP and HTTPS:
  751. *
  752. * If you run your application both as HTTP
  753. * and HTTPS you may wrap them individually,
  754. * since your Connect "server" is really just
  755. * a JavaScript `Function`.
  756. *
  757. * var connect = require('connect')
  758. * , http = require('http')
  759. * , https = require('https');
  760. *
  761. * var app = connect();
  762. *
  763. * http.createServer(app).listen(80);
  764. * https.createServer(options, app).listen(443);
  765. */
  766. listen(
  767. port: number,
  768. hostname?: string,
  769. backlog?: number,
  770. callback?: Function
  771. ): http.Server
  772. listen(port: number, hostname?: string, callback?: Function): http.Server
  773. listen(path: string, callback?: Function): http.Server
  774. listen(handle: any, listeningListener?: Function): http.Server
  775. }
  776. }
  777. export declare interface ConnectedPayload {
  778. type: 'connected'
  779. }
  780. /**
  781. * https://github.com/expressjs/cors#configuration-options
  782. */
  783. export declare interface CorsOptions {
  784. origin?: CorsOrigin | ((origin: string, cb: (err: Error, origins: CorsOrigin) => void) => void);
  785. methods?: string | string[];
  786. allowedHeaders?: string | string[];
  787. exposedHeaders?: string | string[];
  788. credentials?: boolean;
  789. maxAge?: number;
  790. preflightContinue?: boolean;
  791. optionsSuccessStatus?: number;
  792. }
  793. export declare type CorsOrigin = boolean | string | RegExp | (string | RegExp)[];
  794. export declare function createLogger(level?: LogLevel, allowClearScreen?: boolean): Logger;
  795. export declare function createServer(inlineConfig?: InlineConfig): Promise<ViteDevServer>;
  796. export declare interface CSSModulesOptions {
  797. getJSON?: (cssFileName: string, json: Record<string, string>, outputFileName: string) => void;
  798. scopeBehaviour?: 'global' | 'local';
  799. globalModulePaths?: string[];
  800. generateScopedName?: string | ((name: string, filename: string, css: string) => string);
  801. hashPrefix?: string;
  802. /**
  803. * default: 'camelCase'
  804. */
  805. localsConvention?: 'camelCase' | 'camelCaseOnly' | 'dashes' | 'dashesOnly' | null;
  806. }
  807. export declare interface CSSOptions {
  808. /**
  809. * https://github.com/css-modules/postcss-modules
  810. */
  811. modules?: CSSModulesOptions | false;
  812. preprocessorOptions?: Record<string, any>;
  813. postcss?: string | (Postcss.ProcessOptions & {
  814. plugins?: Postcss.Plugin[];
  815. });
  816. }
  817. export declare interface CustomPayload {
  818. type: 'custom'
  819. event: string
  820. data?: any
  821. }
  822. /**
  823. * Type helper to make it easier to use vite.config.ts
  824. * accepts a direct {@link UserConfig} object, or a function that returns it.
  825. * The function receives a {@link ConfigEnv} object that exposes two properties:
  826. * `command` (either `'build'` or `'serve'`), and `mode`.
  827. */
  828. export declare function defineConfig(config: UserConfigExport): UserConfigExport;
  829. export declare interface DepOptimizationMetadata {
  830. /**
  831. * The main hash is determined by user config and dependency lockfiles.
  832. * This is checked on server startup to avoid unnecessary re-bundles.
  833. */
  834. hash: string;
  835. /**
  836. * The browser hash is determined by the main hash plus additional dependencies
  837. * discovered at runtime. This is used to invalidate browser requests to
  838. * optimized deps.
  839. */
  840. browserHash: string;
  841. optimized: Record<string, {
  842. file: string;
  843. src: string;
  844. needsInterop: boolean;
  845. }>;
  846. }
  847. export declare interface DepOptimizationOptions {
  848. /**
  849. * By default, Vite will crawl your index.html to detect dependencies that
  850. * need to be pre-bundled. If build.rollupOptions.input is specified, Vite
  851. * will crawl those entry points instead.
  852. *
  853. * If neither of these fit your needs, you can specify custom entries using
  854. * this option - the value should be a fast-glob pattern or array of patterns
  855. * (https://github.com/mrmlnc/fast-glob#basic-syntax) that are relative from
  856. * vite project root. This will overwrite default entries inference.
  857. */
  858. entries?: string | string[];
  859. /**
  860. * Force optimize listed dependencies (must be resolvable import paths,
  861. * cannot be globs).
  862. */
  863. include?: string[];
  864. /**
  865. * Do not optimize these dependencies (must be resolvable import paths,
  866. * cannot be globs).
  867. */
  868. exclude?: string[];
  869. }
  870. export declare interface ErrorPayload {
  871. type: 'error'
  872. err: {
  873. [name: string]: any
  874. message: string
  875. stack: string
  876. id?: string
  877. frame?: string
  878. plugin?: string
  879. pluginCode?: string
  880. loc?: {
  881. file?: string
  882. line: number
  883. column: number
  884. }
  885. }
  886. }
  887. export declare interface ESBuildOptions extends TransformOptions_2 {
  888. include?: string | RegExp | string[] | RegExp[];
  889. exclude?: string | RegExp | string[] | RegExp[];
  890. jsxInject?: string;
  891. }
  892. export declare type ESBuildTransformResult = Omit<TransformResult_3, 'map'> & {
  893. map: SourceMap;
  894. };
  895. export declare interface FSWatcher extends fs.FSWatcher {
  896. options: WatchOptions
  897. /**
  898. * Constructs a new FSWatcher instance with optional WatchOptions parameter.
  899. */
  900. (options?: WatchOptions): void
  901. /**
  902. * Add files, directories, or glob patterns for tracking. Takes an array of strings or just one
  903. * string.
  904. */
  905. add(paths: string | ReadonlyArray<string>): void
  906. /**
  907. * Stop watching files, directories, or glob patterns. Takes an array of strings or just one
  908. * string.
  909. */
  910. unwatch(paths: string | ReadonlyArray<string>): void
  911. /**
  912. * Returns an object representing all the paths on the file system being watched by this
  913. * `FSWatcher` instance. The object's keys are all the directories (using absolute paths unless
  914. * the `cwd` option was used), and the values are arrays of the names of the items contained in
  915. * each directory.
  916. */
  917. getWatched(): {
  918. [directory: string]: string[]
  919. }
  920. /**
  921. * Removes all listeners from watched files.
  922. */
  923. close(): Promise<void>
  924. on(
  925. event: 'add' | 'addDir' | 'change',
  926. listener: (path: string, stats?: fs.Stats) => void
  927. ): this
  928. on(
  929. event: 'all',
  930. listener: (
  931. eventName: 'add' | 'addDir' | 'change' | 'unlink' | 'unlinkDir',
  932. path: string,
  933. stats?: fs.Stats
  934. ) => void
  935. ): this
  936. /**
  937. * Error occurred
  938. */
  939. on(event: 'error', listener: (error: Error) => void): this
  940. /**
  941. * Exposes the native Node `fs.FSWatcher events`
  942. */
  943. on(
  944. event: 'raw',
  945. listener: (eventName: string, path: string, details: any) => void
  946. ): this
  947. /**
  948. * Fires when the initial scan is complete
  949. */
  950. on(event: 'ready', listener: () => void): this
  951. on(event: 'unlink' | 'unlinkDir', listener: (path: string) => void): this
  952. on(event: string, listener: (...args: any[]) => void): this
  953. }
  954. export declare interface FullReloadPayload {
  955. type: 'full-reload'
  956. path?: string
  957. }
  958. export declare interface HmrContext {
  959. file: string;
  960. timestamp: number;
  961. modules: Array<ModuleNode>;
  962. read: () => string | Promise<string>;
  963. server: ViteDevServer;
  964. }
  965. export declare interface HmrOptions {
  966. protocol?: string;
  967. host?: string;
  968. port?: number;
  969. path?: string;
  970. timeout?: number;
  971. overlay?: boolean;
  972. }
  973. export declare type HMRPayload =
  974. | ConnectedPayload
  975. | UpdatePayload
  976. | FullReloadPayload
  977. | CustomPayload
  978. | ErrorPayload
  979. | PrunePayload
  980. export declare interface HtmlTagDescriptor {
  981. tag: string;
  982. attrs?: Record<string, string | boolean | undefined>;
  983. children?: string | HtmlTagDescriptor[];
  984. /**
  985. * default: 'head-prepend'
  986. */
  987. injectTo?: 'head' | 'body' | 'head-prepend' | 'body-prepend';
  988. }
  989. export declare namespace HttpProxy {
  990. export type ProxyTarget = ProxyTargetUrl | ProxyTargetDetailed
  991. export type ProxyTargetUrl = string | Partial<url.Url>
  992. export interface ProxyTargetDetailed {
  993. host: string
  994. port: number
  995. protocol?: string
  996. hostname?: string
  997. socketPath?: string
  998. key?: string
  999. passphrase?: string
  1000. pfx?: Buffer | string
  1001. cert?: string
  1002. ca?: string
  1003. ciphers?: string
  1004. secureProtocol?: string
  1005. }
  1006. export type ErrorCallback = (
  1007. err: Error,
  1008. req: http.IncomingMessage,
  1009. res: http.ServerResponse,
  1010. target?: ProxyTargetUrl
  1011. ) => void
  1012. export class Server extends events.EventEmitter {
  1013. /**
  1014. * Creates the proxy server with specified options.
  1015. * @param options - Config object passed to the proxy
  1016. */
  1017. constructor(options?: ServerOptions)
  1018. /**
  1019. * Used for proxying regular HTTP(S) requests
  1020. * @param req - Client request.
  1021. * @param res - Client response.
  1022. * @param options - Additionnal options.
  1023. */
  1024. web(
  1025. req: http.IncomingMessage,
  1026. res: http.ServerResponse,
  1027. options?: ServerOptions,
  1028. callback?: ErrorCallback
  1029. ): void
  1030. /**
  1031. * Used for proxying regular HTTP(S) requests
  1032. * @param req - Client request.
  1033. * @param socket - Client socket.
  1034. * @param head - Client head.
  1035. * @param options - Additionnal options.
  1036. */
  1037. ws(
  1038. req: http.IncomingMessage,
  1039. socket: any,
  1040. head: any,
  1041. options?: ServerOptions,
  1042. callback?: ErrorCallback
  1043. ): void
  1044. /**
  1045. * A function that wraps the object in a webserver, for your convenience
  1046. * @param port - Port to listen on
  1047. */
  1048. listen(port: number): Server
  1049. /**
  1050. * A function that closes the inner webserver and stops listening on given port
  1051. */
  1052. close(callback?: () => void): void
  1053. /**
  1054. * Creates the proxy server with specified options.
  1055. * @param options - Config object passed to the proxy
  1056. * @returns Proxy object with handlers for `ws` and `web` requests
  1057. */
  1058. static createProxyServer(options?: ServerOptions): Server
  1059. /**
  1060. * Creates the proxy server with specified options.
  1061. * @param options - Config object passed to the proxy
  1062. * @returns Proxy object with handlers for `ws` and `web` requests
  1063. */
  1064. static createServer(options?: ServerOptions): Server
  1065. /**
  1066. * Creates the proxy server with specified options.
  1067. * @param options - Config object passed to the proxy
  1068. * @returns Proxy object with handlers for `ws` and `web` requests
  1069. */
  1070. static createProxy(options?: ServerOptions): Server
  1071. addListener(event: string, listener: () => void): this
  1072. on(event: string, listener: () => void): this
  1073. on(event: 'error', listener: ErrorCallback): this
  1074. on(
  1075. event: 'start',
  1076. listener: (
  1077. req: http.IncomingMessage,
  1078. res: http.ServerResponse,
  1079. target: ProxyTargetUrl
  1080. ) => void
  1081. ): this
  1082. on(
  1083. event: 'proxyReq',
  1084. listener: (
  1085. proxyReq: http.ClientRequest,
  1086. req: http.IncomingMessage,
  1087. res: http.ServerResponse,
  1088. options: ServerOptions
  1089. ) => void
  1090. ): this
  1091. on(
  1092. event: 'proxyRes',
  1093. listener: (
  1094. proxyRes: http.IncomingMessage,
  1095. req: http.IncomingMessage,
  1096. res: http.ServerResponse
  1097. ) => void
  1098. ): this
  1099. on(
  1100. event: 'proxyReqWs',
  1101. listener: (
  1102. proxyReq: http.ClientRequest,
  1103. req: http.IncomingMessage,
  1104. socket: net.Socket,
  1105. options: ServerOptions,
  1106. head: any
  1107. ) => void
  1108. ): this
  1109. on(
  1110. event: 'econnreset',
  1111. listener: (
  1112. err: Error,
  1113. req: http.IncomingMessage,
  1114. res: http.ServerResponse,
  1115. target: ProxyTargetUrl
  1116. ) => void
  1117. ): this
  1118. on(
  1119. event: 'end',
  1120. listener: (
  1121. req: http.IncomingMessage,
  1122. res: http.ServerResponse,
  1123. proxyRes: http.IncomingMessage
  1124. ) => void
  1125. ): this
  1126. on(
  1127. event: 'close',
  1128. listener: (
  1129. proxyRes: http.IncomingMessage,
  1130. proxySocket: net.Socket,
  1131. proxyHead: any
  1132. ) => void
  1133. ): this
  1134. once(event: string, listener: () => void): this
  1135. removeListener(event: string, listener: () => void): this
  1136. removeAllListeners(event?: string): this
  1137. getMaxListeners(): number
  1138. setMaxListeners(n: number): this
  1139. listeners(event: string): Array<() => void>
  1140. emit(event: string, ...args: any[]): boolean
  1141. listenerCount(type: string): number
  1142. }
  1143. export interface ServerOptions {
  1144. /** URL string to be parsed with the url module. */
  1145. target?: ProxyTarget
  1146. /** URL string to be parsed with the url module. */
  1147. forward?: ProxyTargetUrl
  1148. /** Object to be passed to http(s).request. */
  1149. agent?: any
  1150. /** Object to be passed to https.createServer(). */
  1151. ssl?: any
  1152. /** If you want to proxy websockets. */
  1153. ws?: boolean
  1154. /** Adds x- forward headers. */
  1155. xfwd?: boolean
  1156. /** Verify SSL certificate. */
  1157. secure?: boolean
  1158. /** Explicitly specify if we are proxying to another proxy. */
  1159. toProxy?: boolean
  1160. /** Specify whether you want to prepend the target's path to the proxy path. */
  1161. prependPath?: boolean
  1162. /** Specify whether you want to ignore the proxy path of the incoming request. */
  1163. ignorePath?: boolean
  1164. /** Local interface string to bind for outgoing connections. */
  1165. localAddress?: string
  1166. /** Changes the origin of the host header to the target URL. */
  1167. changeOrigin?: boolean
  1168. /** specify whether you want to keep letter case of response header key */
  1169. preserveHeaderKeyCase?: boolean
  1170. /** Basic authentication i.e. 'user:password' to compute an Authorization header. */
  1171. auth?: string
  1172. /** Rewrites the location hostname on (301 / 302 / 307 / 308) redirects, Default: null. */
  1173. hostRewrite?: string
  1174. /** Rewrites the location host/ port on (301 / 302 / 307 / 308) redirects based on requested host/ port.Default: false. */
  1175. autoRewrite?: boolean
  1176. /** Rewrites the location protocol on (301 / 302 / 307 / 308) redirects to 'http' or 'https'.Default: null. */
  1177. protocolRewrite?: string
  1178. /** rewrites domain of set-cookie headers. */
  1179. cookieDomainRewrite?: false | string | { [oldDomain: string]: string }
  1180. /** rewrites path of set-cookie headers. Default: false */
  1181. cookiePathRewrite?: false | string | { [oldPath: string]: string }
  1182. /** object with extra headers to be added to target requests. */
  1183. headers?: { [header: string]: string }
  1184. /** Timeout (in milliseconds) when proxy receives no response from target. Default: 120000 (2 minutes) */
  1185. proxyTimeout?: number
  1186. /** Timeout (in milliseconds) for incoming requests */
  1187. timeout?: number
  1188. /** Specify whether you want to follow redirects. Default: false */
  1189. followRedirects?: boolean
  1190. /** 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 */
  1191. selfHandleResponse?: boolean
  1192. /** Buffer */
  1193. buffer?: stream.Stream
  1194. }
  1195. }
  1196. export declare type IndexHtmlTransform = IndexHtmlTransformHook | {
  1197. enforce?: 'pre' | 'post';
  1198. transform: IndexHtmlTransformHook;
  1199. };
  1200. export declare interface IndexHtmlTransformContext {
  1201. /**
  1202. * public path when served
  1203. */
  1204. path: string;
  1205. /**
  1206. * filename on disk
  1207. */
  1208. filename: string;
  1209. server?: ViteDevServer;
  1210. bundle?: OutputBundle;
  1211. chunk?: OutputChunk;
  1212. }
  1213. export declare type IndexHtmlTransformHook = (html: string, ctx: IndexHtmlTransformContext) => IndexHtmlTransformResult | void | Promise<IndexHtmlTransformResult | void>;
  1214. export declare type IndexHtmlTransformResult = string | HtmlTagDescriptor[] | {
  1215. html: string;
  1216. tags: HtmlTagDescriptor[];
  1217. };
  1218. export declare interface InlineConfig extends UserConfig {
  1219. configFile?: string | false;
  1220. }
  1221. export declare interface InternalResolveOptions extends ResolveOptions {
  1222. root: string;
  1223. isBuild: boolean;
  1224. isProduction: boolean;
  1225. /**
  1226. * src code mode also attempts the following:
  1227. * - resolving /xxx as URLs
  1228. * - resolving bare imports from optimized deps
  1229. */
  1230. asSrc?: boolean;
  1231. tryIndex?: boolean;
  1232. tryPrefix?: string;
  1233. preferRelative?: boolean;
  1234. isRequire?: boolean;
  1235. }
  1236. export declare interface JsonOptions {
  1237. /**
  1238. * Generate a named export for every property of the JSON object
  1239. * @default true
  1240. */
  1241. namedExports?: boolean;
  1242. /**
  1243. * Generate performant output as JSON.parse("stringified").
  1244. * Enabling this will disable namedExports.
  1245. * @default false
  1246. */
  1247. stringify?: boolean;
  1248. }
  1249. export declare type LibraryFormats = 'es' | 'cjs' | 'umd' | 'iife';
  1250. export declare interface LibraryOptions {
  1251. entry: string;
  1252. name?: string;
  1253. formats?: LibraryFormats[];
  1254. }
  1255. export declare function loadConfigFromFile(configEnv: ConfigEnv, configFile?: string, configRoot?: string, logLevel?: LogLevel): Promise<{
  1256. path: string;
  1257. config: UserConfig;
  1258. } | null>;
  1259. export declare function loadEnv(mode: string, root: string, prefix?: string): Record<string, string>;
  1260. export declare interface Logger {
  1261. info(msg: string, options?: LogOptions): void;
  1262. warn(msg: string, options?: LogOptions): void;
  1263. error(msg: string, options?: LogOptions): void;
  1264. clearScreen(type: LogType): void;
  1265. hasWarned: boolean;
  1266. }
  1267. export declare type LogLevel = LogType | 'silent';
  1268. export declare interface LogOptions {
  1269. clear?: boolean;
  1270. timestamp?: boolean;
  1271. }
  1272. export declare type LogType = 'error' | 'warn' | 'info';
  1273. export declare function mergeConfig(a: Record<string, any>, b: Record<string, any>, isRoot?: boolean): Record<string, any>;
  1274. export declare class ModuleGraph {
  1275. urlToModuleMap: Map<string, ModuleNode>;
  1276. idToModuleMap: Map<string, ModuleNode>;
  1277. fileToModulesMap: Map<string, Set<ModuleNode>>;
  1278. container: PluginContainer;
  1279. constructor(container: PluginContainer);
  1280. getModuleByUrl(rawUrl: string): Promise<ModuleNode | undefined>;
  1281. getModuleById(id: string): ModuleNode | undefined;
  1282. getModulesByFile(file: string): Set<ModuleNode> | undefined;
  1283. onFileChange(file: string): void;
  1284. invalidateModule(mod: ModuleNode, seen?: Set<ModuleNode>): void;
  1285. invalidateAll(): void;
  1286. /**
  1287. * Update the module graph based on a module's updated imports information
  1288. * If there are dependencies that no longer have any importers, they are
  1289. * returned as a Set.
  1290. */
  1291. updateModuleInfo(mod: ModuleNode, importedModules: Set<string | ModuleNode>, acceptedModules: Set<string | ModuleNode>, isSelfAccepting: boolean): Promise<Set<ModuleNode> | undefined>;
  1292. ensureEntryFromUrl(rawUrl: string): Promise<ModuleNode>;
  1293. createFileOnlyEntry(file: string): ModuleNode;
  1294. resolveUrl(url: string): Promise<[string, string]>;
  1295. }
  1296. export declare class ModuleNode {
  1297. /**
  1298. * Public served url path, starts with /
  1299. */
  1300. url: string;
  1301. /**
  1302. * Resolved file system path + query
  1303. */
  1304. id: string | null;
  1305. file: string | null;
  1306. type: 'js' | 'css';
  1307. importers: Set<ModuleNode>;
  1308. importedModules: Set<ModuleNode>;
  1309. acceptedHmrDeps: Set<ModuleNode>;
  1310. isSelfAccepting: boolean;
  1311. transformResult: TransformResult | null;
  1312. ssrTransformResult: TransformResult | null;
  1313. ssrModule: Record<string, any> | null;
  1314. lastHMRTimestamp: number;
  1315. constructor(url: string);
  1316. }
  1317. export declare function normalizePath(id: string): string;
  1318. export declare function optimizeDeps(config: ResolvedConfig, force?: boolean | undefined, asCommand?: boolean, newDeps?: Record<string, string>): Promise<DepOptimizationMetadata | null>;
  1319. export declare interface PackageData {
  1320. dir: string;
  1321. hasSideEffects: (id: string) => boolean;
  1322. resolvedImports: Record<string, string | undefined>;
  1323. data: {
  1324. [field: string]: any;
  1325. version: string;
  1326. main: string;
  1327. module: string;
  1328. browser: string | Record<string, string | false>;
  1329. exports: string | Record<string, any> | string[];
  1330. dependencies: Record<string, string>;
  1331. };
  1332. }
  1333. /**
  1334. * Vite plugins extends the Rollup plugin interface with a few extra
  1335. * vite-specific options. A valid vite plugin is also a valid Rollup plugin.
  1336. * On the contrary, a Rollup plugin may or may NOT be a valid vite universal
  1337. * plugin, since some Rollup features do not make sense in an unbundled
  1338. * dev server context. That said, as long as a rollup plugin doesn't have strong
  1339. * coupling between its bundle phase and output phase hooks then it should
  1340. * just work (that means, most of them).
  1341. *
  1342. * By default, the plugins are run during both serve and build. When a plugin
  1343. * is applied during serve, it will only run **non output plugin hooks** (see
  1344. * rollup type definition of {@link rollup#PluginHooks}). You can think of the
  1345. * dev server as only running `const bundle = rollup.rollup()` but never calling
  1346. * `bundle.generate()`.
  1347. *
  1348. * A plugin that expects to have different behavior depending on serve/build can
  1349. * export a factory function that receives the command being run via options.
  1350. *
  1351. * If a plugin should be applied only for server or build, a function format
  1352. * config file can be used to conditional determine the plugins to use.
  1353. */
  1354. export declare interface Plugin extends Plugin_2 {
  1355. /**
  1356. * Enforce plugin invocation tier similar to webpack loaders.
  1357. *
  1358. * Plugin invocation order:
  1359. * - alias resolution
  1360. * - `enforce: 'pre'` plugins
  1361. * - vite core plugins
  1362. * - normal plugins
  1363. * - vite build plugins
  1364. * - `enforce: 'post'` plugins
  1365. * - vite build post plugins
  1366. */
  1367. enforce?: 'pre' | 'post';
  1368. /**
  1369. * Apply the plugin only for serve or for build.
  1370. */
  1371. apply?: 'serve' | 'build';
  1372. /**
  1373. * Modify vite config before it's resolved. The hook can either mutate the
  1374. * passed-in config directly, or return a partial config object that will be
  1375. * deeply merged into existing config.
  1376. *
  1377. * Note: User plugins are resolved before running this hook so injecting other
  1378. * plugins inside the `config` hook will have no effect.
  1379. */
  1380. config?: (config: UserConfig, env: ConfigEnv) => UserConfig | null | void;
  1381. /**
  1382. * Use this hook to read and store the final resolved vite config.
  1383. */
  1384. configResolved?: (config: ResolvedConfig) => void;
  1385. /**
  1386. * Configure the vite server. The hook receives the {@link ViteDevServer}
  1387. * instance. This can also be used to store a reference to the server
  1388. * for use in other hooks.
  1389. *
  1390. * The hooks will be called before internal middlewares are applied. A hook
  1391. * can return a post hook that will be called after internal middlewares
  1392. * are applied. Hook can be async functions and will be called in series.
  1393. */
  1394. configureServer?: ServerHook;
  1395. /**
  1396. * Transform index.html.
  1397. * The hook receives the following arguments:
  1398. *
  1399. * - html: string
  1400. * - ctx?: vite.ServerContext (only present during serve)
  1401. * - bundle?: rollup.OutputBundle (only present during build)
  1402. *
  1403. * It can either return a transformed string, or a list of html tag
  1404. * descriptors that will be injected into the <head> or <body>.
  1405. *
  1406. * By default the transform is applied **after** vite's internal html
  1407. * transform. If you need to apply the transform before vite, use an object:
  1408. * `{ enforce: 'pre', transform: hook }`
  1409. */
  1410. transformIndexHtml?: IndexHtmlTransform;
  1411. /**
  1412. * Perform custom handling of HMR updates.
  1413. * The handler receives a context containing changed filename, timestamp, a
  1414. * list of modules affected by the file change, and the dev server instance.
  1415. *
  1416. * - The hook can return a filtered list of modules to narrow down the update.
  1417. * e.g. for a Vue SFC, we can narrow down the part to update by comparing
  1418. * the descriptors.
  1419. *
  1420. * - The hook can also return an empty array and then perform custom updates
  1421. * by sending a custom hmr payload via server.ws.send().
  1422. *
  1423. * - If the hook doesn't return a value, the hmr update will be performed as
  1424. * normal.
  1425. */
  1426. handleHotUpdate?(ctx: HmrContext): Array<ModuleNode> | void | Promise<Array<ModuleNode> | void>;
  1427. /**
  1428. * extend hooks with ssr flag
  1429. */
  1430. resolveId?(this: PluginContext, source: string, importer: string | undefined, options: {
  1431. custom?: CustomPluginOptions;
  1432. }, ssr?: boolean): Promise<ResolveIdResult> | ResolveIdResult;
  1433. load?(this: PluginContext, id: string, ssr?: boolean): Promise<LoadResult> | LoadResult;
  1434. transform?(this: TransformPluginContext, code: string, id: string, ssr?: boolean): Promise<TransformResult_2> | TransformResult_2;
  1435. }
  1436. export declare interface PluginContainer {
  1437. options: InputOptions;
  1438. buildStart(options: InputOptions): Promise<void>;
  1439. watchChange(id: string, event?: ChangeEvent): void;
  1440. resolveId(id: string, importer?: string, skip?: Set<Plugin>, ssr?: boolean): Promise<PartialResolvedId | null>;
  1441. transform(code: string, id: string, inMap?: SourceDescription['map'], ssr?: boolean): Promise<SourceDescription | null>;
  1442. load(id: string, ssr?: boolean): Promise<LoadResult | null>;
  1443. close(): Promise<void>;
  1444. }
  1445. export declare interface ProxyOptions extends HttpProxy.ServerOptions {
  1446. /**
  1447. * rewrite path
  1448. */
  1449. rewrite?: (path: string) => string;
  1450. /**
  1451. * configure the proxy server (e.g. listen to events)
  1452. */
  1453. configure?: (proxy: HttpProxy.Server, options: ProxyOptions) => void;
  1454. /**
  1455. * webpack-dev-server style bypass function
  1456. */
  1457. bypass?: (req: http.IncomingMessage, res: http.ServerResponse, options: ProxyOptions) => void | null | undefined | false | string;
  1458. }
  1459. export declare interface PrunePayload {
  1460. type: 'prune'
  1461. paths: string[]
  1462. }
  1463. export declare function resolveConfig(inlineConfig: InlineConfig, command: 'build' | 'serve', defaultMode?: string): Promise<ResolvedConfig>;
  1464. export declare type ResolvedBuildOptions = Required<Omit<BuildOptions, 'base'>>;
  1465. export declare type ResolvedConfig = Readonly<Omit<UserConfig, 'plugins' | 'alias' | 'dedupe' | 'assetsInclude'> & {
  1466. configFile: string | undefined;
  1467. inlineConfig: UserConfig;
  1468. root: string;
  1469. base: string;
  1470. publicDir: string;
  1471. command: 'build' | 'serve';
  1472. mode: string;
  1473. isProduction: boolean;
  1474. optimizeCacheDir: string | undefined;
  1475. env: Record<string, any>;
  1476. resolve: ResolveOptions & {
  1477. alias: Alias[];
  1478. };
  1479. plugins: readonly Plugin[];
  1480. server: ServerOptions;
  1481. build: ResolvedBuildOptions;
  1482. assetsInclude: (file: string) => boolean;
  1483. logger: Logger;
  1484. createResolver: (options?: Partial<InternalResolveOptions>) => ResolveFn;
  1485. }>;
  1486. export declare type ResolveFn = (id: string, importer?: string, aliasOnly?: boolean) => Promise<string | undefined>;
  1487. export declare interface ResolveOptions {
  1488. mainFields?: string[];
  1489. conditions?: string[];
  1490. extensions?: string[];
  1491. dedupe?: string[];
  1492. }
  1493. export declare function resolvePackageData(id: string, basedir: string): PackageData | undefined;
  1494. export declare function resolvePackageEntry(id: string, { resolvedImports, dir, data }: PackageData, options: InternalResolveOptions): string | undefined;
  1495. export declare type ResolverFunction = PluginHooks['resolveId']
  1496. export declare interface ResolverObject {
  1497. buildStart?: PluginHooks['buildStart']
  1498. resolveId: ResolverFunction
  1499. }
  1500. /**
  1501. * https://github.com/rollup/plugins/blob/master/packages/commonjs/types/index.d.ts
  1502. *
  1503. * This source code is licensed under the MIT license found in the
  1504. * LICENSE file at
  1505. * https://github.com/rollup/plugins/blob/master/LICENSE
  1506. */
  1507. export declare interface RollupCommonJSOptions {
  1508. /**
  1509. * A minimatch pattern, or array of patterns, which specifies the files in
  1510. * the build the plugin should operate on. By default, all files with
  1511. * extension `".cjs"` or those in `extensions` are included, but you can narrow
  1512. * this list by only including specific files. These files will be analyzed
  1513. * and transpiled if either the analysis does not find ES module specific
  1514. * statements or `transformMixedEsModules` is `true`.
  1515. * @default undefined
  1516. */
  1517. include?: string | RegExp | readonly (string | RegExp)[]
  1518. /**
  1519. * A minimatch pattern, or array of patterns, which specifies the files in
  1520. * the build the plugin should _ignore_. By default, all files with
  1521. * extensions other than those in `extensions` or `".cjs"` are ignored, but you
  1522. * can exclude additional files. See also the `include` option.
  1523. * @default undefined
  1524. */
  1525. exclude?: string | RegExp | readonly (string | RegExp)[]
  1526. /**
  1527. * For extensionless imports, search for extensions other than .js in the
  1528. * order specified. Note that you need to make sure that non-JavaScript files
  1529. * are transpiled by another plugin first.
  1530. * @default [ '.js' ]
  1531. */
  1532. extensions?: ReadonlyArray<string>
  1533. /**
  1534. * If true then uses of `global` won't be dealt with by this plugin
  1535. * @default false
  1536. */
  1537. ignoreGlobal?: boolean
  1538. /**
  1539. * If false, skips source map generation for CommonJS modules. This will improve performance.
  1540. * @default true
  1541. */
  1542. sourceMap?: boolean
  1543. /**
  1544. * Instructs the plugin whether to enable mixed module transformations. This
  1545. * is useful in scenarios with modules that contain a mix of ES `import`
  1546. * statements and CommonJS `require` expressions. Set to `true` if `require`
  1547. * calls should be transformed to imports in mixed modules, or `false` if the
  1548. * `require` expressions should survive the transformation. The latter can be
  1549. * important if the code contains environment detection, or you are coding
  1550. * for an environment with special treatment for `require` calls such as
  1551. * ElectronJS. See also the `ignore` option.
  1552. * @default false
  1553. */
  1554. transformMixedEsModules?: boolean
  1555. /**
  1556. * Sometimes you have to leave require statements unconverted. Pass an array
  1557. * containing the IDs or a `id => boolean` function.
  1558. * @default []
  1559. */
  1560. ignore?: ReadonlyArray<string> | ((id: string) => boolean)
  1561. /**
  1562. * Controls how to render imports from external dependencies. By default,
  1563. * this plugin assumes that all external dependencies are CommonJS. This
  1564. * means they are rendered as default imports to be compatible with e.g.
  1565. * NodeJS where ES modules can only import a default export from a CommonJS
  1566. * dependency.
  1567. *
  1568. * If you set `esmExternals` to `true`, this plugins assumes that all
  1569. * external dependencies are ES modules and respect the
  1570. * `requireReturnsDefault` option. If that option is not set, they will be
  1571. * rendered as namespace imports.
  1572. *
  1573. * You can also supply an array of ids to be treated as ES modules, or a
  1574. * function that will be passed each external id to determine if it is an ES
  1575. * module.
  1576. * @default false
  1577. */
  1578. esmExternals?: boolean | ReadonlyArray<string> | ((id: string) => boolean)
  1579. /**
  1580. * Controls what is returned when requiring an ES module from a CommonJS file.
  1581. * When using the `esmExternals` option, this will also apply to external
  1582. * modules. By default, this plugin will render those imports as namespace
  1583. * imports i.e.
  1584. *
  1585. * ```js
  1586. * // input
  1587. * const foo = require('foo');
  1588. *
  1589. * // output
  1590. * import * as foo from 'foo';
  1591. * ```
  1592. *
  1593. * However there are some situations where this may not be desired.
  1594. * For these situations, you can change Rollup's behaviour either globally or
  1595. * per module. To change it globally, set the `requireReturnsDefault` option
  1596. * to one of the following values:
  1597. *
  1598. * - `false`: This is the default, requiring an ES module returns its
  1599. * namespace. This is the only option that will also add a marker
  1600. * `__esModule: true` to the namespace to support interop patterns in
  1601. * CommonJS modules that are transpiled ES modules.
  1602. * - `"namespace"`: Like `false`, requiring an ES module returns its
  1603. * namespace, but the plugin does not add the `__esModule` marker and thus
  1604. * creates more efficient code. For external dependencies when using
  1605. * `esmExternals: true`, no additional interop code is generated.
  1606. * - `"auto"`: This is complementary to how `output.exports: "auto"` works in
  1607. * Rollup: If a module has a default export and no named exports, requiring
  1608. * that module returns the default export. In all other cases, the namespace
  1609. * is returned. For external dependencies when using `esmExternals: true`, a
  1610. * corresponding interop helper is added.
  1611. * - `"preferred"`: If a module has a default export, requiring that module
  1612. * always returns the default export, no matter whether additional named
  1613. * exports exist. This is similar to how previous versions of this plugin
  1614. * worked. Again for external dependencies when using `esmExternals: true`,
  1615. * an interop helper is added.
  1616. * - `true`: This will always try to return the default export on require
  1617. * without checking if it actually exists. This can throw at build time if
  1618. * there is no default export. This is how external dependencies are handled
  1619. * when `esmExternals` is not used. The advantage over the other options is
  1620. * that, like `false`, this does not add an interop helper for external
  1621. * dependencies, keeping the code lean.
  1622. *
  1623. * To change this for individual modules, you can supply a function for
  1624. * `requireReturnsDefault` instead. This function will then be called once for
  1625. * each required ES module or external dependency with the corresponding id
  1626. * and allows you to return different values for different modules.
  1627. * @default false
  1628. */
  1629. requireReturnsDefault?:
  1630. | boolean
  1631. | 'auto'
  1632. | 'preferred'
  1633. | 'namespace'
  1634. | ((id: string) => boolean | 'auto' | 'preferred' | 'namespace')
  1635. /**
  1636. * Some modules contain dynamic `require` calls, or require modules that
  1637. * contain circular dependencies, which are not handled well by static
  1638. * imports. Including those modules as `dynamicRequireTargets` will simulate a
  1639. * CommonJS (NodeJS-like) environment for them with support for dynamic and
  1640. * circular dependencies.
  1641. *
  1642. * Note: In extreme cases, this feature may result in some paths being
  1643. * rendered as absolute in the final bundle. The plugin tries to avoid
  1644. * exposing paths from the local machine, but if you are `dynamicRequirePaths`
  1645. * with paths that are far away from your project's folder, that may require
  1646. * replacing strings like `"/Users/John/Desktop/foo-project/"` -\> `"/"`.
  1647. */
  1648. dynamicRequireTargets?: string | ReadonlyArray<string>
  1649. }
  1650. export declare function send(req: IncomingMessage, res: ServerResponse, content: string | Buffer, type: string, etag?: string, cacheControl?: string, map?: SourceMap | null): void;
  1651. export declare type ServerHook = (server: ViteDevServer) => (() => void) | void | Promise<(() => void) | void>;
  1652. export declare interface ServerOptions {
  1653. host?: string;
  1654. port?: number;
  1655. /**
  1656. * Enable TLS + HTTP/2.
  1657. * Note: this downgrades to TLS only when the proxy option is also used.
  1658. */
  1659. https?: boolean | https.ServerOptions;
  1660. /**
  1661. * Open browser window on startup
  1662. */
  1663. open?: boolean | string;
  1664. /**
  1665. * Force dep pre-optimization regardless of whether deps have changed.
  1666. */
  1667. force?: boolean;
  1668. /**
  1669. * Configure HMR-specific options (port, host, path & protocol)
  1670. */
  1671. hmr?: HmrOptions | boolean;
  1672. /**
  1673. * chokidar watch options
  1674. * https://github.com/paulmillr/chokidar#api
  1675. */
  1676. watch?: WatchOptions;
  1677. /**
  1678. * Configure custom proxy rules for the dev server. Expects an object
  1679. * of `{ key: options }` pairs.
  1680. * Uses [`http-proxy`](https://github.com/http-party/node-http-proxy).
  1681. * Full options [here](https://github.com/http-party/node-http-proxy#options).
  1682. *
  1683. * Example `vite.config.js`:
  1684. * ``` js
  1685. * module.exports = {
  1686. * proxy: {
  1687. * // string shorthand
  1688. * '/foo': 'http://localhost:4567/foo',
  1689. * // with options
  1690. * '/api': {
  1691. * target: 'http://jsonplaceholder.typicode.com',
  1692. * changeOrigin: true,
  1693. * rewrite: path => path.replace(/^\/api/, '')
  1694. * }
  1695. * }
  1696. * }
  1697. * ```
  1698. */
  1699. proxy?: Record<string, string | ProxyOptions>;
  1700. /**
  1701. * Configure CORS for the dev server.
  1702. * Uses https://github.com/expressjs/cors.
  1703. * Set to `true` to allow all methods from any origin, or configure separately
  1704. * using an object.
  1705. */
  1706. cors?: CorsOptions | boolean;
  1707. /**
  1708. * If enabled, vite will exit if specified port is already in use
  1709. */
  1710. strictPort?: boolean;
  1711. /**
  1712. * Create Vite dev server to be used as a middleware in an existing server
  1713. */
  1714. middlewareMode?: boolean;
  1715. /**
  1716. * Prepend this folder to http requests, for use when proxying vite as a subfolder
  1717. * Should start and end with the `/` character
  1718. */
  1719. base?: string;
  1720. }
  1721. export declare function sortUserPlugins(plugins: (Plugin | Plugin[])[] | undefined): [Plugin[], Plugin[], Plugin[]];
  1722. export declare interface SSROptions {
  1723. external?: string[];
  1724. noExternal?: string[];
  1725. }
  1726. export declare namespace Terser {
  1727. export type ECMA = 5 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020
  1728. export interface ParseOptions {
  1729. bare_returns?: boolean
  1730. ecma?: ECMA
  1731. html5_comments?: boolean
  1732. shebang?: boolean
  1733. }
  1734. export interface CompressOptions {
  1735. arguments?: boolean
  1736. arrows?: boolean
  1737. booleans_as_integers?: boolean
  1738. booleans?: boolean
  1739. collapse_vars?: boolean
  1740. comparisons?: boolean
  1741. computed_props?: boolean
  1742. conditionals?: boolean
  1743. dead_code?: boolean
  1744. defaults?: boolean
  1745. directives?: boolean
  1746. drop_console?: boolean
  1747. drop_debugger?: boolean
  1748. ecma?: ECMA
  1749. evaluate?: boolean
  1750. expression?: boolean
  1751. global_defs?: object
  1752. hoist_funs?: boolean
  1753. hoist_props?: boolean
  1754. hoist_vars?: boolean
  1755. ie8?: boolean
  1756. if_return?: boolean
  1757. inline?: boolean | InlineFunctions
  1758. join_vars?: boolean
  1759. keep_classnames?: boolean | RegExp
  1760. keep_fargs?: boolean
  1761. keep_fnames?: boolean | RegExp
  1762. keep_infinity?: boolean
  1763. loops?: boolean
  1764. module?: boolean
  1765. negate_iife?: boolean
  1766. passes?: number
  1767. properties?: boolean
  1768. pure_funcs?: string[]
  1769. pure_getters?: boolean | 'strict'
  1770. reduce_funcs?: boolean
  1771. reduce_vars?: boolean
  1772. sequences?: boolean | number
  1773. side_effects?: boolean
  1774. switches?: boolean
  1775. toplevel?: boolean
  1776. top_retain?: null | string | string[] | RegExp
  1777. typeofs?: boolean
  1778. unsafe_arrows?: boolean
  1779. unsafe?: boolean
  1780. unsafe_comps?: boolean
  1781. unsafe_Function?: boolean
  1782. unsafe_math?: boolean
  1783. unsafe_symbols?: boolean
  1784. unsafe_methods?: boolean
  1785. unsafe_proto?: boolean
  1786. unsafe_regexp?: boolean
  1787. unsafe_undefined?: boolean
  1788. unused?: boolean
  1789. }
  1790. export enum InlineFunctions {
  1791. Disabled = 0,
  1792. SimpleFunctions = 1,
  1793. WithArguments = 2,
  1794. WithArgumentsAndVariables = 3
  1795. }
  1796. export interface MangleOptions {
  1797. eval?: boolean
  1798. keep_classnames?: boolean | RegExp
  1799. keep_fnames?: boolean | RegExp
  1800. module?: boolean
  1801. properties?: boolean | ManglePropertiesOptions
  1802. reserved?: string[]
  1803. safari10?: boolean
  1804. toplevel?: boolean
  1805. }
  1806. export interface ManglePropertiesOptions {
  1807. builtins?: boolean
  1808. debug?: boolean
  1809. keep_quoted?: boolean | 'strict'
  1810. regex?: RegExp | string
  1811. reserved?: string[]
  1812. }
  1813. export interface FormatOptions {
  1814. ascii_only?: boolean
  1815. beautify?: boolean
  1816. braces?: boolean
  1817. comments?:
  1818. | boolean
  1819. | 'all'
  1820. | 'some'
  1821. | RegExp
  1822. | ((
  1823. node: any,
  1824. comment: {
  1825. value: string
  1826. type: 'comment1' | 'comment2' | 'comment3' | 'comment4'
  1827. pos: number
  1828. line: number
  1829. col: number
  1830. }
  1831. ) => boolean)
  1832. ecma?: ECMA
  1833. ie8?: boolean
  1834. indent_level?: number
  1835. indent_start?: number
  1836. inline_script?: boolean
  1837. keep_quoted_props?: boolean
  1838. max_line_len?: number | false
  1839. preamble?: string
  1840. preserve_annotations?: boolean
  1841. quote_keys?: boolean
  1842. quote_style?: OutputQuoteStyle
  1843. safari10?: boolean
  1844. semicolons?: boolean
  1845. shebang?: boolean
  1846. shorthand?: boolean
  1847. source_map?: SourceMapOptions
  1848. webkit?: boolean
  1849. width?: number
  1850. wrap_iife?: boolean
  1851. wrap_func_args?: boolean
  1852. }
  1853. export enum OutputQuoteStyle {
  1854. PreferDouble = 0,
  1855. AlwaysSingle = 1,
  1856. AlwaysDouble = 2,
  1857. AlwaysOriginal = 3
  1858. }
  1859. export interface MinifyOptions {
  1860. compress?: boolean | CompressOptions
  1861. ecma?: ECMA
  1862. ie8?: boolean
  1863. keep_classnames?: boolean | RegExp
  1864. keep_fnames?: boolean | RegExp
  1865. mangle?: boolean | MangleOptions
  1866. module?: boolean
  1867. nameCache?: object
  1868. format?: FormatOptions
  1869. /** @deprecated use format instead */
  1870. output?: FormatOptions
  1871. parse?: ParseOptions
  1872. safari10?: boolean
  1873. sourceMap?: boolean | SourceMapOptions
  1874. toplevel?: boolean
  1875. }
  1876. export interface MinifyOutput {
  1877. code?: string
  1878. map?: object | string
  1879. }
  1880. export interface SourceMapOptions {
  1881. /** Source map object, 'inline' or source map file content */
  1882. content?: object | string
  1883. includeSources?: boolean
  1884. filename?: string
  1885. root?: string
  1886. url?: string | 'inline'
  1887. }
  1888. }
  1889. export declare interface TransformOptions {
  1890. ssr?: boolean;
  1891. html?: boolean;
  1892. }
  1893. export declare interface TransformResult {
  1894. code: string;
  1895. map: SourceMap | null;
  1896. etag?: string;
  1897. deps?: string[];
  1898. }
  1899. export declare interface Update {
  1900. type: 'js-update' | 'css-update'
  1901. path: string
  1902. acceptedPath: string
  1903. timestamp: number
  1904. }
  1905. export declare interface UpdatePayload {
  1906. type: 'update'
  1907. updates: Update[]
  1908. }
  1909. export declare interface UserConfig {
  1910. /**
  1911. * Project root directory. Can be an absolute path, or a path relative from
  1912. * the location of the config file itself.
  1913. * @default process.cwd()
  1914. */
  1915. root?: string;
  1916. /**
  1917. * Base public path when served in development or production.
  1918. * @default '/'
  1919. */
  1920. base?: string;
  1921. /**
  1922. * Directory to serve as plain static assets. Files in this directory are
  1923. * served and copied to build dist dir as-is without transform. The value
  1924. * can be either an absolute file system path or a path relative to <root>.
  1925. * @default 'public'
  1926. */
  1927. publicDir?: string;
  1928. /**
  1929. * Explicitly set a mode to run in. This will override the default mode for
  1930. * each command, and can be overridden by the command line --mode option.
  1931. */
  1932. mode?: string;
  1933. /**
  1934. * Define global variable replacements.
  1935. * Entries will be defined on `window` during dev and replaced during build.
  1936. */
  1937. define?: Record<string, any>;
  1938. /**
  1939. * Array of vite plugins to use.
  1940. */
  1941. plugins?: (Plugin | Plugin[])[];
  1942. /**
  1943. * Configure resolver
  1944. */
  1945. resolve?: ResolveOptions & {
  1946. alias?: AliasOptions;
  1947. };
  1948. /**
  1949. * CSS related options (preprocessors and CSS modules)
  1950. */
  1951. css?: CSSOptions;
  1952. /**
  1953. * JSON loading options
  1954. */
  1955. json?: JsonOptions;
  1956. /**
  1957. * Transform options to pass to esbuild.
  1958. * Or set to `false` to disable esbuild.
  1959. */
  1960. esbuild?: ESBuildOptions | false;
  1961. /**
  1962. * Specify additional files to be treated as static assets.
  1963. */
  1964. assetsInclude?: string | RegExp | (string | RegExp)[];
  1965. /**
  1966. * Server specific options, e.g. host, port, https...
  1967. */
  1968. server?: ServerOptions;
  1969. /**
  1970. * Build specific options
  1971. */
  1972. build?: BuildOptions;
  1973. /**
  1974. * Dep optimization options
  1975. */
  1976. optimizeDeps?: DepOptimizationOptions;
  1977. /* Excluded from this release type: ssr */
  1978. /**
  1979. * Log level.
  1980. * Default: 'info'
  1981. */
  1982. logLevel?: LogLevel;
  1983. /**
  1984. * Default: true
  1985. */
  1986. clearScreen?: boolean;
  1987. /**
  1988. * Import aliases
  1989. * @deprecated use `resolve.alias` instead
  1990. */
  1991. alias?: AliasOptions;
  1992. /**
  1993. * Force Vite to always resolve listed dependencies to the same copy (from
  1994. * project root).
  1995. * @deprecated use `resolve.dedupe` instead
  1996. */
  1997. dedupe?: string[];
  1998. }
  1999. export declare type UserConfigExport = UserConfig | UserConfigFn;
  2000. export declare type UserConfigFn = (env: ConfigEnv) => UserConfig;
  2001. export declare interface ViteDevServer {
  2002. /**
  2003. * The resolved vite config object
  2004. */
  2005. config: ResolvedConfig;
  2006. /**
  2007. * A connect app instance.
  2008. * - Can be used to attach custom middlewares to the dev server.
  2009. * - Can also be used as the handler function of a custom http server
  2010. * or as a middleware in any connect-style Node.js frameworks
  2011. *
  2012. * https://github.com/senchalabs/connect#use-middleware
  2013. */
  2014. middlewares: Connect.Server;
  2015. /**
  2016. * @deprecated use `server.middlewares` instead
  2017. */
  2018. app: Connect.Server;
  2019. /**
  2020. * native Node http server instance
  2021. * will be null in middleware mode
  2022. */
  2023. httpServer: http.Server | null;
  2024. /**
  2025. * chokidar watcher instance
  2026. * https://github.com/paulmillr/chokidar#api
  2027. */
  2028. watcher: FSWatcher;
  2029. /**
  2030. * web socket server with `send(payload)` method
  2031. */
  2032. ws: WebSocketServer;
  2033. /**
  2034. * Rollup plugin container that can run plugin hooks on a given file
  2035. */
  2036. pluginContainer: PluginContainer;
  2037. /**
  2038. * Module graph that tracks the import relationships, url to file mapping
  2039. * and hmr state.
  2040. */
  2041. moduleGraph: ModuleGraph;
  2042. /**
  2043. * Programmatically resolve, load and transform a URL and get the result
  2044. * without going through the http request pipeline.
  2045. */
  2046. transformRequest(url: string, options?: TransformOptions): Promise<TransformResult_2 | null>;
  2047. /**
  2048. * Apply vite built-in HTML transforms and any plugin HTML transforms.
  2049. */
  2050. transformIndexHtml(url: string, html: string): Promise<string>;
  2051. /**
  2052. * Util for transforming a file with esbuild.
  2053. * Can be useful for certain plugins.
  2054. */
  2055. transformWithEsbuild(code: string, filename: string, options?: TransformOptions_2, inMap?: object): Promise<ESBuildTransformResult>;
  2056. /**
  2057. * Load a given URL as an instantiated module for SSR.
  2058. */
  2059. ssrLoadModule(url: string): Promise<Record<string, any>>;
  2060. /**
  2061. * Fix ssr error stacktrace
  2062. */
  2063. ssrFixStacktrace(e: Error): void;
  2064. /**
  2065. * Start the server.
  2066. */
  2067. listen(port?: number, isRestart?: boolean): Promise<ViteDevServer>;
  2068. /**
  2069. * Stop the server.
  2070. */
  2071. close(): Promise<void>;
  2072. /* Excluded from this release type: _optimizeDepsMetadata */
  2073. /* Excluded from this release type: _ssrExternals */
  2074. /* Excluded from this release type: _globImporters */
  2075. /* Excluded from this release type: _isRunningOptimizer */
  2076. /* Excluded from this release type: _registerMissingImport */
  2077. /* Excluded from this release type: _pendingReload */
  2078. }
  2079. export declare interface WatchOptions {
  2080. /**
  2081. * Indicates whether the process should continue to run as long as files are being watched. If
  2082. * set to `false` when using `fsevents` to watch, no more events will be emitted after `ready`,
  2083. * even if the process continues to run.
  2084. */
  2085. persistent?: boolean
  2086. /**
  2087. * ([anymatch](https://github.com/micromatch/anymatch)-compatible definition) Defines files/paths to
  2088. * be ignored. The whole relative or absolute path is tested, not just filename. If a function
  2089. * with two arguments is provided, it gets called twice per path - once with a single argument
  2090. * (the path), second time with two arguments (the path and the
  2091. * [`fs.Stats`](https://nodejs.org/api/fs.html#fs_class_fs_stats) object of that path).
  2092. */
  2093. ignored?: any
  2094. /**
  2095. * If set to `false` then `add`/`addDir` events are also emitted for matching paths while
  2096. * instantiating the watching as chokidar discovers these file paths (before the `ready` event).
  2097. */
  2098. ignoreInitial?: boolean
  2099. /**
  2100. * When `false`, only the symlinks themselves will be watched for changes instead of following
  2101. * the link references and bubbling events through the link's path.
  2102. */
  2103. followSymlinks?: boolean
  2104. /**
  2105. * The base directory from which watch `paths` are to be derived. Paths emitted with events will
  2106. * be relative to this.
  2107. */
  2108. cwd?: string
  2109. /**
  2110. * If set to true then the strings passed to .watch() and .add() are treated as literal path
  2111. * names, even if they look like globs. Default: false.
  2112. */
  2113. disableGlobbing?: boolean
  2114. /**
  2115. * Whether to use fs.watchFile (backed by polling), or fs.watch. If polling leads to high CPU
  2116. * utilization, consider setting this to `false`. It is typically necessary to **set this to
  2117. * `true` to successfully watch files over a network**, and it may be necessary to successfully
  2118. * watch files in other non-standard situations. Setting to `true` explicitly on OS X overrides
  2119. * the `useFsEvents` default.
  2120. */
  2121. usePolling?: boolean
  2122. /**
  2123. * Whether to use the `fsevents` watching interface if available. When set to `true` explicitly
  2124. * and `fsevents` is available this supersedes the `usePolling` setting. When set to `false` on
  2125. * OS X, `usePolling: true` becomes the default.
  2126. */
  2127. useFsEvents?: boolean
  2128. /**
  2129. * If relying upon the [`fs.Stats`](https://nodejs.org/api/fs.html#fs_class_fs_stats) object that
  2130. * may get passed with `add`, `addDir`, and `change` events, set this to `true` to ensure it is
  2131. * provided even in cases where it wasn't already available from the underlying watch events.
  2132. */
  2133. alwaysStat?: boolean
  2134. /**
  2135. * If set, limits how many levels of subdirectories will be traversed.
  2136. */
  2137. depth?: number
  2138. /**
  2139. * Interval of file system polling.
  2140. */
  2141. interval?: number
  2142. /**
  2143. * Interval of file system polling for binary files. ([see list of binary extensions](https://gi
  2144. * thub.com/sindresorhus/binary-extensions/blob/master/binary-extensions.json))
  2145. */
  2146. binaryInterval?: number
  2147. /**
  2148. * Indicates whether to watch files that don't have read permissions if possible. If watching
  2149. * fails due to `EPERM` or `EACCES` with this set to `true`, the errors will be suppressed
  2150. * silently.
  2151. */
  2152. ignorePermissionErrors?: boolean
  2153. /**
  2154. * `true` if `useFsEvents` and `usePolling` are `false`). Automatically filters out artifacts
  2155. * that occur when using editors that use "atomic writes" instead of writing directly to the
  2156. * source file. If a file is re-added within 100 ms of being deleted, Chokidar emits a `change`
  2157. * event rather than `unlink` then `add`. If the default of 100 ms does not work well for you,
  2158. * you can override it by setting `atomic` to a custom value, in milliseconds.
  2159. */
  2160. atomic?: boolean | number
  2161. /**
  2162. * can be set to an object in order to adjust timing params:
  2163. */
  2164. awaitWriteFinish?:
  2165. | {
  2166. /**
  2167. * Amount of time in milliseconds for a file size to remain constant before emitting its event.
  2168. */
  2169. stabilityThreshold?: number
  2170. /**
  2171. * File size polling interval.
  2172. */
  2173. pollInterval?: number
  2174. }
  2175. | boolean
  2176. }
  2177. export declare interface WebSocketServer {
  2178. send(payload: HMRPayload): void;
  2179. close(): Promise<void>;
  2180. }
  2181. export { }