index.d.ts 69 KB

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