vite 6.0.0-alpha.9 → 6.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { PluginHooks, RollupError, InputOptions, CustomPluginOptions, PartialResolvedId, SourceDescription, SourceMap, LoadResult, ModuleInfo, RollupOptions, WatcherOptions, InputOption, ModuleFormat, RollupOutput, RollupWatcher, SourceMapInput, ExistingRawSourceMap, OutputBundle, OutputChunk, ObjectHook, ResolveIdResult, GetManualChunk } from 'rollup';
2
+ import { PluginHooks, RollupError, SourceMap, ModuleInfo, PartialResolvedId, RollupOptions, WatcherOptions, InputOption, ModuleFormat, RollupOutput, RollupWatcher, MinimalPluginContext, InputOptions, CustomPluginOptions, LoadResult, SourceDescription, SourceMapInput, ExistingRawSourceMap, OutputBundle, OutputChunk, ObjectHook, ResolveIdResult, GetManualChunk } from 'rollup';
3
3
  import * as rollup from 'rollup';
4
4
  export { rollup as Rollup };
5
5
  export { parseAst, parseAstAsync } from 'rollup/parseAst';
@@ -15,16 +15,16 @@ import * as url from 'node:url';
15
15
  import { URL } from 'node:url';
16
16
  import * as stream from 'node:stream';
17
17
  import { Duplex, DuplexOptions } from 'node:stream';
18
- import { SecureContextOptions } from 'node:tls';
19
- import { ZlibOptions } from 'node:zlib';
20
- import { HMRPayload, CustomPayload } from '../../types/hmrPayload.js';
21
- export { ConnectedPayload, CustomPayload, ErrorPayload, FullReloadPayload, HMRPayload, PrunePayload, Update, UpdatePayload } from '../../types/hmrPayload.js';
22
- import { InferCustomEventPayload } from '../../types/customEvent.js';
23
- export { CustomEventMap, InferCustomEventPayload, InvalidatePayload } from '../../types/customEvent.js';
24
- import { FetchResult, ModuleRunnerOptions, ModuleRunnerHMRConnection, ModuleRunnerHmr, ModuleEvaluator, ModuleRunner } from 'vite/module-runner';
18
+ import { FetchResult, FetchFunctionOptions, ModuleRunnerOptions, ModuleRunnerHMRConnection, ModuleRunnerHmr, ModuleEvaluator, ModuleRunner } from 'vite/module-runner';
25
19
  export { FetchFunction, FetchResult } from 'vite/module-runner';
26
20
  import { BuildOptions as esbuild_BuildOptions, TransformOptions as esbuild_TransformOptions, TransformResult as esbuild_TransformResult } from 'esbuild';
27
21
  export { TransformOptions as EsbuildTransformOptions, version as esbuildVersion } from 'esbuild';
22
+ import { HotPayload, CustomPayload } from '../../types/hmrPayload.js';
23
+ export { ConnectedPayload, CustomPayload, ErrorPayload, FullReloadPayload, HMRPayload, HotPayload, PrunePayload, Update, UpdatePayload } from '../../types/hmrPayload.js';
24
+ import { InferCustomEventPayload } from '../../types/customEvent.js';
25
+ export { CustomEventMap, InferCustomEventPayload, InvalidatePayload } from '../../types/customEvent.js';
26
+ import { SecureContextOptions } from 'node:tls';
27
+ import { ZlibOptions } from 'node:zlib';
28
28
  import * as PostCSS from 'postcss';
29
29
  export { GeneralImportGlobOptions, ImportGlobFunction, ImportGlobOptions, KnownAsTypeMap } from '../../types/importGlob.js';
30
30
  export { ChunkMetadata } from '../../types/metadata.js';
@@ -412,6 +412,7 @@ declare namespace HttpProxy {
412
412
  * @param req - Client request.
413
413
  * @param res - Client response.
414
414
  * @param options - Additional options.
415
+ * @param callback - Error callback.
415
416
  */
416
417
  web(
417
418
  req: http.IncomingMessage,
@@ -426,6 +427,7 @@ declare namespace HttpProxy {
426
427
  * @param socket - Client socket.
427
428
  * @param head - Client head.
428
429
  * @param options - Additional options.
430
+ * @param callback - Error callback.
429
431
  */
430
432
  ws(
431
433
  req: http.IncomingMessage,
@@ -616,6 +618,12 @@ interface ProxyOptions extends HttpProxy.ServerOptions {
616
618
  * webpack-dev-server style bypass function
617
619
  */
618
620
  bypass?: (req: http.IncomingMessage, res: http.ServerResponse, options: ProxyOptions) => void | null | undefined | false | string;
621
+ /**
622
+ * rewrite the Origin header of a WebSocket request to match the the target
623
+ *
624
+ * **Exercise caution as rewriting the Origin can leave the proxying open to [CSRF attacks](https://owasp.org/www-community/attacks/csrf).**
625
+ */
626
+ rewriteWsOrigin?: boolean | undefined;
619
627
  }
620
628
 
621
629
  type LogType = 'error' | 'warn' | 'info';
@@ -679,8 +687,8 @@ interface CommonServerOptions {
679
687
  * ``` js
680
688
  * module.exports = {
681
689
  * proxy: {
682
- * // string shorthand
683
- * '/foo': 'http://localhost:4567/foo',
690
+ * // string shorthand: /foo -> http://localhost:4567/foo
691
+ * '/foo': 'http://localhost:4567',
684
692
  * // with options
685
693
  * '/api': {
686
694
  * target: 'http://jsonplaceholder.typicode.com',
@@ -708,7 +716,7 @@ interface CommonServerOptions {
708
716
  * https://github.com/expressjs/cors#configuration-options
709
717
  */
710
718
  interface CorsOptions {
711
- origin?: CorsOrigin | ((origin: string, cb: (err: Error, origins: CorsOrigin) => void) => void);
719
+ origin?: CorsOrigin | ((origin: string | undefined, cb: (err: Error, origins: CorsOrigin) => void) => void);
712
720
  methods?: string | string[];
713
721
  allowedHeaders?: string | string[];
714
722
  exposedHeaders?: string | string[];
@@ -783,835 +791,220 @@ type CLIShortcut<Server = ViteDevServer | PreviewServer> = {
783
791
  action?(server: Server): void | Promise<void>;
784
792
  };
785
793
 
794
+ declare class PartialEnvironment {
795
+ name: string;
796
+ getTopLevelConfig(): ResolvedConfig;
797
+ config: ResolvedConfig & ResolvedEnvironmentOptions;
798
+ /**
799
+ * @deprecated use environment.config instead
800
+ **/
801
+ get options(): ResolvedEnvironmentOptions;
802
+ logger: Logger;
803
+ constructor(name: string, topLevelConfig: ResolvedConfig, options?: ResolvedEnvironmentOptions);
804
+ }
805
+ declare class BaseEnvironment extends PartialEnvironment {
806
+ get plugins(): Plugin[];
807
+ constructor(name: string, config: ResolvedConfig, options?: ResolvedEnvironmentOptions);
808
+ }
786
809
  /**
787
- * This file is refactored into TypeScript based on
788
- * https://github.com/preactjs/wmr/blob/main/packages/wmr/src/lib/rollup-plugin-container.js
810
+ * This class discourages users from inversely checking the `mode`
811
+ * to determine the type of environment, e.g.
812
+ *
813
+ * ```js
814
+ * const isDev = environment.mode !== 'build' // bad
815
+ * const isDev = environment.mode === 'dev' // good
816
+ * ```
817
+ *
818
+ * You should also not check against `"unknown"` specfically. It's
819
+ * a placeholder for more possible environment types.
789
820
  */
790
-
791
- interface BoundedPluginContainer {
792
- options: InputOptions;
793
- buildStart(options: InputOptions): Promise<void>;
794
- resolveId(id: string, importer: string | undefined, options?: {
795
- attributes?: Record<string, string>;
796
- custom?: CustomPluginOptions;
797
- skip?: Set<Plugin>;
798
- isEntry?: boolean;
799
- }): Promise<PartialResolvedId | null>;
800
- transform(code: string, id: string, options?: {
801
- inMap?: SourceDescription['map'];
802
- }): Promise<{
803
- code: string;
804
- map: SourceMap | {
805
- mappings: '';
806
- } | null;
807
- }>;
808
- load(id: string, options?: {}): Promise<LoadResult | null>;
809
- watchChange(id: string, change: {
810
- event: 'create' | 'update' | 'delete';
811
- }): Promise<void>;
812
- close(): Promise<void>;
821
+ declare class UnknownEnvironment extends BaseEnvironment {
822
+ mode: "unknown";
813
823
  }
814
- interface PluginContainer {
815
- options: InputOptions;
816
- buildStart(options: InputOptions): Promise<void>;
817
- resolveId(id: string, importer: string | undefined, options?: {
818
- attributes?: Record<string, string>;
819
- custom?: CustomPluginOptions;
820
- skip?: Set<Plugin>;
821
- ssr?: boolean;
822
- environment?: PluginEnvironment;
823
- isEntry?: boolean;
824
- }): Promise<PartialResolvedId | null>;
825
- transform(code: string, id: string, options?: {
826
- inMap?: SourceDescription['map'];
827
- ssr?: boolean;
828
- environment?: PluginEnvironment;
829
- }): Promise<{
830
- code: string;
831
- map: SourceMap | {
832
- mappings: '';
833
- } | null;
834
- }>;
835
- load(id: string, options?: {
836
- ssr?: boolean;
837
- environment?: PluginEnvironment;
838
- }): Promise<LoadResult | null>;
839
- watchChange(id: string, change: {
840
- event: 'create' | 'update' | 'delete';
841
- }): Promise<void>;
842
- close(): Promise<void>;
824
+
825
+ interface FetchModuleOptions {
826
+ cached?: boolean;
827
+ inlineSourceMap?: boolean;
828
+ processSourceMap?<T extends NonNullable<TransformResult['map']>>(map: T): T;
843
829
  }
830
+ /**
831
+ * Fetch module information for Vite runner.
832
+ * @experimental
833
+ */
834
+ declare function fetchModule(environment: DevEnvironment, url: string, importer?: string, options?: FetchModuleOptions): Promise<FetchResult>;
844
835
 
845
- // Modified and inlined to avoid extra dependency
846
- // Source: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/ws/index.d.ts
836
+ declare class ScanEnvironment extends BaseEnvironment {
837
+ mode: "scan";
838
+ get pluginContainer(): EnvironmentPluginContainer;
839
+ init(): Promise<void>;
840
+ }
847
841
 
848
- declare const WebSocketAlias: typeof WebSocket
849
- interface WebSocketAlias extends WebSocket {}
850
- // WebSocket socket.
851
- declare class WebSocket extends EventEmitter {
852
- /** The connection is not yet open. */
853
- static readonly CONNECTING: 0
854
- /** The connection is open and ready to communicate. */
855
- static readonly OPEN: 1
856
- /** The connection is in the process of closing. */
857
- static readonly CLOSING: 2
858
- /** The connection is closed. */
859
- static readonly CLOSED: 3
860
-
861
- binaryType: 'nodebuffer' | 'arraybuffer' | 'fragments'
862
- readonly bufferedAmount: number
863
- readonly extensions: string
864
- /** Indicates whether the websocket is paused */
865
- readonly isPaused: boolean
866
- readonly protocol: string
867
- /** The current state of the connection */
868
- readonly readyState:
869
- | typeof WebSocket.CONNECTING
870
- | typeof WebSocket.OPEN
871
- | typeof WebSocket.CLOSING
872
- | typeof WebSocket.CLOSED
873
- readonly url: string
874
-
875
- /** The connection is not yet open. */
876
- readonly CONNECTING: 0
877
- /** The connection is open and ready to communicate. */
878
- readonly OPEN: 1
879
- /** The connection is in the process of closing. */
880
- readonly CLOSING: 2
881
- /** The connection is closed. */
882
- readonly CLOSED: 3
883
-
884
- onopen: ((event: WebSocket.Event) => void) | null
885
- onerror: ((event: WebSocket.ErrorEvent) => void) | null
886
- onclose: ((event: WebSocket.CloseEvent) => void) | null
887
- onmessage: ((event: WebSocket.MessageEvent) => void) | null
888
-
889
- constructor(address: null)
890
- constructor(
891
- address: string | URL,
892
- options?: WebSocket.ClientOptions | ClientRequestArgs,
893
- )
894
- constructor(
895
- address: string | URL,
896
- protocols?: string | string[],
897
- options?: WebSocket.ClientOptions | ClientRequestArgs,
898
- )
899
-
900
- close(code?: number, data?: string | Buffer): void
901
- ping(data?: any, mask?: boolean, cb?: (err: Error) => void): void
902
- pong(data?: any, mask?: boolean, cb?: (err: Error) => void): void
903
- send(data: any, cb?: (err?: Error) => void): void
904
- send(
905
- data: any,
906
- options: {
907
- mask?: boolean | undefined
908
- binary?: boolean | undefined
909
- compress?: boolean | undefined
910
- fin?: boolean | undefined
911
- },
912
- cb?: (err?: Error) => void,
913
- ): void
914
- terminate(): void
915
-
916
- /**
917
- * Pause the websocket causing it to stop emitting events. Some events can still be
918
- * emitted after this is called, until all buffered data is consumed. This method
919
- * is a noop if the ready state is `CONNECTING` or `CLOSED`.
920
- */
921
- pause(): void
922
- /**
923
- * Make a paused socket resume emitting events. This method is a noop if the ready
924
- * state is `CONNECTING` or `CLOSED`.
925
- */
926
- resume(): void
927
-
928
- // HTML5 WebSocket events
929
- addEventListener(
930
- method: 'message',
931
- cb: (event: WebSocket.MessageEvent) => void,
932
- options?: WebSocket.EventListenerOptions,
933
- ): void
934
- addEventListener(
935
- method: 'close',
936
- cb: (event: WebSocket.CloseEvent) => void,
937
- options?: WebSocket.EventListenerOptions,
938
- ): void
939
- addEventListener(
940
- method: 'error',
941
- cb: (event: WebSocket.ErrorEvent) => void,
942
- options?: WebSocket.EventListenerOptions,
943
- ): void
944
- addEventListener(
945
- method: 'open',
946
- cb: (event: WebSocket.Event) => void,
947
- options?: WebSocket.EventListenerOptions,
948
- ): void
949
-
950
- removeEventListener(
951
- method: 'message',
952
- cb: (event: WebSocket.MessageEvent) => void,
953
- ): void
954
- removeEventListener(
955
- method: 'close',
956
- cb: (event: WebSocket.CloseEvent) => void,
957
- ): void
958
- removeEventListener(
959
- method: 'error',
960
- cb: (event: WebSocket.ErrorEvent) => void,
961
- ): void
962
- removeEventListener(
963
- method: 'open',
964
- cb: (event: WebSocket.Event) => void,
965
- ): void
966
-
967
- // Events
968
- on(
969
- event: 'close',
970
- listener: (this: WebSocket, code: number, reason: Buffer) => void,
971
- ): this
972
- on(event: 'error', listener: (this: WebSocket, err: Error) => void): this
973
- on(
974
- event: 'upgrade',
975
- listener: (this: WebSocket, request: IncomingMessage) => void,
976
- ): this
977
- on(
978
- event: 'message',
979
- listener: (
980
- this: WebSocket,
981
- data: WebSocket.RawData,
982
- isBinary: boolean,
983
- ) => void,
984
- ): this
985
- on(event: 'open', listener: (this: WebSocket) => void): this
986
- on(
987
- event: 'ping' | 'pong',
988
- listener: (this: WebSocket, data: Buffer) => void,
989
- ): this
990
- on(
991
- event: 'unexpected-response',
992
- listener: (
993
- this: WebSocket,
994
- request: ClientRequest,
995
- response: IncomingMessage,
996
- ) => void,
997
- ): this
998
- on(
999
- event: string | symbol,
1000
- listener: (this: WebSocket, ...args: any[]) => void,
1001
- ): this
1002
-
1003
- once(
1004
- event: 'close',
1005
- listener: (this: WebSocket, code: number, reason: Buffer) => void,
1006
- ): this
1007
- once(event: 'error', listener: (this: WebSocket, err: Error) => void): this
1008
- once(
1009
- event: 'upgrade',
1010
- listener: (this: WebSocket, request: IncomingMessage) => void,
1011
- ): this
1012
- once(
1013
- event: 'message',
1014
- listener: (
1015
- this: WebSocket,
1016
- data: WebSocket.RawData,
1017
- isBinary: boolean,
1018
- ) => void,
1019
- ): this
1020
- once(event: 'open', listener: (this: WebSocket) => void): this
1021
- once(
1022
- event: 'ping' | 'pong',
1023
- listener: (this: WebSocket, data: Buffer) => void,
1024
- ): this
1025
- once(
1026
- event: 'unexpected-response',
1027
- listener: (
1028
- this: WebSocket,
1029
- request: ClientRequest,
1030
- response: IncomingMessage,
1031
- ) => void,
1032
- ): this
1033
- once(
1034
- event: string | symbol,
1035
- listener: (this: WebSocket, ...args: any[]) => void,
1036
- ): this
1037
-
1038
- off(
1039
- event: 'close',
1040
- listener: (this: WebSocket, code: number, reason: Buffer) => void,
1041
- ): this
1042
- off(event: 'error', listener: (this: WebSocket, err: Error) => void): this
1043
- off(
1044
- event: 'upgrade',
1045
- listener: (this: WebSocket, request: IncomingMessage) => void,
1046
- ): this
1047
- off(
1048
- event: 'message',
1049
- listener: (
1050
- this: WebSocket,
1051
- data: WebSocket.RawData,
1052
- isBinary: boolean,
1053
- ) => void,
1054
- ): this
1055
- off(event: 'open', listener: (this: WebSocket) => void): this
1056
- off(
1057
- event: 'ping' | 'pong',
1058
- listener: (this: WebSocket, data: Buffer) => void,
1059
- ): this
1060
- off(
1061
- event: 'unexpected-response',
1062
- listener: (
1063
- this: WebSocket,
1064
- request: ClientRequest,
1065
- response: IncomingMessage,
1066
- ) => void,
1067
- ): this
1068
- off(
1069
- event: string | symbol,
1070
- listener: (this: WebSocket, ...args: any[]) => void,
1071
- ): this
1072
-
1073
- addListener(
1074
- event: 'close',
1075
- listener: (code: number, reason: Buffer) => void,
1076
- ): this
1077
- addListener(event: 'error', listener: (err: Error) => void): this
1078
- addListener(
1079
- event: 'upgrade',
1080
- listener: (request: IncomingMessage) => void,
1081
- ): this
1082
- addListener(
1083
- event: 'message',
1084
- listener: (data: WebSocket.RawData, isBinary: boolean) => void,
1085
- ): this
1086
- addListener(event: 'open', listener: () => void): this
1087
- addListener(event: 'ping' | 'pong', listener: (data: Buffer) => void): this
1088
- addListener(
1089
- event: 'unexpected-response',
1090
- listener: (request: ClientRequest, response: IncomingMessage) => void,
1091
- ): this
1092
- addListener(event: string | symbol, listener: (...args: any[]) => void): this
1093
-
1094
- removeListener(
1095
- event: 'close',
1096
- listener: (code: number, reason: Buffer) => void,
1097
- ): this
1098
- removeListener(event: 'error', listener: (err: Error) => void): this
1099
- removeListener(
1100
- event: 'upgrade',
1101
- listener: (request: IncomingMessage) => void,
1102
- ): this
1103
- removeListener(
1104
- event: 'message',
1105
- listener: (data: WebSocket.RawData, isBinary: boolean) => void,
1106
- ): this
1107
- removeListener(event: 'open', listener: () => void): this
1108
- removeListener(event: 'ping' | 'pong', listener: (data: Buffer) => void): this
1109
- removeListener(
1110
- event: 'unexpected-response',
1111
- listener: (request: ClientRequest, response: IncomingMessage) => void,
1112
- ): this
1113
- removeListener(
1114
- event: string | symbol,
1115
- listener: (...args: any[]) => void,
1116
- ): this
1117
- }
1118
- // tslint:disable-line no-empty-interface
1119
-
1120
- declare namespace WebSocket {
1121
- /**
1122
- * Data represents the raw message payload received over the WebSocket.
1123
- */
1124
- type RawData = Buffer | ArrayBuffer | Buffer[]
1125
-
1126
- /**
1127
- * Data represents the message payload received over the WebSocket.
1128
- */
1129
- type Data = string | Buffer | ArrayBuffer | Buffer[]
1130
-
1131
- /**
1132
- * CertMeta represents the accepted types for certificate & key data.
1133
- */
1134
- type CertMeta = string | string[] | Buffer | Buffer[]
1135
-
1136
- /**
1137
- * VerifyClientCallbackSync is a synchronous callback used to inspect the
1138
- * incoming message. The return value (boolean) of the function determines
1139
- * whether or not to accept the handshake.
1140
- */
1141
- type VerifyClientCallbackSync = (info: {
1142
- origin: string
1143
- secure: boolean
1144
- req: IncomingMessage
1145
- }) => boolean
1146
-
1147
- /**
1148
- * VerifyClientCallbackAsync is an asynchronous callback used to inspect the
1149
- * incoming message. The return value (boolean) of the function determines
1150
- * whether or not to accept the handshake.
1151
- */
1152
- type VerifyClientCallbackAsync = (
1153
- info: { origin: string; secure: boolean; req: IncomingMessage },
1154
- callback: (
1155
- res: boolean,
1156
- code?: number,
1157
- message?: string,
1158
- headers?: OutgoingHttpHeaders,
1159
- ) => void,
1160
- ) => void
1161
-
1162
- interface ClientOptions extends SecureContextOptions {
1163
- protocol?: string | undefined
1164
- followRedirects?: boolean | undefined
1165
- generateMask?(mask: Buffer): void
1166
- handshakeTimeout?: number | undefined
1167
- maxRedirects?: number | undefined
1168
- perMessageDeflate?: boolean | PerMessageDeflateOptions | undefined
1169
- localAddress?: string | undefined
1170
- protocolVersion?: number | undefined
1171
- headers?: { [key: string]: string } | undefined
1172
- origin?: string | undefined
1173
- agent?: Agent | undefined
1174
- host?: string | undefined
1175
- family?: number | undefined
1176
- checkServerIdentity?(servername: string, cert: CertMeta): boolean
1177
- rejectUnauthorized?: boolean | undefined
1178
- maxPayload?: number | undefined
1179
- skipUTF8Validation?: boolean | undefined
1180
- }
1181
-
1182
- interface PerMessageDeflateOptions {
1183
- serverNoContextTakeover?: boolean | undefined
1184
- clientNoContextTakeover?: boolean | undefined
1185
- serverMaxWindowBits?: number | undefined
1186
- clientMaxWindowBits?: number | undefined
1187
- zlibDeflateOptions?:
1188
- | {
1189
- flush?: number | undefined
1190
- finishFlush?: number | undefined
1191
- chunkSize?: number | undefined
1192
- windowBits?: number | undefined
1193
- level?: number | undefined
1194
- memLevel?: number | undefined
1195
- strategy?: number | undefined
1196
- dictionary?: Buffer | Buffer[] | DataView | undefined
1197
- info?: boolean | undefined
1198
- }
1199
- | undefined
1200
- zlibInflateOptions?: ZlibOptions | undefined
1201
- threshold?: number | undefined
1202
- concurrencyLimit?: number | undefined
1203
- }
1204
-
1205
- interface Event {
1206
- type: string
1207
- target: WebSocket
1208
- }
1209
-
1210
- interface ErrorEvent {
1211
- error: any
1212
- message: string
1213
- type: string
1214
- target: WebSocket
1215
- }
1216
-
1217
- interface CloseEvent {
1218
- wasClean: boolean
1219
- code: number
1220
- reason: string
1221
- type: string
1222
- target: WebSocket
1223
- }
1224
-
1225
- interface MessageEvent {
1226
- data: Data
1227
- type: string
1228
- target: WebSocket
1229
- }
1230
-
1231
- interface EventListenerOptions {
1232
- once?: boolean | undefined
1233
- }
1234
-
1235
- interface ServerOptions {
1236
- host?: string | undefined
1237
- port?: number | undefined
1238
- backlog?: number | undefined
1239
- server?: Server | HttpsServer | undefined
1240
- verifyClient?:
1241
- | VerifyClientCallbackAsync
1242
- | VerifyClientCallbackSync
1243
- | undefined
1244
- handleProtocols?: (
1245
- protocols: Set<string>,
1246
- request: IncomingMessage,
1247
- ) => string | false
1248
- path?: string | undefined
1249
- noServer?: boolean | undefined
1250
- clientTracking?: boolean | undefined
1251
- perMessageDeflate?: boolean | PerMessageDeflateOptions | undefined
1252
- maxPayload?: number | undefined
1253
- skipUTF8Validation?: boolean | undefined
1254
- WebSocket?: typeof WebSocket.WebSocket | undefined
1255
- }
1256
-
1257
- interface AddressInfo {
1258
- address: string
1259
- family: string
1260
- port: number
1261
- }
1262
-
1263
- // WebSocket Server
1264
- class Server<T extends WebSocket = WebSocket> extends EventEmitter {
1265
- options: ServerOptions
1266
- path: string
1267
- clients: Set<T>
1268
-
1269
- constructor(options?: ServerOptions, callback?: () => void)
1270
-
1271
- address(): AddressInfo | string
1272
- close(cb?: (err?: Error) => void): void
1273
- handleUpgrade(
1274
- request: IncomingMessage,
1275
- socket: Duplex,
1276
- upgradeHead: Buffer,
1277
- callback: (client: T, request: IncomingMessage) => void,
1278
- ): void
1279
- shouldHandle(request: IncomingMessage): boolean | Promise<boolean>
1280
-
1281
- // Events
1282
- on(
1283
- event: 'connection',
1284
- cb: (this: Server<T>, socket: T, request: IncomingMessage) => void,
1285
- ): this
1286
- on(event: 'error', cb: (this: Server<T>, error: Error) => void): this
1287
- on(
1288
- event: 'headers',
1289
- cb: (
1290
- this: Server<T>,
1291
- headers: string[],
1292
- request: IncomingMessage,
1293
- ) => void,
1294
- ): this
1295
- on(event: 'close' | 'listening', cb: (this: Server<T>) => void): this
1296
- on(
1297
- event: string | symbol,
1298
- listener: (this: Server<T>, ...args: any[]) => void,
1299
- ): this
1300
-
1301
- once(
1302
- event: 'connection',
1303
- cb: (this: Server<T>, socket: T, request: IncomingMessage) => void,
1304
- ): this
1305
- once(event: 'error', cb: (this: Server<T>, error: Error) => void): this
1306
- once(
1307
- event: 'headers',
1308
- cb: (
1309
- this: Server<T>,
1310
- headers: string[],
1311
- request: IncomingMessage,
1312
- ) => void,
1313
- ): this
1314
- once(event: 'close' | 'listening', cb: (this: Server<T>) => void): this
1315
- once(
1316
- event: string | symbol,
1317
- listener: (this: Server<T>, ...args: any[]) => void,
1318
- ): this
1319
-
1320
- off(
1321
- event: 'connection',
1322
- cb: (this: Server<T>, socket: T, request: IncomingMessage) => void,
1323
- ): this
1324
- off(event: 'error', cb: (this: Server<T>, error: Error) => void): this
1325
- off(
1326
- event: 'headers',
1327
- cb: (
1328
- this: Server<T>,
1329
- headers: string[],
1330
- request: IncomingMessage,
1331
- ) => void,
1332
- ): this
1333
- off(event: 'close' | 'listening', cb: (this: Server<T>) => void): this
1334
- off(
1335
- event: string | symbol,
1336
- listener: (this: Server<T>, ...args: any[]) => void,
1337
- ): this
1338
-
1339
- addListener(
1340
- event: 'connection',
1341
- cb: (client: T, request: IncomingMessage) => void,
1342
- ): this
1343
- addListener(event: 'error', cb: (err: Error) => void): this
1344
- addListener(
1345
- event: 'headers',
1346
- cb: (headers: string[], request: IncomingMessage) => void,
1347
- ): this
1348
- addListener(event: 'close' | 'listening', cb: () => void): this
1349
- addListener(
1350
- event: string | symbol,
1351
- listener: (...args: any[]) => void,
1352
- ): this
1353
-
1354
- removeListener(event: 'connection', cb: (client: T) => void): this
1355
- removeListener(event: 'error', cb: (err: Error) => void): this
1356
- removeListener(
1357
- event: 'headers',
1358
- cb: (headers: string[], request: IncomingMessage) => void,
1359
- ): this
1360
- removeListener(event: 'close' | 'listening', cb: () => void): this
1361
- removeListener(
1362
- event: string | symbol,
1363
- listener: (...args: any[]) => void,
1364
- ): this
1365
- }
1366
-
1367
- const WebSocketServer: typeof Server
1368
- interface WebSocketServer extends Server {} // tslint:disable-line no-empty-interface
1369
- const WebSocket: typeof WebSocketAlias
1370
- interface WebSocket extends WebSocketAlias {} // tslint:disable-line no-empty-interface
1371
-
1372
- // WebSocket stream
1373
- function createWebSocketStream(
1374
- websocket: WebSocket,
1375
- options?: DuplexOptions,
1376
- ): Duplex
1377
- }
1378
-
1379
- declare class Environment {
1380
- #private;
1381
- name: string;
1382
- config: ResolvedConfig;
1383
- options: ResolvedEnvironmentOptions;
1384
- get plugins(): BoundedPlugin[];
1385
- get logger(): Logger;
1386
- constructor(name: string, config: ResolvedConfig, options?: ResolvedEnvironmentOptions);
1387
- }
1388
-
1389
- interface FetchModuleOptions {
1390
- inlineSourceMap?: boolean;
1391
- processSourceMap?<T extends NonNullable<TransformResult['map']>>(map: T): T;
1392
- }
1393
- /**
1394
- * Fetch module information for Vite runner.
1395
- * @experimental
1396
- */
1397
- declare function fetchModule(environment: DevEnvironment, url: string, importer?: string, options?: FetchModuleOptions): Promise<FetchResult>;
1398
-
1399
- declare class ScanEnvironment extends Environment {
1400
- mode: "scan";
1401
- get pluginContainer(): BoundedPluginContainer;
1402
- init(): Promise<void>;
1403
- }
1404
-
1405
- type ExportsData = {
1406
- hasModuleSyntax: boolean;
1407
- exports: readonly string[];
1408
- jsxLoader?: boolean;
1409
- };
1410
- interface DepsOptimizer {
1411
- init: () => Promise<void>;
1412
- metadata: DepOptimizationMetadata;
1413
- scanProcessing?: Promise<void>;
1414
- registerMissingImport: (id: string, resolved: string) => OptimizedDepInfo;
1415
- run: () => void;
1416
- isOptimizedDepFile: (id: string) => boolean;
1417
- isOptimizedDepUrl: (url: string) => boolean;
1418
- getOptimizedDepId: (depInfo: OptimizedDepInfo) => string;
1419
- close: () => Promise<void>;
1420
- options: DepOptimizationOptions;
1421
- }
1422
- interface DepOptimizationConfig {
1423
- /**
1424
- * Force optimize listed dependencies (must be resolvable import paths,
1425
- * cannot be globs).
1426
- */
1427
- include?: string[];
1428
- /**
1429
- * Do not optimize these dependencies (must be resolvable import paths,
1430
- * cannot be globs).
1431
- */
1432
- exclude?: string[];
1433
- /**
1434
- * Forces ESM interop when importing these dependencies. Some legacy
1435
- * packages advertise themselves as ESM but use `require` internally
1436
- * @experimental
1437
- */
1438
- needsInterop?: string[];
1439
- /**
1440
- * Options to pass to esbuild during the dep scanning and optimization
1441
- *
1442
- * Certain options are omitted since changing them would not be compatible
1443
- * with Vite's dep optimization.
1444
- *
1445
- * - `external` is also omitted, use Vite's `optimizeDeps.exclude` option
1446
- * - `plugins` are merged with Vite's dep plugin
1447
- *
1448
- * https://esbuild.github.io/api
1449
- */
1450
- esbuildOptions?: Omit<esbuild_BuildOptions, 'bundle' | 'entryPoints' | 'external' | 'write' | 'watch' | 'outdir' | 'outfile' | 'outbase' | 'outExtension' | 'metafile'>;
1451
- /**
1452
- * List of file extensions that can be optimized. A corresponding esbuild
1453
- * plugin must exist to handle the specific extension.
1454
- *
1455
- * By default, Vite can optimize `.mjs`, `.js`, `.ts`, and `.mts` files. This option
1456
- * allows specifying additional extensions.
1457
- *
1458
- * @experimental
1459
- */
1460
- extensions?: string[];
1461
- /**
1462
- * Deps optimization during build was removed in Vite 5.1. This option is
1463
- * now redundant and will be removed in a future version. Switch to using
1464
- * `optimizeDeps.noDiscovery` and an empty or undefined `optimizeDeps.include`.
1465
- * true or 'dev' disables the optimizer, false or 'build' leaves it enabled.
1466
- * @default 'build'
1467
- * @deprecated
1468
- * @experimental
1469
- */
1470
- disabled?: boolean | 'build' | 'dev';
1471
- /**
1472
- * Automatic dependency discovery. When `noDiscovery` is true, only dependencies
1473
- * listed in `include` will be optimized. The scanner isn't run for cold start
1474
- * in this case. CJS-only dependencies must be present in `include` during dev.
1475
- * @default false
1476
- * @experimental
1477
- */
1478
- noDiscovery?: boolean;
1479
- /**
1480
- * When enabled, it will hold the first optimized deps results until all static
1481
- * imports are crawled on cold start. This avoids the need for full-page reloads
1482
- * when new dependencies are discovered and they trigger the generation of new
1483
- * common chunks. If all dependencies are found by the scanner plus the explicitely
1484
- * defined ones in `include`, it is better to disable this option to let the
1485
- * browser process more requests in parallel.
1486
- * @default true
1487
- * @experimental
1488
- */
1489
- holdUntilCrawlEnd?: boolean;
1490
- }
1491
- type DepOptimizationOptions = DepOptimizationConfig & {
1492
- /**
1493
- * By default, Vite will crawl your `index.html` to detect dependencies that
1494
- * need to be pre-bundled. If `build.rollupOptions.input` is specified, Vite
1495
- * will crawl those entry points instead.
1496
- *
1497
- * If neither of these fit your needs, you can specify custom entries using
1498
- * this option - the value should be a fast-glob pattern or array of patterns
1499
- * (https://github.com/mrmlnc/fast-glob#basic-syntax) that are relative from
1500
- * vite project root. This will overwrite default entries inference.
1501
- */
1502
- entries?: string | string[];
1503
- /**
1504
- * Force dep pre-optimization regardless of whether deps have changed.
1505
- * @experimental
1506
- */
1507
- force?: boolean;
1508
- };
1509
- interface OptimizedDepInfo {
1510
- id: string;
1511
- file: string;
1512
- src?: string;
1513
- needsInterop?: boolean;
1514
- browserHash?: string;
1515
- fileHash?: string;
1516
- /**
1517
- * During optimization, ids can still be resolved to their final location
1518
- * but the bundles may not yet be saved to disk
1519
- */
1520
- processing?: Promise<void>;
1521
- /**
1522
- * ExportData cache, discovered deps will parse the src entry to get exports
1523
- * data used both to define if interop is needed and when pre-bundling
1524
- */
1525
- exportsData?: Promise<ExportsData>;
1526
- }
1527
- interface DepOptimizationMetadata {
1528
- /**
1529
- * The main hash is determined by user config and dependency lockfiles.
1530
- * This is checked on server startup to avoid unnecessary re-bundles.
1531
- */
1532
- hash: string;
1533
- /**
1534
- * This hash is determined by dependency lockfiles.
1535
- * This is checked on server startup to avoid unnecessary re-bundles.
1536
- */
1537
- lockfileHash: string;
1538
- /**
1539
- * This hash is determined by user config.
1540
- * This is checked on server startup to avoid unnecessary re-bundles.
1541
- */
1542
- configHash: string;
1543
- /**
1544
- * The browser hash is determined by the main hash plus additional dependencies
1545
- * discovered at runtime. This is used to invalidate browser requests to
1546
- * optimized deps.
1547
- */
1548
- browserHash: string;
1549
- /**
1550
- * Metadata for each already optimized dependency
1551
- */
1552
- optimized: Record<string, OptimizedDepInfo>;
1553
- /**
1554
- * Metadata for non-entry optimized chunks and dynamic imports
1555
- */
1556
- chunks: Record<string, OptimizedDepInfo>;
1557
- /**
1558
- * Metadata for each newly discovered dependency after processing
1559
- */
1560
- discovered: Record<string, OptimizedDepInfo>;
1561
- /**
1562
- * OptimizedDepInfo list
1563
- */
1564
- depInfoList: OptimizedDepInfo[];
1565
- }
1566
-
1567
- declare class RemoteEnvironmentTransport {
1568
- private readonly options;
1569
- constructor(options: {
1570
- send: (data: any) => void;
1571
- onMessage: (handler: (data: any) => void) => void;
1572
- });
1573
- register(environment: DevEnvironment): void;
1574
- }
1575
-
1576
- interface DevEnvironmentSetup {
1577
- hot?: false | HMRChannel;
1578
- watcher?: FSWatcher;
1579
- options?: EnvironmentOptions;
1580
- runner?: FetchModuleOptions & {
1581
- transport?: RemoteEnvironmentTransport;
1582
- };
1583
- depsOptimizer?: DepsOptimizer;
1584
- }
1585
- declare class DevEnvironment extends Environment {
1586
- mode: "dev";
1587
- moduleGraph: EnvironmentModuleGraph;
1588
- watcher?: FSWatcher;
1589
- depsOptimizer?: DepsOptimizer;
1590
- get pluginContainer(): BoundedPluginContainer;
1591
- /**
1592
- * HMR channel for this environment. If not provided or disabled,
1593
- * it will be a noop channel that does nothing.
1594
- *
1595
- * @example
1596
- * environment.hot.send({ type: 'full-reload' })
1597
- */
1598
- hot: HMRChannel;
1599
- constructor(name: string, config: ResolvedConfig, setup?: DevEnvironmentSetup);
1600
- init(): Promise<void>;
1601
- fetchModule(id: string, importer?: string): Promise<FetchResult>;
1602
- transformRequest(url: string): Promise<TransformResult | null>;
1603
- warmupRequest(url: string): Promise<void>;
1604
- close(): Promise<void>;
1605
- /**
1606
- * Calling `await environment.waitForRequestsIdle(id)` will wait until all static imports
1607
- * are processed after the first transformRequest call. If called from a load or transform
1608
- * plugin hook, the id needs to be passed as a parameter to avoid deadlocks.
1609
- * Calling this function after the first static imports section of the module graph has been
1610
- * processed will resolve immediately.
1611
- * @experimental
1612
- */
1613
- waitForRequestsIdle(ignoredId?: string): Promise<void>;
1614
- }
842
+ type ExportsData = {
843
+ hasModuleSyntax: boolean;
844
+ exports: readonly string[];
845
+ jsxLoader?: boolean;
846
+ };
847
+ interface DepsOptimizer {
848
+ init: () => Promise<void>;
849
+ metadata: DepOptimizationMetadata;
850
+ scanProcessing?: Promise<void>;
851
+ registerMissingImport: (id: string, resolved: string) => OptimizedDepInfo;
852
+ run: () => void;
853
+ isOptimizedDepFile: (id: string) => boolean;
854
+ isOptimizedDepUrl: (url: string) => boolean;
855
+ getOptimizedDepId: (depInfo: OptimizedDepInfo) => string;
856
+ close: () => Promise<void>;
857
+ options: DepOptimizationOptions;
858
+ }
859
+ interface DepOptimizationConfig {
860
+ /**
861
+ * Force optimize listed dependencies (must be resolvable import paths,
862
+ * cannot be globs).
863
+ */
864
+ include?: string[];
865
+ /**
866
+ * Do not optimize these dependencies (must be resolvable import paths,
867
+ * cannot be globs).
868
+ */
869
+ exclude?: string[];
870
+ /**
871
+ * Forces ESM interop when importing these dependencies. Some legacy
872
+ * packages advertise themselves as ESM but use `require` internally
873
+ * @experimental
874
+ */
875
+ needsInterop?: string[];
876
+ /**
877
+ * Options to pass to esbuild during the dep scanning and optimization
878
+ *
879
+ * Certain options are omitted since changing them would not be compatible
880
+ * with Vite's dep optimization.
881
+ *
882
+ * - `external` is also omitted, use Vite's `optimizeDeps.exclude` option
883
+ * - `plugins` are merged with Vite's dep plugin
884
+ *
885
+ * https://esbuild.github.io/api
886
+ */
887
+ esbuildOptions?: Omit<esbuild_BuildOptions, 'bundle' | 'entryPoints' | 'external' | 'write' | 'watch' | 'outdir' | 'outfile' | 'outbase' | 'outExtension' | 'metafile'>;
888
+ /**
889
+ * List of file extensions that can be optimized. A corresponding esbuild
890
+ * plugin must exist to handle the specific extension.
891
+ *
892
+ * By default, Vite can optimize `.mjs`, `.js`, `.ts`, and `.mts` files. This option
893
+ * allows specifying additional extensions.
894
+ *
895
+ * @experimental
896
+ */
897
+ extensions?: string[];
898
+ /**
899
+ * Deps optimization during build was removed in Vite 5.1. This option is
900
+ * now redundant and will be removed in a future version. Switch to using
901
+ * `optimizeDeps.noDiscovery` and an empty or undefined `optimizeDeps.include`.
902
+ * true or 'dev' disables the optimizer, false or 'build' leaves it enabled.
903
+ * @default 'build'
904
+ * @deprecated
905
+ * @experimental
906
+ */
907
+ disabled?: boolean | 'build' | 'dev';
908
+ /**
909
+ * Automatic dependency discovery. When `noDiscovery` is true, only dependencies
910
+ * listed in `include` will be optimized. The scanner isn't run for cold start
911
+ * in this case. CJS-only dependencies must be present in `include` during dev.
912
+ * @default false
913
+ * @experimental
914
+ */
915
+ noDiscovery?: boolean;
916
+ /**
917
+ * When enabled, it will hold the first optimized deps results until all static
918
+ * imports are crawled on cold start. This avoids the need for full-page reloads
919
+ * when new dependencies are discovered and they trigger the generation of new
920
+ * common chunks. If all dependencies are found by the scanner plus the explicitly
921
+ * defined ones in `include`, it is better to disable this option to let the
922
+ * browser process more requests in parallel.
923
+ * @default true
924
+ * @experimental
925
+ */
926
+ holdUntilCrawlEnd?: boolean;
927
+ }
928
+ type DepOptimizationOptions = DepOptimizationConfig & {
929
+ /**
930
+ * By default, Vite will crawl your `index.html` to detect dependencies that
931
+ * need to be pre-bundled. If `build.rollupOptions.input` is specified, Vite
932
+ * will crawl those entry points instead.
933
+ *
934
+ * If neither of these fit your needs, you can specify custom entries using
935
+ * this option - the value should be a fast-glob pattern or array of patterns
936
+ * (https://github.com/mrmlnc/fast-glob#basic-syntax) that are relative from
937
+ * vite project root. This will overwrite default entries inference.
938
+ */
939
+ entries?: string | string[];
940
+ /**
941
+ * Force dep pre-optimization regardless of whether deps have changed.
942
+ * @experimental
943
+ */
944
+ force?: boolean;
945
+ };
946
+ interface OptimizedDepInfo {
947
+ id: string;
948
+ file: string;
949
+ src?: string;
950
+ needsInterop?: boolean;
951
+ browserHash?: string;
952
+ fileHash?: string;
953
+ /**
954
+ * During optimization, ids can still be resolved to their final location
955
+ * but the bundles may not yet be saved to disk
956
+ */
957
+ processing?: Promise<void>;
958
+ /**
959
+ * ExportData cache, discovered deps will parse the src entry to get exports
960
+ * data used both to define if interop is needed and when pre-bundling
961
+ */
962
+ exportsData?: Promise<ExportsData>;
963
+ }
964
+ interface DepOptimizationMetadata {
965
+ /**
966
+ * The main hash is determined by user config and dependency lockfiles.
967
+ * This is checked on server startup to avoid unnecessary re-bundles.
968
+ */
969
+ hash: string;
970
+ /**
971
+ * This hash is determined by dependency lockfiles.
972
+ * This is checked on server startup to avoid unnecessary re-bundles.
973
+ */
974
+ lockfileHash: string;
975
+ /**
976
+ * This hash is determined by user config.
977
+ * This is checked on server startup to avoid unnecessary re-bundles.
978
+ */
979
+ configHash: string;
980
+ /**
981
+ * The browser hash is determined by the main hash plus additional dependencies
982
+ * discovered at runtime. This is used to invalidate browser requests to
983
+ * optimized deps.
984
+ */
985
+ browserHash: string;
986
+ /**
987
+ * Metadata for each already optimized dependency
988
+ */
989
+ optimized: Record<string, OptimizedDepInfo>;
990
+ /**
991
+ * Metadata for non-entry optimized chunks and dynamic imports
992
+ */
993
+ chunks: Record<string, OptimizedDepInfo>;
994
+ /**
995
+ * Metadata for each newly discovered dependency after processing
996
+ */
997
+ discovered: Record<string, OptimizedDepInfo>;
998
+ /**
999
+ * OptimizedDepInfo list
1000
+ */
1001
+ depInfoList: OptimizedDepInfo[];
1002
+ }
1003
+ /**
1004
+ * Scan and optimize dependencies within a project.
1005
+ * Used by Vite CLI when running `vite optimize`.
1006
+ */
1007
+ declare function optimizeDeps(config: ResolvedConfig, force?: boolean | undefined, asCommand?: boolean): Promise<DepOptimizationMetadata>;
1615
1008
 
1616
1009
  interface TransformResult {
1617
1010
  code: string;
@@ -1625,13 +1018,9 @@ interface TransformResult {
1625
1018
  }
1626
1019
  interface TransformOptions {
1627
1020
  /**
1628
- * @deprecated infered from environment
1021
+ * @deprecated inferred from environment
1629
1022
  */
1630
1023
  ssr?: boolean;
1631
- /**
1632
- * TODO: should this be internal?
1633
- */
1634
- html?: boolean;
1635
1024
  }
1636
1025
 
1637
1026
  declare class EnvironmentModuleNode {
@@ -1702,7 +1091,7 @@ declare class EnvironmentModuleGraph {
1702
1091
  }
1703
1092
 
1704
1093
  /**
1705
- * Backward compatible ModuleNode and ModuleGraph with mixed nodes from both the client and ssr enviornments
1094
+ * Backward compatible ModuleNode and ModuleGraph with mixed nodes from both the client and ssr environments
1706
1095
  * It would be good to take the types names for the new EnvironmentModuleNode and EnvironmentModuleGraph but we can't
1707
1096
  * do that at this point without breaking to much code in the ecosystem.
1708
1097
  * We are going to deprecate these types and we can try to use them back in the future.
@@ -1713,11 +1102,15 @@ declare class ModuleNode {
1713
1102
  _ssrModule: EnvironmentModuleNode | undefined;
1714
1103
  constructor(moduleGraph: ModuleGraph, clientModule?: EnvironmentModuleNode, ssrModule?: EnvironmentModuleNode);
1715
1104
  _get<T extends keyof EnvironmentModuleNode>(prop: T): EnvironmentModuleNode[T];
1105
+ _set<T extends keyof EnvironmentModuleNode>(prop: T, value: EnvironmentModuleNode[T]): void;
1716
1106
  _wrapModuleSet(prop: ModuleSetNames, module: EnvironmentModuleNode | undefined): Set<ModuleNode>;
1717
1107
  _getModuleSetUnion(prop: 'importedModules' | 'importers'): Set<ModuleNode>;
1718
1108
  get url(): string;
1109
+ set url(value: string);
1719
1110
  get id(): string | null;
1111
+ set id(value: string | null);
1720
1112
  get file(): string | null;
1113
+ set file(value: string | null);
1721
1114
  get type(): 'js' | 'css';
1722
1115
  get info(): ModuleInfo | undefined;
1723
1116
  get meta(): Record<string, any> | undefined;
@@ -1750,30 +1143,18 @@ declare class ModuleGraph {
1750
1143
  client: () => EnvironmentModuleGraph;
1751
1144
  ssr: () => EnvironmentModuleGraph;
1752
1145
  });
1753
- /** @deprecated */
1754
1146
  getModuleById(id: string): ModuleNode | undefined;
1755
- /** @deprecated */
1756
- getModuleByUrl(url: string, ssr?: boolean): Promise<ModuleNode | undefined>;
1757
- /** @deprecated */
1147
+ getModuleByUrl(url: string, _ssr?: boolean): Promise<ModuleNode | undefined>;
1758
1148
  getModulesByFile(file: string): Set<ModuleNode> | undefined;
1759
- /** @deprecated */
1760
1149
  onFileChange(file: string): void;
1761
- /** @deprecated */
1762
1150
  onFileDelete(file: string): void;
1763
- /** @deprecated */
1764
1151
  invalidateModule(mod: ModuleNode, seen?: Set<ModuleNode>, timestamp?: number, isHmr?: boolean,
1765
1152
  ): void;
1766
- /** @deprecated */
1767
1153
  invalidateAll(): void;
1768
- /** @deprecated */
1769
1154
  ensureEntryFromUrl(rawUrl: string, ssr?: boolean, setIsSelfAccepting?: boolean): Promise<ModuleNode>;
1770
- /** @deprecated */
1771
1155
  createFileOnlyEntry(file: string): ModuleNode;
1772
- /** @deprecated */
1773
1156
  resolveUrl(url: string, ssr?: boolean): Promise<ResolvedUrl>;
1774
- /** @deprecated */
1775
1157
  updateModuleTransformResult(mod: ModuleNode, result: TransformResult | null, ssr?: boolean): void;
1776
- /** @deprecated */
1777
1158
  getModuleByEtag(etag: string): ModuleNode | undefined;
1778
1159
  getBackwardCompatibleBrowserModuleNode(clientModule: EnvironmentModuleNode): ModuleNode;
1779
1160
  getBackwardCompatibleServerModuleNode(ssrModule: EnvironmentModuleNode): ModuleNode;
@@ -1782,1172 +1163,1832 @@ declare class ModuleGraph {
1782
1163
  }
1783
1164
  type ModuleSetNames = 'acceptedHmrDeps' | 'importedModules';
1784
1165
 
1785
- interface HmrOptions {
1786
- protocol?: string;
1787
- host?: string;
1788
- port?: number;
1789
- clientPort?: number;
1790
- path?: string;
1791
- timeout?: number;
1792
- overlay?: boolean;
1793
- server?: Server;
1794
- }
1795
- interface HotUpdateContext {
1796
- type: 'create' | 'update' | 'delete';
1797
- file: string;
1798
- timestamp: number;
1799
- modules: Array<EnvironmentModuleNode>;
1800
- read: () => string | Promise<string>;
1801
- server: ViteDevServer;
1802
- environment: DevEnvironment;
1803
- }
1804
- /**
1805
- * @deprecated
1806
- * Used by handleHotUpdate for backward compatibility with mixed client and ssr moduleGraph
1807
- **/
1808
- interface HmrContext {
1809
- file: string;
1810
- timestamp: number;
1811
- modules: Array<ModuleNode>;
1812
- read: () => string | Promise<string>;
1813
- server: ViteDevServer;
1814
- }
1815
- interface HMRBroadcasterClient {
1816
- /**
1817
- * Send event to the client
1818
- */
1819
- send(payload: HMRPayload): void;
1820
- /**
1821
- * Send custom event
1822
- */
1823
- send(event: string, payload?: CustomPayload['data']): void;
1824
- }
1825
- interface HMRChannel {
1826
- /**
1827
- * Unique channel name
1828
- */
1829
- name: string;
1830
- /**
1831
- * Broadcast events to all clients
1832
- */
1833
- send(payload: HMRPayload): void;
1834
- /**
1835
- * Send custom event
1836
- */
1837
- send<T extends string>(event: T, payload?: InferCustomEventPayload<T>): void;
1838
- /**
1839
- * Handle custom event emitted by `import.meta.hot.send`
1840
- */
1841
- on<T extends string>(event: T, listener: (data: InferCustomEventPayload<T>, client: HMRBroadcasterClient, ...args: any[]) => void): void;
1842
- on(event: 'connection', listener: () => void): void;
1843
- /**
1844
- * Unregister event listener
1845
- */
1846
- off(event: string, listener: Function): void;
1847
- /**
1848
- * Start listening for messages
1849
- */
1850
- listen(): void;
1851
- /**
1852
- * Disconnect all clients, called when server is closed or restarted.
1853
- */
1854
- close(): void;
1855
- }
1856
- interface HMRBroadcaster extends Omit<HMRChannel, 'close' | 'name'> {
1857
- /**
1858
- * All registered channels. Always has websocket channel.
1859
- */
1860
- readonly channels: HMRChannel[];
1861
- /**
1862
- * Add a new third-party channel.
1863
- */
1864
- addChannel(connection: HMRChannel): HMRBroadcaster;
1865
- close(): Promise<unknown[]>;
1166
+ interface HmrOptions {
1167
+ protocol?: string;
1168
+ host?: string;
1169
+ port?: number;
1170
+ clientPort?: number;
1171
+ path?: string;
1172
+ timeout?: number;
1173
+ overlay?: boolean;
1174
+ server?: HttpServer;
1175
+ }
1176
+ interface HotUpdateOptions {
1177
+ type: 'create' | 'update' | 'delete';
1178
+ file: string;
1179
+ timestamp: number;
1180
+ modules: Array<EnvironmentModuleNode>;
1181
+ read: () => string | Promise<string>;
1182
+ server: ViteDevServer;
1183
+ /**
1184
+ * @deprecated use this.environment in the hotUpdate hook instead
1185
+ **/
1186
+ environment: DevEnvironment;
1187
+ }
1188
+ interface HmrContext {
1189
+ file: string;
1190
+ timestamp: number;
1191
+ modules: Array<ModuleNode>;
1192
+ read: () => string | Promise<string>;
1193
+ server: ViteDevServer;
1194
+ }
1195
+ interface HotChannelClient {
1196
+ /**
1197
+ * Send event to the client
1198
+ */
1199
+ send(payload: HotPayload): void;
1200
+ /**
1201
+ * Send custom event
1202
+ */
1203
+ send(event: string, payload?: CustomPayload['data']): void;
1204
+ }
1205
+ /** @deprecated use `HotChannelClient` instead */
1206
+ type HMRBroadcasterClient = HotChannelClient;
1207
+ interface HotChannel {
1208
+ /**
1209
+ * Broadcast events to all clients
1210
+ */
1211
+ send(payload: HotPayload): void;
1212
+ /**
1213
+ * Send custom event
1214
+ */
1215
+ send<T extends string>(event: T, payload?: InferCustomEventPayload<T>): void;
1216
+ /**
1217
+ * Handle custom event emitted by `import.meta.hot.send`
1218
+ */
1219
+ on<T extends string>(event: T, listener: (data: InferCustomEventPayload<T>, client: HotChannelClient, ...args: any[]) => void): void;
1220
+ on(event: 'connection', listener: () => void): void;
1221
+ /**
1222
+ * Unregister event listener
1223
+ */
1224
+ off(event: string, listener: Function): void;
1225
+ /**
1226
+ * Start listening for messages
1227
+ */
1228
+ listen(): void;
1229
+ /**
1230
+ * Disconnect all clients, called when server is closed or restarted.
1231
+ */
1232
+ close(): void;
1233
+ }
1234
+ /** @deprecated use `HotChannel` instead */
1235
+ type HMRChannel = HotChannel;
1236
+ interface ServerHotChannel extends HotChannel {
1237
+ api: {
1238
+ innerEmitter: EventEmitter;
1239
+ outsideEmitter: EventEmitter;
1240
+ };
1241
+ }
1242
+ /** @deprecated use `ServerHotChannel` instead */
1243
+ type ServerHMRChannel = ServerHotChannel;
1244
+ declare function createServerHotChannel(): ServerHotChannel;
1245
+ /** @deprecated use `environment.hot` instead */
1246
+ interface HotBroadcaster extends HotChannel {
1247
+ readonly channels: HotChannel[];
1248
+ /**
1249
+ * A noop.
1250
+ * @deprecated
1251
+ */
1252
+ addChannel(channel: HotChannel): HotBroadcaster;
1253
+ close(): Promise<unknown[]>;
1254
+ }
1255
+ /** @deprecated use `environment.hot` instead */
1256
+ type HMRBroadcaster = HotBroadcaster;
1257
+
1258
+ declare class RemoteEnvironmentTransport {
1259
+ private readonly options;
1260
+ constructor(options: {
1261
+ send: (data: any) => void;
1262
+ onMessage: (handler: (data: any) => void) => void;
1263
+ });
1264
+ register(environment: DevEnvironment): void;
1265
+ }
1266
+
1267
+ interface DevEnvironmentContext {
1268
+ hot: false | HotChannel;
1269
+ options?: EnvironmentOptions;
1270
+ runner?: FetchModuleOptions & {
1271
+ transport?: RemoteEnvironmentTransport;
1272
+ };
1273
+ depsOptimizer?: DepsOptimizer;
1274
+ }
1275
+ declare class DevEnvironment extends BaseEnvironment {
1276
+ mode: "dev";
1277
+ moduleGraph: EnvironmentModuleGraph;
1278
+ depsOptimizer?: DepsOptimizer;
1279
+ get pluginContainer(): EnvironmentPluginContainer;
1280
+ /**
1281
+ * Hot channel for this environment. If not provided or disabled,
1282
+ * it will be a noop channel that does nothing.
1283
+ *
1284
+ * @example
1285
+ * environment.hot.send({ type: 'full-reload' })
1286
+ */
1287
+ hot: HotChannel;
1288
+ constructor(name: string, config: ResolvedConfig, context: DevEnvironmentContext);
1289
+ init(options?: {
1290
+ watcher?: FSWatcher;
1291
+ }): Promise<void>;
1292
+ fetchModule(id: string, importer?: string, options?: FetchFunctionOptions): Promise<FetchResult>;
1293
+ reloadModule(module: EnvironmentModuleNode): Promise<void>;
1294
+ transformRequest(url: string): Promise<TransformResult | null>;
1295
+ warmupRequest(url: string): Promise<void>;
1296
+ close(): Promise<void>;
1297
+ /**
1298
+ * Calling `await environment.waitForRequestsIdle(id)` will wait until all static imports
1299
+ * are processed after the first transformRequest call. If called from a load or transform
1300
+ * plugin hook, the id needs to be passed as a parameter to avoid deadlocks.
1301
+ * Calling this function after the first static imports section of the module graph has been
1302
+ * processed will resolve immediately.
1303
+ * @experimental
1304
+ */
1305
+ waitForRequestsIdle(ignoredId?: string): Promise<void>;
1306
+ }
1307
+
1308
+ interface RollupCommonJSOptions {
1309
+ /**
1310
+ * A minimatch pattern, or array of patterns, which specifies the files in
1311
+ * the build the plugin should operate on. By default, all files with
1312
+ * extension `".cjs"` or those in `extensions` are included, but you can
1313
+ * narrow this list by only including specific files. These files will be
1314
+ * analyzed and transpiled if either the analysis does not find ES module
1315
+ * specific statements or `transformMixedEsModules` is `true`.
1316
+ * @default undefined
1317
+ */
1318
+ include?: string | RegExp | readonly (string | RegExp)[]
1319
+ /**
1320
+ * A minimatch pattern, or array of patterns, which specifies the files in
1321
+ * the build the plugin should _ignore_. By default, all files with
1322
+ * extensions other than those in `extensions` or `".cjs"` are ignored, but you
1323
+ * can exclude additional files. See also the `include` option.
1324
+ * @default undefined
1325
+ */
1326
+ exclude?: string | RegExp | readonly (string | RegExp)[]
1327
+ /**
1328
+ * For extensionless imports, search for extensions other than .js in the
1329
+ * order specified. Note that you need to make sure that non-JavaScript files
1330
+ * are transpiled by another plugin first.
1331
+ * @default [ '.js' ]
1332
+ */
1333
+ extensions?: ReadonlyArray<string>
1334
+ /**
1335
+ * If true then uses of `global` won't be dealt with by this plugin
1336
+ * @default false
1337
+ */
1338
+ ignoreGlobal?: boolean
1339
+ /**
1340
+ * If false, skips source map generation for CommonJS modules. This will
1341
+ * improve performance.
1342
+ * @default true
1343
+ */
1344
+ sourceMap?: boolean
1345
+ /**
1346
+ * Some `require` calls cannot be resolved statically to be translated to
1347
+ * imports.
1348
+ * When this option is set to `false`, the generated code will either
1349
+ * directly throw an error when such a call is encountered or, when
1350
+ * `dynamicRequireTargets` is used, when such a call cannot be resolved with a
1351
+ * configured dynamic require target.
1352
+ * Setting this option to `true` will instead leave the `require` call in the
1353
+ * code or use it as a fallback for `dynamicRequireTargets`.
1354
+ * @default false
1355
+ */
1356
+ ignoreDynamicRequires?: boolean
1357
+ /**
1358
+ * Instructs the plugin whether to enable mixed module transformations. This
1359
+ * is useful in scenarios with modules that contain a mix of ES `import`
1360
+ * statements and CommonJS `require` expressions. Set to `true` if `require`
1361
+ * calls should be transformed to imports in mixed modules, or `false` if the
1362
+ * `require` expressions should survive the transformation. The latter can be
1363
+ * important if the code contains environment detection, or you are coding
1364
+ * for an environment with special treatment for `require` calls such as
1365
+ * ElectronJS. See also the `ignore` option.
1366
+ * @default false
1367
+ */
1368
+ transformMixedEsModules?: boolean
1369
+ /**
1370
+ * By default, this plugin will try to hoist `require` statements as imports
1371
+ * to the top of each file. While this works well for many code bases and
1372
+ * allows for very efficient ESM output, it does not perfectly capture
1373
+ * CommonJS semantics as the order of side effects like log statements may
1374
+ * change. But it is especially problematic when there are circular `require`
1375
+ * calls between CommonJS modules as those often rely on the lazy execution of
1376
+ * nested `require` calls.
1377
+ *
1378
+ * Setting this option to `true` will wrap all CommonJS files in functions
1379
+ * which are executed when they are required for the first time, preserving
1380
+ * NodeJS semantics. Note that this can have an impact on the size and
1381
+ * performance of the generated code.
1382
+ *
1383
+ * The default value of `"auto"` will only wrap CommonJS files when they are
1384
+ * part of a CommonJS dependency cycle, e.g. an index file that is required by
1385
+ * many of its dependencies. All other CommonJS files are hoisted. This is the
1386
+ * recommended setting for most code bases.
1387
+ *
1388
+ * `false` will entirely prevent wrapping and hoist all files. This may still
1389
+ * work depending on the nature of cyclic dependencies but will often cause
1390
+ * problems.
1391
+ *
1392
+ * You can also provide a minimatch pattern, or array of patterns, to only
1393
+ * specify a subset of files which should be wrapped in functions for proper
1394
+ * `require` semantics.
1395
+ *
1396
+ * `"debug"` works like `"auto"` but after bundling, it will display a warning
1397
+ * containing a list of ids that have been wrapped which can be used as
1398
+ * minimatch pattern for fine-tuning.
1399
+ * @default "auto"
1400
+ */
1401
+ strictRequires?: boolean | string | RegExp | readonly (string | RegExp)[]
1402
+ /**
1403
+ * Sometimes you have to leave require statements unconverted. Pass an array
1404
+ * containing the IDs or a `id => boolean` function.
1405
+ * @default []
1406
+ */
1407
+ ignore?: ReadonlyArray<string> | ((id: string) => boolean)
1408
+ /**
1409
+ * In most cases, where `require` calls are inside a `try-catch` clause,
1410
+ * they should be left unconverted as it requires an optional dependency
1411
+ * that may or may not be installed beside the rolled up package.
1412
+ * Due to the conversion of `require` to a static `import` - the call is
1413
+ * hoisted to the top of the file, outside the `try-catch` clause.
1414
+ *
1415
+ * - `true`: Default. All `require` calls inside a `try` will be left unconverted.
1416
+ * - `false`: All `require` calls inside a `try` will be converted as if the
1417
+ * `try-catch` clause is not there.
1418
+ * - `remove`: Remove all `require` calls from inside any `try` block.
1419
+ * - `string[]`: Pass an array containing the IDs to left unconverted.
1420
+ * - `((id: string) => boolean|'remove')`: Pass a function that controls
1421
+ * individual IDs.
1422
+ *
1423
+ * @default true
1424
+ */
1425
+ ignoreTryCatch?:
1426
+ | boolean
1427
+ | 'remove'
1428
+ | ReadonlyArray<string>
1429
+ | ((id: string) => boolean | 'remove')
1430
+ /**
1431
+ * Controls how to render imports from external dependencies. By default,
1432
+ * this plugin assumes that all external dependencies are CommonJS. This
1433
+ * means they are rendered as default imports to be compatible with e.g.
1434
+ * NodeJS where ES modules can only import a default export from a CommonJS
1435
+ * dependency.
1436
+ *
1437
+ * If you set `esmExternals` to `true`, this plugin assumes that all
1438
+ * external dependencies are ES modules and respect the
1439
+ * `requireReturnsDefault` option. If that option is not set, they will be
1440
+ * rendered as namespace imports.
1441
+ *
1442
+ * You can also supply an array of ids to be treated as ES modules, or a
1443
+ * function that will be passed each external id to determine whether it is
1444
+ * an ES module.
1445
+ * @default false
1446
+ */
1447
+ esmExternals?: boolean | ReadonlyArray<string> | ((id: string) => boolean)
1448
+ /**
1449
+ * Controls what is returned when requiring an ES module from a CommonJS file.
1450
+ * When using the `esmExternals` option, this will also apply to external
1451
+ * modules. By default, this plugin will render those imports as namespace
1452
+ * imports i.e.
1453
+ *
1454
+ * ```js
1455
+ * // input
1456
+ * const foo = require('foo');
1457
+ *
1458
+ * // output
1459
+ * import * as foo from 'foo';
1460
+ * ```
1461
+ *
1462
+ * However, there are some situations where this may not be desired.
1463
+ * For these situations, you can change Rollup's behaviour either globally or
1464
+ * per module. To change it globally, set the `requireReturnsDefault` option
1465
+ * to one of the following values:
1466
+ *
1467
+ * - `false`: This is the default, requiring an ES module returns its
1468
+ * namespace. This is the only option that will also add a marker
1469
+ * `__esModule: true` to the namespace to support interop patterns in
1470
+ * CommonJS modules that are transpiled ES modules.
1471
+ * - `"namespace"`: Like `false`, requiring an ES module returns its
1472
+ * namespace, but the plugin does not add the `__esModule` marker and thus
1473
+ * creates more efficient code. For external dependencies when using
1474
+ * `esmExternals: true`, no additional interop code is generated.
1475
+ * - `"auto"`: This is complementary to how `output.exports: "auto"` works in
1476
+ * Rollup: If a module has a default export and no named exports, requiring
1477
+ * that module returns the default export. In all other cases, the namespace
1478
+ * is returned. For external dependencies when using `esmExternals: true`, a
1479
+ * corresponding interop helper is added.
1480
+ * - `"preferred"`: If a module has a default export, requiring that module
1481
+ * always returns the default export, no matter whether additional named
1482
+ * exports exist. This is similar to how previous versions of this plugin
1483
+ * worked. Again for external dependencies when using `esmExternals: true`,
1484
+ * an interop helper is added.
1485
+ * - `true`: This will always try to return the default export on require
1486
+ * without checking if it actually exists. This can throw at build time if
1487
+ * there is no default export. This is how external dependencies are handled
1488
+ * when `esmExternals` is not used. The advantage over the other options is
1489
+ * that, like `false`, this does not add an interop helper for external
1490
+ * dependencies, keeping the code lean.
1491
+ *
1492
+ * To change this for individual modules, you can supply a function for
1493
+ * `requireReturnsDefault` instead. This function will then be called once for
1494
+ * each required ES module or external dependency with the corresponding id
1495
+ * and allows you to return different values for different modules.
1496
+ * @default false
1497
+ */
1498
+ requireReturnsDefault?:
1499
+ | boolean
1500
+ | 'auto'
1501
+ | 'preferred'
1502
+ | 'namespace'
1503
+ | ((id: string) => boolean | 'auto' | 'preferred' | 'namespace')
1504
+
1505
+ /**
1506
+ * @default "auto"
1507
+ */
1508
+ defaultIsModuleExports?: boolean | 'auto' | ((id: string) => boolean | 'auto')
1509
+ /**
1510
+ * Some modules contain dynamic `require` calls, or require modules that
1511
+ * contain circular dependencies, which are not handled well by static
1512
+ * imports. Including those modules as `dynamicRequireTargets` will simulate a
1513
+ * CommonJS (NodeJS-like) environment for them with support for dynamic
1514
+ * dependencies. It also enables `strictRequires` for those modules.
1515
+ *
1516
+ * Note: In extreme cases, this feature may result in some paths being
1517
+ * rendered as absolute in the final bundle. The plugin tries to avoid
1518
+ * exposing paths from the local machine, but if you are `dynamicRequirePaths`
1519
+ * with paths that are far away from your project's folder, that may require
1520
+ * replacing strings like `"/Users/John/Desktop/foo-project/"` -\> `"/"`.
1521
+ */
1522
+ dynamicRequireTargets?: string | ReadonlyArray<string>
1523
+ /**
1524
+ * To avoid long paths when using the `dynamicRequireTargets` option, you can use this option to specify a directory
1525
+ * that is a common parent for all files that use dynamic require statements. Using a directory higher up such as `/`
1526
+ * may lead to unnecessarily long paths in the generated code and may expose directory names on your machine like your
1527
+ * home directory name. By default, it uses the current working directory.
1528
+ */
1529
+ dynamicRequireRoot?: string
1866
1530
  }
1867
- interface ServerHMRChannel extends HMRChannel {
1868
- api: {
1869
- innerEmitter: EventEmitter;
1870
- outsideEmitter: EventEmitter;
1871
- };
1531
+
1532
+ interface RollupDynamicImportVarsOptions {
1533
+ /**
1534
+ * Files to include in this plugin (default all).
1535
+ * @default []
1536
+ */
1537
+ include?: string | RegExp | (string | RegExp)[]
1538
+ /**
1539
+ * Files to exclude in this plugin (default none).
1540
+ * @default []
1541
+ */
1542
+ exclude?: string | RegExp | (string | RegExp)[]
1543
+ /**
1544
+ * 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.
1545
+ * @default false
1546
+ */
1547
+ warnOnError?: boolean
1872
1548
  }
1873
1549
 
1874
- type WebSocketCustomListener<T> = (data: T, client: WebSocketClient) => void;
1875
- interface WebSocketServer extends HMRChannel {
1876
- /**
1877
- * Listen on port and host
1878
- */
1879
- listen(): void;
1550
+ // Modified and inlined to avoid extra dependency
1551
+ // Source: https://github.com/terser/terser/blob/master/tools/terser.d.ts
1552
+ // BSD Licensed https://github.com/terser/terser/blob/master/LICENSE
1553
+
1554
+ declare namespace Terser {
1555
+ export type ECMA = 5 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020
1556
+
1557
+ export type ConsoleProperty = keyof typeof console
1558
+ type DropConsoleOption = boolean | ConsoleProperty[]
1559
+
1560
+ export interface ParseOptions {
1561
+ bare_returns?: boolean
1562
+ /** @deprecated legacy option. Currently, all supported EcmaScript is valid to parse. */
1563
+ ecma?: ECMA
1564
+ html5_comments?: boolean
1565
+ shebang?: boolean
1566
+ }
1567
+
1568
+ export interface CompressOptions {
1569
+ arguments?: boolean
1570
+ arrows?: boolean
1571
+ booleans_as_integers?: boolean
1572
+ booleans?: boolean
1573
+ collapse_vars?: boolean
1574
+ comparisons?: boolean
1575
+ computed_props?: boolean
1576
+ conditionals?: boolean
1577
+ dead_code?: boolean
1578
+ defaults?: boolean
1579
+ directives?: boolean
1580
+ drop_console?: DropConsoleOption
1581
+ drop_debugger?: boolean
1582
+ ecma?: ECMA
1583
+ evaluate?: boolean
1584
+ expression?: boolean
1585
+ global_defs?: object
1586
+ hoist_funs?: boolean
1587
+ hoist_props?: boolean
1588
+ hoist_vars?: boolean
1589
+ ie8?: boolean
1590
+ if_return?: boolean
1591
+ inline?: boolean | InlineFunctions
1592
+ join_vars?: boolean
1593
+ keep_classnames?: boolean | RegExp
1594
+ keep_fargs?: boolean
1595
+ keep_fnames?: boolean | RegExp
1596
+ keep_infinity?: boolean
1597
+ loops?: boolean
1598
+ module?: boolean
1599
+ negate_iife?: boolean
1600
+ passes?: number
1601
+ properties?: boolean
1602
+ pure_funcs?: string[]
1603
+ pure_new?: boolean
1604
+ pure_getters?: boolean | 'strict'
1605
+ reduce_funcs?: boolean
1606
+ reduce_vars?: boolean
1607
+ sequences?: boolean | number
1608
+ side_effects?: boolean
1609
+ switches?: boolean
1610
+ toplevel?: boolean
1611
+ top_retain?: null | string | string[] | RegExp
1612
+ typeofs?: boolean
1613
+ unsafe_arrows?: boolean
1614
+ unsafe?: boolean
1615
+ unsafe_comps?: boolean
1616
+ unsafe_Function?: boolean
1617
+ unsafe_math?: boolean
1618
+ unsafe_symbols?: boolean
1619
+ unsafe_methods?: boolean
1620
+ unsafe_proto?: boolean
1621
+ unsafe_regexp?: boolean
1622
+ unsafe_undefined?: boolean
1623
+ unused?: boolean
1624
+ }
1625
+
1626
+ export enum InlineFunctions {
1627
+ Disabled = 0,
1628
+ SimpleFunctions = 1,
1629
+ WithArguments = 2,
1630
+ WithArgumentsAndVariables = 3,
1631
+ }
1632
+
1633
+ export interface MangleOptions {
1634
+ eval?: boolean
1635
+ keep_classnames?: boolean | RegExp
1636
+ keep_fnames?: boolean | RegExp
1637
+ module?: boolean
1638
+ nth_identifier?: SimpleIdentifierMangler | WeightedIdentifierMangler
1639
+ properties?: boolean | ManglePropertiesOptions
1640
+ reserved?: string[]
1641
+ safari10?: boolean
1642
+ toplevel?: boolean
1643
+ }
1644
+
1645
+ /**
1646
+ * An identifier mangler for which the output is invariant with respect to the source code.
1647
+ */
1648
+ export interface SimpleIdentifierMangler {
1880
1649
  /**
1881
- * Get all connected clients.
1650
+ * Obtains the nth most favored (usually shortest) identifier to rename a variable to.
1651
+ * The mangler will increment n and retry until the return value is not in use in scope, and is not a reserved word.
1652
+ * This function is expected to be stable; Evaluating get(n) === get(n) should always return true.
1653
+ * @param n The ordinal of the identifier.
1882
1654
  */
1883
- clients: Set<WebSocketClient>;
1655
+ get(n: number): string
1656
+ }
1657
+
1658
+ /**
1659
+ * An identifier mangler that leverages character frequency analysis to determine identifier precedence.
1660
+ */
1661
+ export interface WeightedIdentifierMangler extends SimpleIdentifierMangler {
1884
1662
  /**
1885
- * Disconnect all clients and terminate the server.
1663
+ * Modifies the internal weighting of the input characters by the specified delta.
1664
+ * Will be invoked on the entire printed AST, and then deduct mangleable identifiers.
1665
+ * @param chars The characters to modify the weighting of.
1666
+ * @param delta The numeric weight to add to the characters.
1886
1667
  */
1887
- close(): Promise<void>;
1668
+ consider(chars: string, delta: number): number
1888
1669
  /**
1889
- * Handle custom event emitted by `import.meta.hot.send`
1670
+ * Resets character weights.
1890
1671
  */
1891
- on: WebSocket.Server['on'] & {
1892
- <T extends string>(event: T, listener: WebSocketCustomListener<InferCustomEventPayload<T>>): void;
1893
- };
1672
+ reset(): void
1894
1673
  /**
1895
- * Unregister event listener.
1674
+ * Sorts identifiers by character frequency, in preparation for calls to get(n).
1896
1675
  */
1897
- off: WebSocket.Server['off'] & {
1898
- (event: string, listener: Function): void;
1899
- };
1676
+ sort(): void
1677
+ }
1678
+
1679
+ export interface ManglePropertiesOptions {
1680
+ builtins?: boolean
1681
+ debug?: boolean
1682
+ keep_quoted?: boolean | 'strict'
1683
+ nth_identifier?: SimpleIdentifierMangler | WeightedIdentifierMangler
1684
+ regex?: RegExp | string
1685
+ reserved?: string[]
1686
+ }
1687
+
1688
+ export interface FormatOptions {
1689
+ ascii_only?: boolean
1690
+ /** @deprecated Not implemented anymore */
1691
+ beautify?: boolean
1692
+ braces?: boolean
1693
+ comments?:
1694
+ | boolean
1695
+ | 'all'
1696
+ | 'some'
1697
+ | RegExp
1698
+ | ((
1699
+ node: any,
1700
+ comment: {
1701
+ value: string
1702
+ type: 'comment1' | 'comment2' | 'comment3' | 'comment4'
1703
+ pos: number
1704
+ line: number
1705
+ col: number
1706
+ },
1707
+ ) => boolean)
1708
+ ecma?: ECMA
1709
+ ie8?: boolean
1710
+ keep_numbers?: boolean
1711
+ indent_level?: number
1712
+ indent_start?: number
1713
+ inline_script?: boolean
1714
+ keep_quoted_props?: boolean
1715
+ max_line_len?: number | false
1716
+ preamble?: string
1717
+ preserve_annotations?: boolean
1718
+ quote_keys?: boolean
1719
+ quote_style?: OutputQuoteStyle
1720
+ safari10?: boolean
1721
+ semicolons?: boolean
1722
+ shebang?: boolean
1723
+ shorthand?: boolean
1724
+ source_map?: SourceMapOptions
1725
+ webkit?: boolean
1726
+ width?: number
1727
+ wrap_iife?: boolean
1728
+ wrap_func_args?: boolean
1729
+ }
1730
+
1731
+ export enum OutputQuoteStyle {
1732
+ PreferDouble = 0,
1733
+ AlwaysSingle = 1,
1734
+ AlwaysDouble = 2,
1735
+ AlwaysOriginal = 3,
1736
+ }
1737
+
1738
+ export interface MinifyOptions {
1739
+ compress?: boolean | CompressOptions
1740
+ ecma?: ECMA
1741
+ enclose?: boolean | string
1742
+ ie8?: boolean
1743
+ keep_classnames?: boolean | RegExp
1744
+ keep_fnames?: boolean | RegExp
1745
+ mangle?: boolean | MangleOptions
1746
+ module?: boolean
1747
+ nameCache?: object
1748
+ format?: FormatOptions
1749
+ /** @deprecated */
1750
+ output?: FormatOptions
1751
+ parse?: ParseOptions
1752
+ safari10?: boolean
1753
+ sourceMap?: boolean | SourceMapOptions
1754
+ toplevel?: boolean
1755
+ }
1756
+
1757
+ export interface MinifyOutput {
1758
+ code?: string
1759
+ map?: object | string
1760
+ decoded_map?: object | null
1761
+ }
1762
+
1763
+ export interface SourceMapOptions {
1764
+ /** Source map object, 'inline' or source map file content */
1765
+ content?: object | string
1766
+ includeSources?: boolean
1767
+ filename?: string
1768
+ root?: string
1769
+ asObject?: boolean
1770
+ url?: string | 'inline'
1771
+ }
1900
1772
  }
1901
- interface WebSocketClient {
1902
- /**
1903
- * Send event to the client
1904
- */
1905
- send(payload: HMRPayload): void;
1906
- /**
1907
- * Send custom event
1908
- */
1909
- send(event: string, payload?: CustomPayload['data']): void;
1773
+
1774
+ interface TerserOptions extends Terser.MinifyOptions {
1910
1775
  /**
1911
- * The raw WebSocket instance
1912
- * @advanced
1776
+ * Vite-specific option to specify the max number of workers to spawn
1777
+ * when minifying files with terser.
1778
+ *
1779
+ * @default number of CPUs minus 1
1913
1780
  */
1914
- socket: WebSocket;
1781
+ maxWorkers?: number;
1915
1782
  }
1916
1783
 
1917
- interface ServerOptions extends CommonServerOptions {
1918
- /**
1919
- * Configure HMR-specific options (port, host, path & protocol)
1920
- */
1921
- hmr?: HmrOptions | boolean;
1922
- /**
1923
- * Warm-up files to transform and cache the results in advance. This improves the
1924
- * initial page load during server starts and prevents transform waterfalls.
1925
- * @deprecated use dev.warmup / environment.ssr.dev.warmup
1926
- */
1927
- warmup?: {
1928
- /**
1929
- * The files to be transformed and used on the client-side. Supports glob patterns.
1930
- */
1931
- clientFiles?: string[];
1932
- /**
1933
- * The files to be transformed and used in SSR. Supports glob patterns.
1934
- */
1935
- ssrFiles?: string[];
1936
- };
1937
- /**
1938
- * chokidar watch options or null to disable FS watching
1939
- * https://github.com/paulmillr/chokidar#api
1940
- */
1941
- watch?: WatchOptions | null;
1942
- /**
1943
- * Create Vite dev server to be used as a middleware in an existing server
1944
- * @default false
1945
- */
1946
- middlewareMode?: boolean | {
1947
- /**
1948
- * Parent server instance to attach to
1949
- *
1950
- * This is needed to proxy WebSocket connections to the parent server.
1951
- */
1952
- server: http.Server;
1784
+ /** Cache for package.json resolution and package.json contents */
1785
+ type PackageCache = Map<string, PackageData>;
1786
+ interface PackageData {
1787
+ dir: string;
1788
+ hasSideEffects: (id: string) => boolean | 'no-treeshake' | null;
1789
+ webResolvedImports: Record<string, string | undefined>;
1790
+ nodeResolvedImports: Record<string, string | undefined>;
1791
+ setResolvedCache: (key: string, entry: string, targetWeb: boolean) => void;
1792
+ getResolvedCache: (key: string, targetWeb: boolean) => string | undefined;
1793
+ data: {
1794
+ [field: string]: any;
1795
+ name: string;
1796
+ type: string;
1797
+ version: string;
1798
+ main: string;
1799
+ module: string;
1800
+ browser: string | Record<string, string | false>;
1801
+ exports: string | Record<string, any> | string[];
1802
+ imports: Record<string, any>;
1803
+ dependencies: Record<string, string>;
1953
1804
  };
1805
+ }
1806
+
1807
+ interface BuildEnvironmentOptions {
1954
1808
  /**
1955
- * Options for files served via '/\@fs/'.
1956
- */
1957
- fs?: FileSystemServeOptions;
1958
- /**
1959
- * Origin for the generated asset URLs.
1809
+ * Compatibility transform target. The transform is performed with esbuild
1810
+ * and the lowest supported target is es2015/es6. Note this only handles
1811
+ * syntax transformation and does not cover polyfills (except for dynamic
1812
+ * import)
1960
1813
  *
1961
- * @example `http://127.0.0.1:8080`
1962
- */
1963
- origin?: string;
1964
- /**
1965
- * Pre-transform known direct imports
1966
- * @default true
1967
- * @deprecated use dev.preTransformRequests
1968
- */
1969
- preTransformRequests?: boolean;
1970
- /**
1971
- * Whether or not to ignore-list source files in the dev server sourcemap, used to populate
1972
- * the [`x_google_ignoreList` source map extension](https://developer.chrome.com/blog/devtools-better-angular-debugging/#the-x_google_ignorelist-source-map-extension).
1814
+ * Default: 'modules' - Similar to `@babel/preset-env`'s targets.esmodules,
1815
+ * transpile targeting browsers that natively support dynamic es module imports.
1816
+ * https://caniuse.com/es6-module-dynamic-import
1973
1817
  *
1974
- * By default, it excludes all paths containing `node_modules`. You can pass `false` to
1975
- * disable this behavior, or, for full control, a function that takes the source path and
1976
- * sourcemap path and returns whether to ignore the source path.
1977
- * @deprecated use dev.sourcemapIgnoreList
1818
+ * Another special value is 'esnext' - which only performs minimal transpiling
1819
+ * (for minification compat) and assumes native dynamic imports support.
1820
+ *
1821
+ * For custom targets, see https://esbuild.github.io/api/#target and
1822
+ * https://esbuild.github.io/content-types/#javascript for more details.
1823
+ * @default 'modules'
1978
1824
  */
1979
- sourcemapIgnoreList?: false | ((sourcePath: string, sourcemapPath: string) => boolean);
1825
+ target?: 'modules' | esbuild_TransformOptions['target'] | false;
1980
1826
  /**
1981
- * Run HMR tasks, by default the HMR propagation is done in parallel for all environments
1982
- * @experimental
1827
+ * whether to inject module preload polyfill.
1828
+ * Note: does not apply to library mode.
1829
+ * @default true
1830
+ * @deprecated use `modulePreload.polyfill` instead
1983
1831
  */
1984
- hotUpdateEnvironments?: (server: ViteDevServer, hmr: (environment: DevEnvironment) => Promise<void>) => Promise<void>;
1985
- }
1986
- interface ResolvedServerOptions extends Omit<ServerOptions, 'fs' | 'middlewareMode' | 'sourcemapIgnoreList'> {
1987
- fs: Required<FileSystemServeOptions>;
1988
- middlewareMode: NonNullable<ServerOptions['middlewareMode']>;
1989
- sourcemapIgnoreList: Exclude<ServerOptions['sourcemapIgnoreList'], false | undefined>;
1990
- }
1991
- interface FileSystemServeOptions {
1832
+ polyfillModulePreload?: boolean;
1992
1833
  /**
1993
- * Strictly restrict file accessing outside of allowing paths.
1994
- *
1995
- * Set to `false` to disable the warning
1996
- *
1834
+ * Configure module preload
1835
+ * Note: does not apply to library mode.
1997
1836
  * @default true
1998
1837
  */
1999
- strict?: boolean;
1838
+ modulePreload?: boolean | ModulePreloadOptions;
2000
1839
  /**
2001
- * Restrict accessing files outside the allowed directories.
2002
- *
2003
- * Accepts absolute path or a path relative to project root.
2004
- * Will try to search up for workspace root by default.
1840
+ * Directory relative from `root` where build output will be placed. If the
1841
+ * directory exists, it will be removed before the build.
1842
+ * @default 'dist'
2005
1843
  */
2006
- allow?: string[];
1844
+ outDir?: string;
2007
1845
  /**
2008
- * Restrict accessing files that matches the patterns.
2009
- *
2010
- * This will have higher priority than `allow`.
2011
- * picomatch patterns are supported.
2012
- *
2013
- * @default ['.env', '.env.*', '*.crt', '*.pem']
1846
+ * Directory relative from `outDir` where the built js/css/image assets will
1847
+ * be placed.
1848
+ * @default 'assets'
2014
1849
  */
2015
- deny?: string[];
1850
+ assetsDir?: string;
2016
1851
  /**
2017
- * Enable caching of fs calls. It is enabled by default if no custom watch ignored patterns are provided.
2018
- *
2019
- * @experimental
2020
- * @default undefined
1852
+ * Static asset files smaller than this number (in bytes) will be inlined as
1853
+ * base64 strings. Default limit is `4096` (4 KiB). Set to `0` to disable.
1854
+ * @default 4096
2021
1855
  */
2022
- cachedChecks?: boolean;
2023
- }
2024
- type ServerHook = (this: void, server: ViteDevServer) => (() => void) | void | Promise<(() => void) | void>;
2025
- type HttpServer = http.Server | Http2SecureServer;
2026
- interface ViteDevServer {
1856
+ assetsInlineLimit?: number | ((filePath: string, content: Buffer) => boolean | undefined);
2027
1857
  /**
2028
- * The resolved vite config object
1858
+ * Whether to code-split CSS. When enabled, CSS in async chunks will be
1859
+ * inlined as strings in the chunk and inserted via dynamically created
1860
+ * style tags when the chunk is loaded.
1861
+ * @default true
2029
1862
  */
2030
- config: ResolvedConfig;
1863
+ cssCodeSplit?: boolean;
2031
1864
  /**
2032
- * A connect app instance.
2033
- * - Can be used to attach custom middlewares to the dev server.
2034
- * - Can also be used as the handler function of a custom http server
2035
- * or as a middleware in any connect-style Node.js frameworks
2036
- *
2037
- * https://github.com/senchalabs/connect#use-middleware
1865
+ * An optional separate target for CSS minification.
1866
+ * As esbuild only supports configuring targets to mainstream
1867
+ * browsers, users may need this option when they are targeting
1868
+ * a niche browser that comes with most modern JavaScript features
1869
+ * but has poor CSS support, e.g. Android WeChat WebView, which
1870
+ * doesn't support the #RGBA syntax.
1871
+ * @default target
2038
1872
  */
2039
- middlewares: Connect.Server;
1873
+ cssTarget?: esbuild_TransformOptions['target'] | false;
2040
1874
  /**
2041
- * native Node http server instance
2042
- * will be null in middleware mode
1875
+ * Override CSS minification specifically instead of defaulting to `build.minify`,
1876
+ * so you can configure minification for JS and CSS separately.
1877
+ * @default 'esbuild'
2043
1878
  */
2044
- httpServer: HttpServer | null;
1879
+ cssMinify?: boolean | 'esbuild' | 'lightningcss';
2045
1880
  /**
2046
- * chokidar watcher instance
2047
- * https://github.com/paulmillr/chokidar#api
1881
+ * If `true`, a separate sourcemap file will be created. If 'inline', the
1882
+ * sourcemap will be appended to the resulting output file as data URI.
1883
+ * 'hidden' works like `true` except that the corresponding sourcemap
1884
+ * comments in the bundled files are suppressed.
1885
+ * @default false
2048
1886
  */
2049
- watcher: FSWatcher;
1887
+ sourcemap?: boolean | 'inline' | 'hidden';
2050
1888
  /**
2051
- * web socket server with `send(payload)` method
2052
- * @deprecated use `hot` instead
1889
+ * Set to `false` to disable minification, or specify the minifier to use.
1890
+ * Available options are 'terser' or 'esbuild'.
1891
+ * @default 'esbuild'
2053
1892
  */
2054
- ws: WebSocketServer;
1893
+ minify?: boolean | 'terser' | 'esbuild';
2055
1894
  /**
2056
- * HMR broadcaster that can be used to send custom HMR messages to the client
1895
+ * Options for terser
1896
+ * https://terser.org/docs/api-reference#minify-options
2057
1897
  *
2058
- * Always sends a message to at least a WebSocket client. Any third party can
2059
- * add a channel to the broadcaster to process messages
2060
- * @deprecated use `environment.hot` instead
1898
+ * In addition, you can also pass a `maxWorkers: number` option to specify the
1899
+ * max number of workers to spawn. Defaults to the number of CPUs minus 1.
2061
1900
  */
2062
- hot: HMRBroadcaster;
1901
+ terserOptions?: TerserOptions;
2063
1902
  /**
2064
- * Rollup plugin container that can run plugin hooks on a given file
2065
- * @deprecated use `environment.pluginContainer` instead
1903
+ * Will be merged with internal rollup options.
1904
+ * https://rollupjs.org/configuration-options/
2066
1905
  */
2067
- pluginContainer: PluginContainer;
1906
+ rollupOptions?: RollupOptions;
2068
1907
  /**
2069
- * Module execution environments attached to the Vite server.
1908
+ * Options to pass on to `@rollup/plugin-commonjs`
2070
1909
  */
2071
- environments: Record<'client' | 'ssr' | (string & {}), DevEnvironment>;
1910
+ commonjsOptions?: RollupCommonJSOptions;
2072
1911
  /**
2073
- * Module graph that tracks the import relationships, url to file mapping
2074
- * and hmr state.
2075
- * @deprecated use `environment.moduleGraph` instead
1912
+ * Options to pass on to `@rollup/plugin-dynamic-import-vars`
2076
1913
  */
2077
- moduleGraph: ModuleGraph;
1914
+ dynamicImportVarsOptions?: RollupDynamicImportVarsOptions;
2078
1915
  /**
2079
- * The resolved urls Vite prints on the CLI. null in middleware mode or
2080
- * before `server.listen` is called.
1916
+ * Whether to write bundle to disk
1917
+ * @default true
2081
1918
  */
2082
- resolvedUrls: ResolvedServerUrls | null;
1919
+ write?: boolean;
2083
1920
  /**
2084
- * Programmatically resolve, load and transform a URL and get the result
2085
- * without going through the http request pipeline.
2086
- * @deprecated use environment.transformRequest
1921
+ * Empty outDir on write.
1922
+ * @default true when outDir is a sub directory of project root
2087
1923
  */
2088
- transformRequest(url: string, options?: TransformOptions): Promise<TransformResult | null>;
1924
+ emptyOutDir?: boolean | null;
2089
1925
  /**
2090
- * Same as `transformRequest` but only warm up the URLs so the next request
2091
- * will already be cached. The function will never throw as it handles and
2092
- * reports errors internally.
2093
- * @deprecated use environment.warmupRequest
1926
+ * Copy the public directory to outDir on write.
1927
+ * @default true
2094
1928
  */
2095
- warmupRequest(url: string, options?: TransformOptions): Promise<void>;
1929
+ copyPublicDir?: boolean;
2096
1930
  /**
2097
- * Apply vite built-in HTML transforms and any plugin HTML transforms.
1931
+ * Whether to emit a .vite/manifest.json under assets dir to map hash-less filenames
1932
+ * to their hashed versions. Useful when you want to generate your own HTML
1933
+ * instead of using the one generated by Vite.
1934
+ *
1935
+ * Example:
1936
+ *
1937
+ * ```json
1938
+ * {
1939
+ * "main.js": {
1940
+ * "file": "main.68fe3fad.js",
1941
+ * "css": "main.e6b63442.css",
1942
+ * "imports": [...],
1943
+ * "dynamicImports": [...]
1944
+ * }
1945
+ * }
1946
+ * ```
1947
+ * @default false
2098
1948
  */
2099
- transformIndexHtml(url: string, html: string, originalUrl?: string): Promise<string>;
1949
+ manifest?: boolean | string;
2100
1950
  /**
2101
- * Transform module code into SSR format.
2102
- * TODO: expose this to any environment?
1951
+ * Build in library mode. The value should be the global name of the lib in
1952
+ * UMD mode. This will produce esm + cjs + umd bundle formats with default
1953
+ * configurations that are suitable for distributing libraries.
1954
+ * @default false
2103
1955
  */
2104
- ssrTransform(code: string, inMap: SourceMap | {
2105
- mappings: '';
2106
- } | null, url: string, originalCode?: string): Promise<TransformResult | null>;
1956
+ lib?: LibraryOptions | false;
2107
1957
  /**
2108
- * Load a given URL as an instantiated module for SSR.
1958
+ * Produce SSR oriented build. Note this requires specifying SSR entry via
1959
+ * `rollupOptions.input`.
1960
+ * @default false
2109
1961
  */
2110
- ssrLoadModule(url: string, opts?: {
2111
- fixStacktrace?: boolean;
2112
- }): Promise<Record<string, any>>;
1962
+ ssr?: boolean | string;
2113
1963
  /**
2114
- * Returns a fixed version of the given stack
1964
+ * Generate SSR manifest for determining style links and asset preload
1965
+ * directives in production.
1966
+ * @default false
2115
1967
  */
2116
- ssrRewriteStacktrace(stack: string): string;
1968
+ ssrManifest?: boolean | string;
2117
1969
  /**
2118
- * Mutates the given SSR error by rewriting the stacktrace
1970
+ * Emit assets during SSR.
1971
+ * @default false
2119
1972
  */
2120
- ssrFixStacktrace(e: Error): void;
1973
+ ssrEmitAssets?: boolean;
2121
1974
  /**
2122
- * Triggers HMR for a module in the module graph. You can use the `server.moduleGraph`
2123
- * API to retrieve the module to be reloaded. If `hmr` is false, this is a no-op.
1975
+ * Emit assets during build. Frameworks can set environments.ssr.build.emitAssets
1976
+ * By default, it is true for the client and false for other environments.
2124
1977
  */
2125
- reloadModule(module: ModuleNode): Promise<void>;
1978
+ emitAssets?: boolean;
2126
1979
  /**
2127
- * Triggers HMR for an environment module in the module graph.
2128
- * If `hmr` is false, this is a no-op.
1980
+ * Set to false to disable reporting compressed chunk sizes.
1981
+ * Can slightly improve build speed.
1982
+ * @default true
2129
1983
  */
2130
- reloadEnvironmentModule(module: EnvironmentModuleNode): Promise<void>;
1984
+ reportCompressedSize?: boolean;
2131
1985
  /**
2132
- * Start the server.
1986
+ * Adjust chunk size warning limit (in kB).
1987
+ * @default 500
2133
1988
  */
2134
- listen(port?: number, isRestart?: boolean): Promise<ViteDevServer>;
1989
+ chunkSizeWarningLimit?: number;
2135
1990
  /**
2136
- * Stop the server.
1991
+ * Rollup watch options
1992
+ * https://rollupjs.org/configuration-options/#watch
1993
+ * @default null
2137
1994
  */
2138
- close(): Promise<void>;
1995
+ watch?: WatcherOptions | null;
2139
1996
  /**
2140
- * Print server urls
1997
+ * create the Build Environment instance
2141
1998
  */
2142
- printUrls(): void;
1999
+ createEnvironment?: (name: string, config: ResolvedConfig) => Promise<BuildEnvironment> | BuildEnvironment;
2000
+ }
2001
+ type BuildOptions = BuildEnvironmentOptions;
2002
+ interface LibraryOptions {
2143
2003
  /**
2144
- * Bind CLI shortcuts
2004
+ * Path of library entry
2145
2005
  */
2146
- bindCLIShortcuts(options?: BindCLIShortcutsOptions<ViteDevServer>): void;
2006
+ entry: InputOption;
2147
2007
  /**
2148
- * Restart the server.
2149
- *
2150
- * @param forceOptimize - force the optimizer to re-bundle, same as --force cli flag
2008
+ * The name of the exposed global variable. Required when the `formats` option includes
2009
+ * `umd` or `iife`
2151
2010
  */
2152
- restart(forceOptimize?: boolean): Promise<void>;
2011
+ name?: string;
2153
2012
  /**
2154
- * Open browser
2013
+ * Output bundle formats
2014
+ * @default ['es', 'umd']
2155
2015
  */
2156
- openBrowser(): void;
2016
+ formats?: LibraryFormats[];
2157
2017
  /**
2158
- * Calling `await server.waitForRequestsIdle(id)` will wait until all static imports
2159
- * are processed. If called from a load or transform plugin hook, the id needs to be
2160
- * passed as a parameter to avoid deadlocks. Calling this function after the first
2161
- * static imports section of the module graph has been processed will resolve immediately.
2018
+ * The name of the package file output. The default file name is the name option
2019
+ * of the project package.json. It can also be defined as a function taking the
2020
+ * format as an argument.
2021
+ */
2022
+ fileName?: string | ((format: ModuleFormat, entryName: string) => string);
2023
+ }
2024
+ type LibraryFormats = 'es' | 'cjs' | 'umd' | 'iife' | 'system';
2025
+ interface ModulePreloadOptions {
2026
+ /**
2027
+ * Whether to inject a module preload polyfill.
2028
+ * Note: does not apply to library mode.
2029
+ * @default true
2030
+ */
2031
+ polyfill?: boolean;
2032
+ /**
2033
+ * Resolve the list of dependencies to preload for a given dynamic import
2162
2034
  * @experimental
2163
- * @deprecated use environment.waitForRequestsIdle()
2164
2035
  */
2165
- waitForRequestsIdle: (ignoredId?: string) => Promise<void>;
2036
+ resolveDependencies?: ResolveModulePreloadDependenciesFn;
2037
+ }
2038
+ interface ResolvedModulePreloadOptions {
2039
+ polyfill: boolean;
2040
+ resolveDependencies?: ResolveModulePreloadDependenciesFn;
2041
+ }
2042
+ type ResolveModulePreloadDependenciesFn = (filename: string, deps: string[], context: {
2043
+ hostId: string;
2044
+ hostType: 'html' | 'js';
2045
+ }) => string[];
2046
+ interface ResolvedBuildEnvironmentOptions extends Required<Omit<BuildEnvironmentOptions, 'polyfillModulePreload'>> {
2047
+ modulePreload: false | ResolvedModulePreloadOptions;
2048
+ }
2049
+ interface ResolvedBuildOptions extends Required<Omit<BuildOptions, 'polyfillModulePreload'>> {
2050
+ modulePreload: false | ResolvedModulePreloadOptions;
2051
+ }
2052
+ /**
2053
+ * Bundles a single environment for production.
2054
+ * Returns a Promise containing the build result.
2055
+ */
2056
+ declare function build(inlineConfig?: InlineConfig): Promise<RollupOutput | RollupOutput[] | RollupWatcher>;
2057
+ type RenderBuiltAssetUrl = (filename: string, type: {
2058
+ type: 'asset' | 'public';
2059
+ hostId: string;
2060
+ hostType: 'js' | 'css' | 'html';
2061
+ ssr: boolean;
2062
+ }) => string | {
2063
+ relative?: boolean;
2064
+ runtime?: string;
2065
+ } | undefined;
2066
+ declare class BuildEnvironment extends BaseEnvironment {
2067
+ mode: "build";
2068
+ constructor(name: string, config: ResolvedConfig, setup?: {
2069
+ options?: EnvironmentOptions;
2070
+ });
2071
+ init(): Promise<void>;
2166
2072
  }
2167
- interface ResolvedServerUrls {
2168
- local: string[];
2169
- network: string[];
2073
+ interface ViteBuilder {
2074
+ environments: Record<string, BuildEnvironment>;
2075
+ config: ResolvedConfig;
2076
+ buildApp(): Promise<void>;
2077
+ build(environment: BuildEnvironment): Promise<RollupOutput | RollupOutput[] | RollupWatcher>;
2170
2078
  }
2171
- declare function createServer(inlineConfig?: InlineConfig): Promise<ViteDevServer>;
2079
+ interface BuilderOptions {
2080
+ sharedConfigBuild?: boolean;
2081
+ sharedPlugins?: boolean;
2082
+ entireApp?: boolean;
2083
+ buildApp?: (builder: ViteBuilder) => Promise<void>;
2084
+ }
2085
+ type ResolvedBuilderOptions = Required<BuilderOptions>;
2086
+ /**
2087
+ * Creates a ViteBuilder to orchestrate building multiple environments.
2088
+ */
2089
+ declare function createBuilder(inlineConfig?: InlineConfig): Promise<ViteBuilder>;
2172
2090
 
2173
- /** Cache for package.json resolution and package.json contents */
2174
- type PackageCache = Map<string, PackageData>;
2175
- interface PackageData {
2176
- dir: string;
2177
- hasSideEffects: (id: string) => boolean | 'no-treeshake' | null;
2178
- webResolvedImports: Record<string, string | undefined>;
2179
- nodeResolvedImports: Record<string, string | undefined>;
2180
- setResolvedCache: (key: string, entry: string, targetWeb: boolean) => void;
2181
- getResolvedCache: (key: string, targetWeb: boolean) => string | undefined;
2182
- data: {
2183
- [field: string]: any;
2184
- name: string;
2185
- type: string;
2186
- version: string;
2187
- main: string;
2188
- module: string;
2189
- browser: string | Record<string, string | false>;
2190
- exports: string | Record<string, any> | string[];
2191
- imports: Record<string, any>;
2192
- dependencies: Record<string, string>;
2193
- };
2091
+ type Environment = DevEnvironment | BuildEnvironment | UnknownEnvironment;
2092
+
2093
+ declare class EnvironmentPluginContainer {
2094
+ environment: Environment;
2095
+ plugins: Plugin[];
2096
+ watcher?: FSWatcher | undefined;
2097
+ private _pluginContextMap;
2098
+ private _resolvedRollupOptions?;
2099
+ private _processesing;
2100
+ private _seenResolves;
2101
+ private _moduleNodeToLoadAddedImports;
2102
+ getSortedPluginHooks: PluginHookUtils['getSortedPluginHooks'];
2103
+ getSortedPlugins: PluginHookUtils['getSortedPlugins'];
2104
+ moduleGraph: EnvironmentModuleGraph | undefined;
2105
+ watchFiles: Set<string>;
2106
+ minimalContext: MinimalPluginContext;
2107
+ private _started;
2108
+ private _buildStartPromise;
2109
+ private _closed;
2110
+ private _updateModuleLoadAddedImports;
2111
+ private _getAddedImports;
2112
+ getModuleInfo(id: string): ModuleInfo | null;
2113
+ private handleHookPromise;
2114
+ get options(): InputOptions;
2115
+ resolveRollupOptions(): Promise<InputOptions>;
2116
+ private _getPluginContext;
2117
+ private hookParallel;
2118
+ buildStart(_options?: InputOptions): Promise<void>;
2119
+ resolveId(rawId: string, importer?: string | undefined, options?: {
2120
+ attributes?: Record<string, string>;
2121
+ custom?: CustomPluginOptions;
2122
+ skip?: Set<Plugin>;
2123
+ isEntry?: boolean;
2124
+ }): Promise<PartialResolvedId | null>;
2125
+ load(id: string): Promise<LoadResult | null>;
2126
+ transform(code: string, id: string, options?: {
2127
+ inMap?: SourceDescription['map'];
2128
+ }): Promise<{
2129
+ code: string;
2130
+ map: SourceMap | {
2131
+ mappings: '';
2132
+ } | null;
2133
+ }>;
2134
+ watchChange(id: string, change: {
2135
+ event: 'create' | 'update' | 'delete';
2136
+ }): Promise<void>;
2137
+ close(): Promise<void>;
2138
+ }
2139
+ declare class PluginContainer {
2140
+ private environments;
2141
+ constructor(environments: Record<string, Environment>);
2142
+ private _getEnvironment;
2143
+ private _getPluginContainer;
2144
+ getModuleInfo(id: string): ModuleInfo | null;
2145
+ get options(): InputOptions;
2146
+ buildStart(_options?: InputOptions): Promise<void>;
2147
+ watchChange(id: string, change: {
2148
+ event: 'create' | 'update' | 'delete';
2149
+ }): Promise<void>;
2150
+ resolveId(rawId: string, importer?: string, options?: {
2151
+ attributes?: Record<string, string>;
2152
+ custom?: CustomPluginOptions;
2153
+ skip?: Set<Plugin>;
2154
+ ssr?: boolean;
2155
+ isEntry?: boolean;
2156
+ }): Promise<PartialResolvedId | null>;
2157
+ load(id: string, options?: {
2158
+ ssr?: boolean;
2159
+ }): Promise<LoadResult | null>;
2160
+ transform(code: string, id: string, options?: {
2161
+ ssr?: boolean;
2162
+ environment?: Environment;
2163
+ inMap?: SourceDescription['map'];
2164
+ }): Promise<{
2165
+ code: string;
2166
+ map: SourceMap | {
2167
+ mappings: '';
2168
+ } | null;
2169
+ }>;
2170
+ close(): Promise<void>;
2194
2171
  }
2195
2172
 
2196
- interface RollupCommonJSOptions {
2197
- /**
2198
- * A minimatch pattern, or array of patterns, which specifies the files in
2199
- * the build the plugin should operate on. By default, all files with
2200
- * extension `".cjs"` or those in `extensions` are included, but you can
2201
- * narrow this list by only including specific files. These files will be
2202
- * analyzed and transpiled if either the analysis does not find ES module
2203
- * specific statements or `transformMixedEsModules` is `true`.
2204
- * @default undefined
2205
- */
2206
- include?: string | RegExp | readonly (string | RegExp)[]
2207
- /**
2208
- * A minimatch pattern, or array of patterns, which specifies the files in
2209
- * the build the plugin should _ignore_. By default, all files with
2210
- * extensions other than those in `extensions` or `".cjs"` are ignored, but you
2211
- * can exclude additional files. See also the `include` option.
2212
- * @default undefined
2213
- */
2214
- exclude?: string | RegExp | readonly (string | RegExp)[]
2215
- /**
2216
- * For extensionless imports, search for extensions other than .js in the
2217
- * order specified. Note that you need to make sure that non-JavaScript files
2218
- * are transpiled by another plugin first.
2219
- * @default [ '.js' ]
2220
- */
2221
- extensions?: ReadonlyArray<string>
2222
- /**
2223
- * If true then uses of `global` won't be dealt with by this plugin
2224
- * @default false
2225
- */
2226
- ignoreGlobal?: boolean
2227
- /**
2228
- * If false, skips source map generation for CommonJS modules. This will
2229
- * improve performance.
2230
- * @default true
2231
- */
2232
- sourceMap?: boolean
2233
- /**
2234
- * Some `require` calls cannot be resolved statically to be translated to
2235
- * imports.
2236
- * When this option is set to `false`, the generated code will either
2237
- * directly throw an error when such a call is encountered or, when
2238
- * `dynamicRequireTargets` is used, when such a call cannot be resolved with a
2239
- * configured dynamic require target.
2240
- * Setting this option to `true` will instead leave the `require` call in the
2241
- * code or use it as a fallback for `dynamicRequireTargets`.
2242
- * @default false
2243
- */
2244
- ignoreDynamicRequires?: boolean
2245
- /**
2246
- * Instructs the plugin whether to enable mixed module transformations. This
2247
- * is useful in scenarios with modules that contain a mix of ES `import`
2248
- * statements and CommonJS `require` expressions. Set to `true` if `require`
2249
- * calls should be transformed to imports in mixed modules, or `false` if the
2250
- * `require` expressions should survive the transformation. The latter can be
2251
- * important if the code contains environment detection, or you are coding
2252
- * for an environment with special treatment for `require` calls such as
2253
- * ElectronJS. See also the `ignore` option.
2254
- * @default false
2255
- */
2256
- transformMixedEsModules?: boolean
2257
- /**
2258
- * By default, this plugin will try to hoist `require` statements as imports
2259
- * to the top of each file. While this works well for many code bases and
2260
- * allows for very efficient ESM output, it does not perfectly capture
2261
- * CommonJS semantics as the order of side effects like log statements may
2262
- * change. But it is especially problematic when there are circular `require`
2263
- * calls between CommonJS modules as those often rely on the lazy execution of
2264
- * nested `require` calls.
2265
- *
2266
- * Setting this option to `true` will wrap all CommonJS files in functions
2267
- * which are executed when they are required for the first time, preserving
2268
- * NodeJS semantics. Note that this can have an impact on the size and
2269
- * performance of the generated code.
2270
- *
2271
- * The default value of `"auto"` will only wrap CommonJS files when they are
2272
- * part of a CommonJS dependency cycle, e.g. an index file that is required by
2273
- * many of its dependencies. All other CommonJS files are hoisted. This is the
2274
- * recommended setting for most code bases.
2275
- *
2276
- * `false` will entirely prevent wrapping and hoist all files. This may still
2277
- * work depending on the nature of cyclic dependencies but will often cause
2278
- * problems.
2279
- *
2280
- * You can also provide a minimatch pattern, or array of patterns, to only
2281
- * specify a subset of files which should be wrapped in functions for proper
2282
- * `require` semantics.
2283
- *
2284
- * `"debug"` works like `"auto"` but after bundling, it will display a warning
2285
- * containing a list of ids that have been wrapped which can be used as
2286
- * minimatch pattern for fine-tuning.
2287
- * @default "auto"
2288
- */
2289
- strictRequires?: boolean | string | RegExp | readonly (string | RegExp)[]
2290
- /**
2291
- * Sometimes you have to leave require statements unconverted. Pass an array
2292
- * containing the IDs or a `id => boolean` function.
2293
- * @default []
2294
- */
2295
- ignore?: ReadonlyArray<string> | ((id: string) => boolean)
2296
- /**
2297
- * In most cases, where `require` calls are inside a `try-catch` clause,
2298
- * they should be left unconverted as it requires an optional dependency
2299
- * that may or may not be installed beside the rolled up package.
2300
- * Due to the conversion of `require` to a static `import` - the call is
2301
- * hoisted to the top of the file, outside the `try-catch` clause.
2302
- *
2303
- * - `true`: Default. All `require` calls inside a `try` will be left unconverted.
2304
- * - `false`: All `require` calls inside a `try` will be converted as if the
2305
- * `try-catch` clause is not there.
2306
- * - `remove`: Remove all `require` calls from inside any `try` block.
2307
- * - `string[]`: Pass an array containing the IDs to left unconverted.
2308
- * - `((id: string) => boolean|'remove')`: Pass a function that controls
2309
- * individual IDs.
2310
- *
2311
- * @default true
2312
- */
2313
- ignoreTryCatch?:
2314
- | boolean
2315
- | 'remove'
2316
- | ReadonlyArray<string>
2317
- | ((id: string) => boolean | 'remove')
2173
+ // Modified and inlined to avoid extra dependency
2174
+ // Source: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/ws/index.d.ts
2175
+
2176
+ declare const WebSocketAlias: typeof WebSocket
2177
+ interface WebSocketAlias extends WebSocket {}
2178
+
2179
+ // WebSocket socket.
2180
+ declare class WebSocket extends EventEmitter {
2181
+ /** The connection is not yet open. */
2182
+ static readonly CONNECTING: 0
2183
+ /** The connection is open and ready to communicate. */
2184
+ static readonly OPEN: 1
2185
+ /** The connection is in the process of closing. */
2186
+ static readonly CLOSING: 2
2187
+ /** The connection is closed. */
2188
+ static readonly CLOSED: 3
2189
+
2190
+ binaryType: 'nodebuffer' | 'arraybuffer' | 'fragments'
2191
+ readonly bufferedAmount: number
2192
+ readonly extensions: string
2193
+ /** Indicates whether the websocket is paused */
2194
+ readonly isPaused: boolean
2195
+ readonly protocol: string
2196
+ /** The current state of the connection */
2197
+ readonly readyState:
2198
+ | typeof WebSocket.CONNECTING
2199
+ | typeof WebSocket.OPEN
2200
+ | typeof WebSocket.CLOSING
2201
+ | typeof WebSocket.CLOSED
2202
+ readonly url: string
2203
+
2204
+ /** The connection is not yet open. */
2205
+ readonly CONNECTING: 0
2206
+ /** The connection is open and ready to communicate. */
2207
+ readonly OPEN: 1
2208
+ /** The connection is in the process of closing. */
2209
+ readonly CLOSING: 2
2210
+ /** The connection is closed. */
2211
+ readonly CLOSED: 3
2212
+
2213
+ onopen: ((event: WebSocket.Event) => void) | null
2214
+ onerror: ((event: WebSocket.ErrorEvent) => void) | null
2215
+ onclose: ((event: WebSocket.CloseEvent) => void) | null
2216
+ onmessage: ((event: WebSocket.MessageEvent) => void) | null
2217
+
2218
+ constructor(address: null)
2219
+ constructor(
2220
+ address: string | URL,
2221
+ options?: WebSocket.ClientOptions | ClientRequestArgs,
2222
+ )
2223
+ constructor(
2224
+ address: string | URL,
2225
+ protocols?: string | string[],
2226
+ options?: WebSocket.ClientOptions | ClientRequestArgs,
2227
+ )
2228
+
2229
+ close(code?: number, data?: string | Buffer): void
2230
+ ping(data?: any, mask?: boolean, cb?: (err: Error) => void): void
2231
+ pong(data?: any, mask?: boolean, cb?: (err: Error) => void): void
2232
+ send(data: any, cb?: (err?: Error) => void): void
2233
+ send(
2234
+ data: any,
2235
+ options: {
2236
+ mask?: boolean | undefined
2237
+ binary?: boolean | undefined
2238
+ compress?: boolean | undefined
2239
+ fin?: boolean | undefined
2240
+ },
2241
+ cb?: (err?: Error) => void,
2242
+ ): void
2243
+ terminate(): void
2244
+
2318
2245
  /**
2319
- * Controls how to render imports from external dependencies. By default,
2320
- * this plugin assumes that all external dependencies are CommonJS. This
2321
- * means they are rendered as default imports to be compatible with e.g.
2322
- * NodeJS where ES modules can only import a default export from a CommonJS
2323
- * dependency.
2324
- *
2325
- * If you set `esmExternals` to `true`, this plugin assumes that all
2326
- * external dependencies are ES modules and respect the
2327
- * `requireReturnsDefault` option. If that option is not set, they will be
2328
- * rendered as namespace imports.
2329
- *
2330
- * You can also supply an array of ids to be treated as ES modules, or a
2331
- * function that will be passed each external id to determine whether it is
2332
- * an ES module.
2333
- * @default false
2246
+ * Pause the websocket causing it to stop emitting events. Some events can still be
2247
+ * emitted after this is called, until all buffered data is consumed. This method
2248
+ * is a noop if the ready state is `CONNECTING` or `CLOSED`.
2334
2249
  */
2335
- esmExternals?: boolean | ReadonlyArray<string> | ((id: string) => boolean)
2250
+ pause(): void
2336
2251
  /**
2337
- * Controls what is returned when requiring an ES module from a CommonJS file.
2338
- * When using the `esmExternals` option, this will also apply to external
2339
- * modules. By default, this plugin will render those imports as namespace
2340
- * imports i.e.
2341
- *
2342
- * ```js
2343
- * // input
2344
- * const foo = require('foo');
2345
- *
2346
- * // output
2347
- * import * as foo from 'foo';
2348
- * ```
2349
- *
2350
- * However, there are some situations where this may not be desired.
2351
- * For these situations, you can change Rollup's behaviour either globally or
2352
- * per module. To change it globally, set the `requireReturnsDefault` option
2353
- * to one of the following values:
2354
- *
2355
- * - `false`: This is the default, requiring an ES module returns its
2356
- * namespace. This is the only option that will also add a marker
2357
- * `__esModule: true` to the namespace to support interop patterns in
2358
- * CommonJS modules that are transpiled ES modules.
2359
- * - `"namespace"`: Like `false`, requiring an ES module returns its
2360
- * namespace, but the plugin does not add the `__esModule` marker and thus
2361
- * creates more efficient code. For external dependencies when using
2362
- * `esmExternals: true`, no additional interop code is generated.
2363
- * - `"auto"`: This is complementary to how `output.exports: "auto"` works in
2364
- * Rollup: If a module has a default export and no named exports, requiring
2365
- * that module returns the default export. In all other cases, the namespace
2366
- * is returned. For external dependencies when using `esmExternals: true`, a
2367
- * corresponding interop helper is added.
2368
- * - `"preferred"`: If a module has a default export, requiring that module
2369
- * always returns the default export, no matter whether additional named
2370
- * exports exist. This is similar to how previous versions of this plugin
2371
- * worked. Again for external dependencies when using `esmExternals: true`,
2372
- * an interop helper is added.
2373
- * - `true`: This will always try to return the default export on require
2374
- * without checking if it actually exists. This can throw at build time if
2375
- * there is no default export. This is how external dependencies are handled
2376
- * when `esmExternals` is not used. The advantage over the other options is
2377
- * that, like `false`, this does not add an interop helper for external
2378
- * dependencies, keeping the code lean.
2379
- *
2380
- * To change this for individual modules, you can supply a function for
2381
- * `requireReturnsDefault` instead. This function will then be called once for
2382
- * each required ES module or external dependency with the corresponding id
2383
- * and allows you to return different values for different modules.
2384
- * @default false
2252
+ * Make a paused socket resume emitting events. This method is a noop if the ready
2253
+ * state is `CONNECTING` or `CLOSED`.
2385
2254
  */
2386
- requireReturnsDefault?:
2387
- | boolean
2388
- | 'auto'
2389
- | 'preferred'
2390
- | 'namespace'
2391
- | ((id: string) => boolean | 'auto' | 'preferred' | 'namespace')
2255
+ resume(): void
2256
+
2257
+ // HTML5 WebSocket events
2258
+ addEventListener(
2259
+ method: 'message',
2260
+ cb: (event: WebSocket.MessageEvent) => void,
2261
+ options?: WebSocket.EventListenerOptions,
2262
+ ): void
2263
+ addEventListener(
2264
+ method: 'close',
2265
+ cb: (event: WebSocket.CloseEvent) => void,
2266
+ options?: WebSocket.EventListenerOptions,
2267
+ ): void
2268
+ addEventListener(
2269
+ method: 'error',
2270
+ cb: (event: WebSocket.ErrorEvent) => void,
2271
+ options?: WebSocket.EventListenerOptions,
2272
+ ): void
2273
+ addEventListener(
2274
+ method: 'open',
2275
+ cb: (event: WebSocket.Event) => void,
2276
+ options?: WebSocket.EventListenerOptions,
2277
+ ): void
2278
+
2279
+ removeEventListener(
2280
+ method: 'message',
2281
+ cb: (event: WebSocket.MessageEvent) => void,
2282
+ ): void
2283
+ removeEventListener(
2284
+ method: 'close',
2285
+ cb: (event: WebSocket.CloseEvent) => void,
2286
+ ): void
2287
+ removeEventListener(
2288
+ method: 'error',
2289
+ cb: (event: WebSocket.ErrorEvent) => void,
2290
+ ): void
2291
+ removeEventListener(
2292
+ method: 'open',
2293
+ cb: (event: WebSocket.Event) => void,
2294
+ ): void
2295
+
2296
+ // Events
2297
+ on(
2298
+ event: 'close',
2299
+ listener: (this: WebSocket, code: number, reason: Buffer) => void,
2300
+ ): this
2301
+ on(event: 'error', listener: (this: WebSocket, err: Error) => void): this
2302
+ on(
2303
+ event: 'upgrade',
2304
+ listener: (this: WebSocket, request: IncomingMessage) => void,
2305
+ ): this
2306
+ on(
2307
+ event: 'message',
2308
+ listener: (
2309
+ this: WebSocket,
2310
+ data: WebSocket.RawData,
2311
+ isBinary: boolean,
2312
+ ) => void,
2313
+ ): this
2314
+ on(event: 'open', listener: (this: WebSocket) => void): this
2315
+ on(
2316
+ event: 'ping' | 'pong',
2317
+ listener: (this: WebSocket, data: Buffer) => void,
2318
+ ): this
2319
+ on(
2320
+ event: 'unexpected-response',
2321
+ listener: (
2322
+ this: WebSocket,
2323
+ request: ClientRequest,
2324
+ response: IncomingMessage,
2325
+ ) => void,
2326
+ ): this
2327
+ on(
2328
+ event: string | symbol,
2329
+ listener: (this: WebSocket, ...args: any[]) => void,
2330
+ ): this
2331
+
2332
+ once(
2333
+ event: 'close',
2334
+ listener: (this: WebSocket, code: number, reason: Buffer) => void,
2335
+ ): this
2336
+ once(event: 'error', listener: (this: WebSocket, err: Error) => void): this
2337
+ once(
2338
+ event: 'upgrade',
2339
+ listener: (this: WebSocket, request: IncomingMessage) => void,
2340
+ ): this
2341
+ once(
2342
+ event: 'message',
2343
+ listener: (
2344
+ this: WebSocket,
2345
+ data: WebSocket.RawData,
2346
+ isBinary: boolean,
2347
+ ) => void,
2348
+ ): this
2349
+ once(event: 'open', listener: (this: WebSocket) => void): this
2350
+ once(
2351
+ event: 'ping' | 'pong',
2352
+ listener: (this: WebSocket, data: Buffer) => void,
2353
+ ): this
2354
+ once(
2355
+ event: 'unexpected-response',
2356
+ listener: (
2357
+ this: WebSocket,
2358
+ request: ClientRequest,
2359
+ response: IncomingMessage,
2360
+ ) => void,
2361
+ ): this
2362
+ once(
2363
+ event: string | symbol,
2364
+ listener: (this: WebSocket, ...args: any[]) => void,
2365
+ ): this
2366
+
2367
+ off(
2368
+ event: 'close',
2369
+ listener: (this: WebSocket, code: number, reason: Buffer) => void,
2370
+ ): this
2371
+ off(event: 'error', listener: (this: WebSocket, err: Error) => void): this
2372
+ off(
2373
+ event: 'upgrade',
2374
+ listener: (this: WebSocket, request: IncomingMessage) => void,
2375
+ ): this
2376
+ off(
2377
+ event: 'message',
2378
+ listener: (
2379
+ this: WebSocket,
2380
+ data: WebSocket.RawData,
2381
+ isBinary: boolean,
2382
+ ) => void,
2383
+ ): this
2384
+ off(event: 'open', listener: (this: WebSocket) => void): this
2385
+ off(
2386
+ event: 'ping' | 'pong',
2387
+ listener: (this: WebSocket, data: Buffer) => void,
2388
+ ): this
2389
+ off(
2390
+ event: 'unexpected-response',
2391
+ listener: (
2392
+ this: WebSocket,
2393
+ request: ClientRequest,
2394
+ response: IncomingMessage,
2395
+ ) => void,
2396
+ ): this
2397
+ off(
2398
+ event: string | symbol,
2399
+ listener: (this: WebSocket, ...args: any[]) => void,
2400
+ ): this
2401
+
2402
+ addListener(
2403
+ event: 'close',
2404
+ listener: (code: number, reason: Buffer) => void,
2405
+ ): this
2406
+ addListener(event: 'error', listener: (err: Error) => void): this
2407
+ addListener(
2408
+ event: 'upgrade',
2409
+ listener: (request: IncomingMessage) => void,
2410
+ ): this
2411
+ addListener(
2412
+ event: 'message',
2413
+ listener: (data: WebSocket.RawData, isBinary: boolean) => void,
2414
+ ): this
2415
+ addListener(event: 'open', listener: () => void): this
2416
+ addListener(event: 'ping' | 'pong', listener: (data: Buffer) => void): this
2417
+ addListener(
2418
+ event: 'unexpected-response',
2419
+ listener: (request: ClientRequest, response: IncomingMessage) => void,
2420
+ ): this
2421
+ addListener(event: string | symbol, listener: (...args: any[]) => void): this
2392
2422
 
2393
- /**
2394
- * @default "auto"
2395
- */
2396
- defaultIsModuleExports?: boolean | 'auto' | ((id: string) => boolean | 'auto')
2397
- /**
2398
- * Some modules contain dynamic `require` calls, or require modules that
2399
- * contain circular dependencies, which are not handled well by static
2400
- * imports. Including those modules as `dynamicRequireTargets` will simulate a
2401
- * CommonJS (NodeJS-like) environment for them with support for dynamic
2402
- * dependencies. It also enables `strictRequires` for those modules.
2403
- *
2404
- * Note: In extreme cases, this feature may result in some paths being
2405
- * rendered as absolute in the final bundle. The plugin tries to avoid
2406
- * exposing paths from the local machine, but if you are `dynamicRequirePaths`
2407
- * with paths that are far away from your project's folder, that may require
2408
- * replacing strings like `"/Users/John/Desktop/foo-project/"` -\> `"/"`.
2409
- */
2410
- dynamicRequireTargets?: string | ReadonlyArray<string>
2411
- /**
2412
- * To avoid long paths when using the `dynamicRequireTargets` option, you can use this option to specify a directory
2413
- * that is a common parent for all files that use dynamic require statements. Using a directory higher up such as `/`
2414
- * may lead to unnecessarily long paths in the generated code and may expose directory names on your machine like your
2415
- * home directory name. By default, it uses the current working directory.
2416
- */
2417
- dynamicRequireRoot?: string
2423
+ removeListener(
2424
+ event: 'close',
2425
+ listener: (code: number, reason: Buffer) => void,
2426
+ ): this
2427
+ removeListener(event: 'error', listener: (err: Error) => void): this
2428
+ removeListener(
2429
+ event: 'upgrade',
2430
+ listener: (request: IncomingMessage) => void,
2431
+ ): this
2432
+ removeListener(
2433
+ event: 'message',
2434
+ listener: (data: WebSocket.RawData, isBinary: boolean) => void,
2435
+ ): this
2436
+ removeListener(event: 'open', listener: () => void): this
2437
+ removeListener(event: 'ping' | 'pong', listener: (data: Buffer) => void): this
2438
+ removeListener(
2439
+ event: 'unexpected-response',
2440
+ listener: (request: ClientRequest, response: IncomingMessage) => void,
2441
+ ): this
2442
+ removeListener(
2443
+ event: string | symbol,
2444
+ listener: (...args: any[]) => void,
2445
+ ): this
2418
2446
  }
2419
2447
 
2420
- interface RollupDynamicImportVarsOptions {
2448
+ declare namespace WebSocket {
2421
2449
  /**
2422
- * Files to include in this plugin (default all).
2423
- * @default []
2450
+ * Data represents the raw message payload received over the WebSocket.
2424
2451
  */
2425
- include?: string | RegExp | (string | RegExp)[]
2452
+ type RawData = Buffer | ArrayBuffer | Buffer[]
2453
+
2426
2454
  /**
2427
- * Files to exclude in this plugin (default none).
2428
- * @default []
2455
+ * Data represents the message payload received over the WebSocket.
2429
2456
  */
2430
- exclude?: string | RegExp | (string | RegExp)[]
2457
+ type Data = string | Buffer | ArrayBuffer | Buffer[]
2458
+
2431
2459
  /**
2432
- * 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.
2433
- * @default false
2460
+ * CertMeta represents the accepted types for certificate & key data.
2434
2461
  */
2435
- warnOnError?: boolean
2436
- }
2437
-
2438
- // Modified and inlined to avoid extra dependency
2439
- // Source: https://github.com/terser/terser/blob/master/tools/terser.d.ts
2440
- // BSD Licensed https://github.com/terser/terser/blob/master/LICENSE
2441
-
2442
- declare namespace Terser {
2443
- export type ECMA = 5 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020
2444
-
2445
- export interface ParseOptions {
2446
- bare_returns?: boolean
2447
- /** @deprecated legacy option. Currently, all supported EcmaScript is valid to parse. */
2448
- ecma?: ECMA
2449
- html5_comments?: boolean
2450
- shebang?: boolean
2451
- }
2452
-
2453
- export interface CompressOptions {
2454
- arguments?: boolean
2455
- arrows?: boolean
2456
- booleans_as_integers?: boolean
2457
- booleans?: boolean
2458
- collapse_vars?: boolean
2459
- comparisons?: boolean
2460
- computed_props?: boolean
2461
- conditionals?: boolean
2462
- dead_code?: boolean
2463
- defaults?: boolean
2464
- directives?: boolean
2465
- drop_console?: boolean
2466
- drop_debugger?: boolean
2467
- ecma?: ECMA
2468
- evaluate?: boolean
2469
- expression?: boolean
2470
- global_defs?: object
2471
- hoist_funs?: boolean
2472
- hoist_props?: boolean
2473
- hoist_vars?: boolean
2474
- ie8?: boolean
2475
- if_return?: boolean
2476
- inline?: boolean | InlineFunctions
2477
- join_vars?: boolean
2478
- keep_classnames?: boolean | RegExp
2479
- keep_fargs?: boolean
2480
- keep_fnames?: boolean | RegExp
2481
- keep_infinity?: boolean
2482
- loops?: boolean
2483
- module?: boolean
2484
- negate_iife?: boolean
2485
- passes?: number
2486
- properties?: boolean
2487
- pure_funcs?: string[]
2488
- pure_getters?: boolean | 'strict'
2489
- reduce_funcs?: boolean
2490
- reduce_vars?: boolean
2491
- sequences?: boolean | number
2492
- side_effects?: boolean
2493
- switches?: boolean
2494
- toplevel?: boolean
2495
- top_retain?: null | string | string[] | RegExp
2496
- typeofs?: boolean
2497
- unsafe_arrows?: boolean
2498
- unsafe?: boolean
2499
- unsafe_comps?: boolean
2500
- unsafe_Function?: boolean
2501
- unsafe_math?: boolean
2502
- unsafe_symbols?: boolean
2503
- unsafe_methods?: boolean
2504
- unsafe_proto?: boolean
2505
- unsafe_regexp?: boolean
2506
- unsafe_undefined?: boolean
2507
- unused?: boolean
2508
- }
2509
-
2510
- export enum InlineFunctions {
2511
- Disabled = 0,
2512
- SimpleFunctions = 1,
2513
- WithArguments = 2,
2514
- WithArgumentsAndVariables = 3,
2515
- }
2516
-
2517
- export interface MangleOptions {
2518
- eval?: boolean
2519
- keep_classnames?: boolean | RegExp
2520
- keep_fnames?: boolean | RegExp
2521
- module?: boolean
2522
- nth_identifier?: SimpleIdentifierMangler | WeightedIdentifierMangler
2523
- properties?: boolean | ManglePropertiesOptions
2524
- reserved?: string[]
2525
- safari10?: boolean
2526
- toplevel?: boolean
2527
- }
2462
+ type CertMeta = string | string[] | Buffer | Buffer[]
2528
2463
 
2529
2464
  /**
2530
- * An identifier mangler for which the output is invariant with respect to the source code.
2465
+ * VerifyClientCallbackSync is a synchronous callback used to inspect the
2466
+ * incoming message. The return value (boolean) of the function determines
2467
+ * whether or not to accept the handshake.
2531
2468
  */
2532
- export interface SimpleIdentifierMangler {
2533
- /**
2534
- * Obtains the nth most favored (usually shortest) identifier to rename a variable to.
2535
- * The mangler will increment n and retry until the return value is not in use in scope, and is not a reserved word.
2536
- * This function is expected to be stable; Evaluating get(n) === get(n) should always return true.
2537
- * @param n - The ordinal of the identifier.
2538
- */
2539
- get(n: number): string
2540
- }
2469
+ type VerifyClientCallbackSync = (info: {
2470
+ origin: string
2471
+ secure: boolean
2472
+ req: IncomingMessage
2473
+ }) => boolean
2541
2474
 
2542
2475
  /**
2543
- * An identifier mangler that leverages character frequency analysis to determine identifier precedence.
2476
+ * VerifyClientCallbackAsync is an asynchronous callback used to inspect the
2477
+ * incoming message. The return value (boolean) of the function determines
2478
+ * whether or not to accept the handshake.
2544
2479
  */
2545
- export interface WeightedIdentifierMangler extends SimpleIdentifierMangler {
2546
- /**
2547
- * Modifies the internal weighting of the input characters by the specified delta.
2548
- * Will be invoked on the entire printed AST, and then deduct mangleable identifiers.
2549
- * @param chars - The characters to modify the weighting of.
2550
- * @param delta - The numeric weight to add to the characters.
2551
- */
2552
- consider(chars: string, delta: number): number
2553
- /**
2554
- * Resets character weights.
2555
- */
2556
- reset(): void
2557
- /**
2558
- * Sorts identifiers by character frequency, in preparation for calls to get(n).
2559
- */
2560
- sort(): void
2480
+ type VerifyClientCallbackAsync = (
2481
+ info: { origin: string; secure: boolean; req: IncomingMessage },
2482
+ callback: (
2483
+ res: boolean,
2484
+ code?: number,
2485
+ message?: string,
2486
+ headers?: OutgoingHttpHeaders,
2487
+ ) => void,
2488
+ ) => void
2489
+
2490
+ interface ClientOptions extends SecureContextOptions {
2491
+ protocol?: string | undefined
2492
+ followRedirects?: boolean | undefined
2493
+ generateMask?(mask: Buffer): void
2494
+ handshakeTimeout?: number | undefined
2495
+ maxRedirects?: number | undefined
2496
+ perMessageDeflate?: boolean | PerMessageDeflateOptions | undefined
2497
+ localAddress?: string | undefined
2498
+ protocolVersion?: number | undefined
2499
+ headers?: { [key: string]: string } | undefined
2500
+ origin?: string | undefined
2501
+ agent?: Agent | undefined
2502
+ host?: string | undefined
2503
+ family?: number | undefined
2504
+ checkServerIdentity?(servername: string, cert: CertMeta): boolean
2505
+ rejectUnauthorized?: boolean | undefined
2506
+ maxPayload?: number | undefined
2507
+ skipUTF8Validation?: boolean | undefined
2508
+ }
2509
+
2510
+ interface PerMessageDeflateOptions {
2511
+ serverNoContextTakeover?: boolean | undefined
2512
+ clientNoContextTakeover?: boolean | undefined
2513
+ serverMaxWindowBits?: number | undefined
2514
+ clientMaxWindowBits?: number | undefined
2515
+ zlibDeflateOptions?:
2516
+ | {
2517
+ flush?: number | undefined
2518
+ finishFlush?: number | undefined
2519
+ chunkSize?: number | undefined
2520
+ windowBits?: number | undefined
2521
+ level?: number | undefined
2522
+ memLevel?: number | undefined
2523
+ strategy?: number | undefined
2524
+ dictionary?: Buffer | Buffer[] | DataView | undefined
2525
+ info?: boolean | undefined
2526
+ }
2527
+ | undefined
2528
+ zlibInflateOptions?: ZlibOptions | undefined
2529
+ threshold?: number | undefined
2530
+ concurrencyLimit?: number | undefined
2561
2531
  }
2562
2532
 
2563
- export interface ManglePropertiesOptions {
2564
- builtins?: boolean
2565
- debug?: boolean
2566
- keep_quoted?: boolean | 'strict'
2567
- nth_identifier?: SimpleIdentifierMangler | WeightedIdentifierMangler
2568
- regex?: RegExp | string
2569
- reserved?: string[]
2533
+ interface Event {
2534
+ type: string
2535
+ target: WebSocket
2570
2536
  }
2571
2537
 
2572
- export interface FormatOptions {
2573
- ascii_only?: boolean
2574
- /** @deprecated Not implemented anymore */
2575
- beautify?: boolean
2576
- braces?: boolean
2577
- comments?:
2578
- | boolean
2579
- | 'all'
2580
- | 'some'
2581
- | RegExp
2582
- | ((
2583
- node: any,
2584
- comment: {
2585
- value: string
2586
- type: 'comment1' | 'comment2' | 'comment3' | 'comment4'
2587
- pos: number
2588
- line: number
2589
- col: number
2590
- },
2591
- ) => boolean)
2592
- ecma?: ECMA
2593
- ie8?: boolean
2594
- keep_numbers?: boolean
2595
- indent_level?: number
2596
- indent_start?: number
2597
- inline_script?: boolean
2598
- keep_quoted_props?: boolean
2599
- max_line_len?: number | false
2600
- preamble?: string
2601
- preserve_annotations?: boolean
2602
- quote_keys?: boolean
2603
- quote_style?: OutputQuoteStyle
2604
- safari10?: boolean
2605
- semicolons?: boolean
2606
- shebang?: boolean
2607
- shorthand?: boolean
2608
- source_map?: SourceMapOptions
2609
- webkit?: boolean
2610
- width?: number
2611
- wrap_iife?: boolean
2612
- wrap_func_args?: boolean
2538
+ interface ErrorEvent {
2539
+ error: any
2540
+ message: string
2541
+ type: string
2542
+ target: WebSocket
2613
2543
  }
2614
2544
 
2615
- export enum OutputQuoteStyle {
2616
- PreferDouble = 0,
2617
- AlwaysSingle = 1,
2618
- AlwaysDouble = 2,
2619
- AlwaysOriginal = 3,
2545
+ interface CloseEvent {
2546
+ wasClean: boolean
2547
+ code: number
2548
+ reason: string
2549
+ type: string
2550
+ target: WebSocket
2620
2551
  }
2621
2552
 
2622
- export interface MinifyOptions {
2623
- compress?: boolean | CompressOptions
2624
- ecma?: ECMA
2625
- enclose?: boolean | string
2626
- ie8?: boolean
2627
- keep_classnames?: boolean | RegExp
2628
- keep_fnames?: boolean | RegExp
2629
- mangle?: boolean | MangleOptions
2630
- module?: boolean
2631
- nameCache?: object
2632
- format?: FormatOptions
2633
- /** @deprecated deprecated */
2634
- output?: FormatOptions
2635
- parse?: ParseOptions
2636
- safari10?: boolean
2637
- sourceMap?: boolean | SourceMapOptions
2638
- toplevel?: boolean
2553
+ interface MessageEvent {
2554
+ data: Data
2555
+ type: string
2556
+ target: WebSocket
2639
2557
  }
2640
2558
 
2641
- export interface MinifyOutput {
2642
- code?: string
2643
- map?: object | string
2644
- decoded_map?: object | null
2559
+ interface EventListenerOptions {
2560
+ once?: boolean | undefined
2645
2561
  }
2646
2562
 
2647
- export interface SourceMapOptions {
2648
- /** Source map object, 'inline' or source map file content */
2649
- content?: object | string
2650
- includeSources?: boolean
2651
- filename?: string
2652
- root?: string
2653
- url?: string | 'inline'
2563
+ interface ServerOptions {
2564
+ host?: string | undefined
2565
+ port?: number | undefined
2566
+ backlog?: number | undefined
2567
+ server?: Server | HttpsServer | undefined
2568
+ verifyClient?:
2569
+ | VerifyClientCallbackAsync
2570
+ | VerifyClientCallbackSync
2571
+ | undefined
2572
+ handleProtocols?: (
2573
+ protocols: Set<string>,
2574
+ request: IncomingMessage,
2575
+ ) => string | false
2576
+ path?: string | undefined
2577
+ noServer?: boolean | undefined
2578
+ clientTracking?: boolean | undefined
2579
+ perMessageDeflate?: boolean | PerMessageDeflateOptions | undefined
2580
+ maxPayload?: number | undefined
2581
+ skipUTF8Validation?: boolean | undefined
2582
+ WebSocket?: typeof WebSocket.WebSocket | undefined
2583
+ }
2584
+
2585
+ interface AddressInfo {
2586
+ address: string
2587
+ family: string
2588
+ port: number
2654
2589
  }
2590
+
2591
+ // WebSocket Server
2592
+ class Server<T extends WebSocket = WebSocket> extends EventEmitter {
2593
+ options: ServerOptions
2594
+ path: string
2595
+ clients: Set<T>
2596
+
2597
+ constructor(options?: ServerOptions, callback?: () => void)
2598
+
2599
+ address(): AddressInfo | string
2600
+ close(cb?: (err?: Error) => void): void
2601
+ handleUpgrade(
2602
+ request: IncomingMessage,
2603
+ socket: Duplex,
2604
+ upgradeHead: Buffer,
2605
+ callback: (client: T, request: IncomingMessage) => void,
2606
+ ): void
2607
+ shouldHandle(request: IncomingMessage): boolean | Promise<boolean>
2608
+
2609
+ // Events
2610
+ on(
2611
+ event: 'connection',
2612
+ cb: (this: Server<T>, socket: T, request: IncomingMessage) => void,
2613
+ ): this
2614
+ on(event: 'error', cb: (this: Server<T>, error: Error) => void): this
2615
+ on(
2616
+ event: 'headers',
2617
+ cb: (
2618
+ this: Server<T>,
2619
+ headers: string[],
2620
+ request: IncomingMessage,
2621
+ ) => void,
2622
+ ): this
2623
+ on(event: 'close' | 'listening', cb: (this: Server<T>) => void): this
2624
+ on(
2625
+ event: string | symbol,
2626
+ listener: (this: Server<T>, ...args: any[]) => void,
2627
+ ): this
2628
+
2629
+ once(
2630
+ event: 'connection',
2631
+ cb: (this: Server<T>, socket: T, request: IncomingMessage) => void,
2632
+ ): this
2633
+ once(event: 'error', cb: (this: Server<T>, error: Error) => void): this
2634
+ once(
2635
+ event: 'headers',
2636
+ cb: (
2637
+ this: Server<T>,
2638
+ headers: string[],
2639
+ request: IncomingMessage,
2640
+ ) => void,
2641
+ ): this
2642
+ once(event: 'close' | 'listening', cb: (this: Server<T>) => void): this
2643
+ once(
2644
+ event: string | symbol,
2645
+ listener: (this: Server<T>, ...args: any[]) => void,
2646
+ ): this
2647
+
2648
+ off(
2649
+ event: 'connection',
2650
+ cb: (this: Server<T>, socket: T, request: IncomingMessage) => void,
2651
+ ): this
2652
+ off(event: 'error', cb: (this: Server<T>, error: Error) => void): this
2653
+ off(
2654
+ event: 'headers',
2655
+ cb: (
2656
+ this: Server<T>,
2657
+ headers: string[],
2658
+ request: IncomingMessage,
2659
+ ) => void,
2660
+ ): this
2661
+ off(event: 'close' | 'listening', cb: (this: Server<T>) => void): this
2662
+ off(
2663
+ event: string | symbol,
2664
+ listener: (this: Server<T>, ...args: any[]) => void,
2665
+ ): this
2666
+
2667
+ addListener(
2668
+ event: 'connection',
2669
+ cb: (client: T, request: IncomingMessage) => void,
2670
+ ): this
2671
+ addListener(event: 'error', cb: (err: Error) => void): this
2672
+ addListener(
2673
+ event: 'headers',
2674
+ cb: (headers: string[], request: IncomingMessage) => void,
2675
+ ): this
2676
+ addListener(event: 'close' | 'listening', cb: () => void): this
2677
+ addListener(
2678
+ event: string | symbol,
2679
+ listener: (...args: any[]) => void,
2680
+ ): this
2681
+
2682
+ removeListener(event: 'connection', cb: (client: T) => void): this
2683
+ removeListener(event: 'error', cb: (err: Error) => void): this
2684
+ removeListener(
2685
+ event: 'headers',
2686
+ cb: (headers: string[], request: IncomingMessage) => void,
2687
+ ): this
2688
+ removeListener(event: 'close' | 'listening', cb: () => void): this
2689
+ removeListener(
2690
+ event: string | symbol,
2691
+ listener: (...args: any[]) => void,
2692
+ ): this
2693
+ }
2694
+
2695
+ const WebSocketServer: typeof Server
2696
+ interface WebSocketServer extends Server {}
2697
+ const WebSocket: typeof WebSocketAlias
2698
+ interface WebSocket extends WebSocketAlias {}
2699
+
2700
+ // WebSocket stream
2701
+ function createWebSocketStream(
2702
+ websocket: WebSocket,
2703
+ options?: DuplexOptions,
2704
+ ): Duplex
2705
+ }
2706
+
2707
+ type WebSocketCustomListener<T> = (data: T, client: WebSocketClient) => void;
2708
+ interface WebSocketServer extends HotChannel {
2709
+ /**
2710
+ * Listen on port and host
2711
+ */
2712
+ listen(): void;
2713
+ /**
2714
+ * Get all connected clients.
2715
+ */
2716
+ clients: Set<WebSocketClient>;
2717
+ /**
2718
+ * Disconnect all clients and terminate the server.
2719
+ */
2720
+ close(): Promise<void>;
2721
+ /**
2722
+ * Handle custom event emitted by `import.meta.hot.send`
2723
+ */
2724
+ on: WebSocket.Server['on'] & {
2725
+ <T extends string>(event: T, listener: WebSocketCustomListener<InferCustomEventPayload<T>>): void;
2726
+ };
2727
+ /**
2728
+ * Unregister event listener.
2729
+ */
2730
+ off: WebSocket.Server['off'] & {
2731
+ (event: string, listener: Function): void;
2732
+ };
2655
2733
  }
2656
-
2657
- interface TerserOptions extends Terser.MinifyOptions {
2734
+ interface WebSocketClient extends HotChannelClient {
2658
2735
  /**
2659
- * Vite-specific option to specify the max number of workers to spawn
2660
- * when minifying files with terser.
2661
- *
2662
- * @default number of CPUs minus 1
2736
+ * The raw WebSocket instance
2737
+ * @advanced
2663
2738
  */
2664
- maxWorkers?: number;
2739
+ socket: WebSocket;
2665
2740
  }
2666
2741
 
2667
- interface BuildEnvironmentOptions {
2742
+ interface ServerOptions extends CommonServerOptions {
2668
2743
  /**
2669
- * Compatibility transform target. The transform is performed with esbuild
2670
- * and the lowest supported target is es2015/es6. Note this only handles
2671
- * syntax transformation and does not cover polyfills (except for dynamic
2672
- * import)
2673
- *
2674
- * Default: 'modules' - Similar to `@babel/preset-env`'s targets.esmodules,
2675
- * transpile targeting browsers that natively support dynamic es module imports.
2676
- * https://caniuse.com/es6-module-dynamic-import
2677
- *
2678
- * Another special value is 'esnext' - which only performs minimal transpiling
2679
- * (for minification compat) and assumes native dynamic imports support.
2680
- *
2681
- * For custom targets, see https://esbuild.github.io/api/#target and
2682
- * https://esbuild.github.io/content-types/#javascript for more details.
2683
- * @default 'modules'
2744
+ * Configure HMR-specific options (port, host, path & protocol)
2684
2745
  */
2685
- target?: 'modules' | esbuild_TransformOptions['target'] | false;
2746
+ hmr?: HmrOptions | boolean;
2686
2747
  /**
2687
- * whether to inject module preload polyfill.
2688
- * Note: does not apply to library mode.
2689
- * @default true
2690
- * @deprecated use `modulePreload.polyfill` instead
2748
+ * Do not start the websocket connection.
2749
+ * @experimental
2691
2750
  */
2692
- polyfillModulePreload?: boolean;
2751
+ ws?: false;
2693
2752
  /**
2694
- * Configure module preload
2695
- * Note: does not apply to library mode.
2696
- * @default true
2753
+ * Warm-up files to transform and cache the results in advance. This improves the
2754
+ * initial page load during server starts and prevents transform waterfalls.
2697
2755
  */
2698
- modulePreload?: boolean | ModulePreloadOptions;
2756
+ warmup?: {
2757
+ /**
2758
+ * The files to be transformed and used on the client-side. Supports glob patterns.
2759
+ */
2760
+ clientFiles?: string[];
2761
+ /**
2762
+ * The files to be transformed and used in SSR. Supports glob patterns.
2763
+ */
2764
+ ssrFiles?: string[];
2765
+ };
2699
2766
  /**
2700
- * Directory relative from `root` where build output will be placed. If the
2701
- * directory exists, it will be removed before the build.
2702
- * @default 'dist'
2767
+ * chokidar watch options or null to disable FS watching
2768
+ * https://github.com/paulmillr/chokidar#api
2703
2769
  */
2704
- outDir?: string;
2770
+ watch?: WatchOptions | null;
2705
2771
  /**
2706
- * Directory relative from `outDir` where the built js/css/image assets will
2707
- * be placed.
2708
- * @default 'assets'
2772
+ * Create Vite dev server to be used as a middleware in an existing server
2773
+ * @default false
2709
2774
  */
2710
- assetsDir?: string;
2775
+ middlewareMode?: boolean | {
2776
+ /**
2777
+ * Parent server instance to attach to
2778
+ *
2779
+ * This is needed to proxy WebSocket connections to the parent server.
2780
+ */
2781
+ server: HttpServer;
2782
+ };
2711
2783
  /**
2712
- * Static asset files smaller than this number (in bytes) will be inlined as
2713
- * base64 strings. Default limit is `4096` (4 KiB). Set to `0` to disable.
2714
- * @default 4096
2784
+ * Options for files served via '/\@fs/'.
2715
2785
  */
2716
- assetsInlineLimit?: number | ((filePath: string, content: Buffer) => boolean | undefined);
2786
+ fs?: FileSystemServeOptions;
2717
2787
  /**
2718
- * Whether to code-split CSS. When enabled, CSS in async chunks will be
2719
- * inlined as strings in the chunk and inserted via dynamically created
2720
- * style tags when the chunk is loaded.
2721
- * @default true
2788
+ * Origin for the generated asset URLs.
2789
+ *
2790
+ * @example `http://127.0.0.1:8080`
2722
2791
  */
2723
- cssCodeSplit?: boolean;
2792
+ origin?: string;
2724
2793
  /**
2725
- * An optional separate target for CSS minification.
2726
- * As esbuild only supports configuring targets to mainstream
2727
- * browsers, users may need this option when they are targeting
2728
- * a niche browser that comes with most modern JavaScript features
2729
- * but has poor CSS support, e.g. Android WeChat WebView, which
2730
- * doesn't support the #RGBA syntax.
2731
- * @default target
2794
+ * Pre-transform known direct imports
2795
+ * @default true
2732
2796
  */
2733
- cssTarget?: esbuild_TransformOptions['target'] | false;
2797
+ preTransformRequests?: boolean;
2734
2798
  /**
2735
- * Override CSS minification specifically instead of defaulting to `build.minify`,
2736
- * so you can configure minification for JS and CSS separately.
2737
- * @default 'esbuild'
2799
+ * Whether or not to ignore-list source files in the dev server sourcemap, used to populate
2800
+ * the [`x_google_ignoreList` source map extension](https://developer.chrome.com/blog/devtools-better-angular-debugging/#the-x_google_ignorelist-source-map-extension).
2801
+ *
2802
+ * By default, it excludes all paths containing `node_modules`. You can pass `false` to
2803
+ * disable this behavior, or, for full control, a function that takes the source path and
2804
+ * sourcemap path and returns whether to ignore the source path.
2738
2805
  */
2739
- cssMinify?: boolean | 'esbuild' | 'lightningcss';
2806
+ sourcemapIgnoreList?: false | ((sourcePath: string, sourcemapPath: string) => boolean);
2740
2807
  /**
2741
- * If `true`, a separate sourcemap file will be created. If 'inline', the
2742
- * sourcemap will be appended to the resulting output file as data URI.
2743
- * 'hidden' works like `true` except that the corresponding sourcemap
2744
- * comments in the bundled files are suppressed.
2808
+ * Backward compatibility. The buildStart and buildEnd hooks were called only once for all
2809
+ * environments. This option enables per-environment buildStart and buildEnd hooks.
2745
2810
  * @default false
2811
+ * @experimental
2746
2812
  */
2747
- sourcemap?: boolean | 'inline' | 'hidden';
2813
+ perEnvironmentBuildStartEnd?: boolean;
2748
2814
  /**
2749
- * Set to `false` to disable minification, or specify the minifier to use.
2750
- * Available options are 'terser' or 'esbuild'.
2751
- * @default 'esbuild'
2815
+ * Run HMR tasks, by default the HMR propagation is done in parallel for all environments
2816
+ * @experimental
2752
2817
  */
2753
- minify?: boolean | 'terser' | 'esbuild';
2818
+ hotUpdateEnvironments?: (server: ViteDevServer, hmr: (environment: DevEnvironment) => Promise<void>) => Promise<void>;
2819
+ }
2820
+ interface ResolvedServerOptions extends Omit<ServerOptions, 'fs' | 'middlewareMode' | 'sourcemapIgnoreList'> {
2821
+ fs: Required<FileSystemServeOptions>;
2822
+ middlewareMode: NonNullable<ServerOptions['middlewareMode']>;
2823
+ sourcemapIgnoreList: Exclude<ServerOptions['sourcemapIgnoreList'], false | undefined>;
2824
+ }
2825
+ interface FileSystemServeOptions {
2754
2826
  /**
2755
- * Options for terser
2756
- * https://terser.org/docs/api-reference#minify-options
2827
+ * Strictly restrict file accessing outside of allowing paths.
2757
2828
  *
2758
- * In addition, you can also pass a `maxWorkers: number` option to specify the
2759
- * max number of workers to spawn. Defaults to the number of CPUs minus 1.
2829
+ * Set to `false` to disable the warning
2830
+ *
2831
+ * @default true
2760
2832
  */
2761
- terserOptions?: TerserOptions;
2833
+ strict?: boolean;
2762
2834
  /**
2763
- * Will be merged with internal rollup options.
2764
- * https://rollupjs.org/configuration-options/
2835
+ * Restrict accessing files outside the allowed directories.
2836
+ *
2837
+ * Accepts absolute path or a path relative to project root.
2838
+ * Will try to search up for workspace root by default.
2765
2839
  */
2766
- rollupOptions?: RollupOptions;
2840
+ allow?: string[];
2767
2841
  /**
2768
- * Options to pass on to `@rollup/plugin-commonjs`
2842
+ * Restrict accessing files that matches the patterns.
2843
+ *
2844
+ * This will have higher priority than `allow`.
2845
+ * picomatch patterns are supported.
2846
+ *
2847
+ * @default ['.env', '.env.*', '*.crt', '*.pem']
2769
2848
  */
2770
- commonjsOptions?: RollupCommonJSOptions;
2849
+ deny?: string[];
2771
2850
  /**
2772
- * Options to pass on to `@rollup/plugin-dynamic-import-vars`
2851
+ * Enable caching of fs calls. It is enabled by default if no custom watch ignored patterns are provided.
2852
+ *
2853
+ * @experimental
2854
+ * @default undefined
2773
2855
  */
2774
- dynamicImportVarsOptions?: RollupDynamicImportVarsOptions;
2856
+ cachedChecks?: boolean;
2857
+ }
2858
+ type ServerHook = (this: void, server: ViteDevServer) => (() => void) | void | Promise<(() => void) | void>;
2859
+ type HttpServer = http.Server | Http2SecureServer;
2860
+ interface ViteDevServer {
2775
2861
  /**
2776
- * Whether to write bundle to disk
2777
- * @default true
2862
+ * The resolved vite config object
2778
2863
  */
2779
- write?: boolean;
2864
+ config: ResolvedConfig;
2780
2865
  /**
2781
- * Empty outDir on write.
2782
- * @default true when outDir is a sub directory of project root
2866
+ * A connect app instance.
2867
+ * - Can be used to attach custom middlewares to the dev server.
2868
+ * - Can also be used as the handler function of a custom http server
2869
+ * or as a middleware in any connect-style Node.js frameworks
2870
+ *
2871
+ * https://github.com/senchalabs/connect#use-middleware
2783
2872
  */
2784
- emptyOutDir?: boolean | null;
2873
+ middlewares: Connect.Server;
2785
2874
  /**
2786
- * Copy the public directory to outDir on write.
2787
- * @default true
2875
+ * native Node http server instance
2876
+ * will be null in middleware mode
2788
2877
  */
2789
- copyPublicDir?: boolean;
2878
+ httpServer: HttpServer | null;
2790
2879
  /**
2791
- * Whether to emit a .vite/manifest.json under assets dir to map hash-less filenames
2792
- * to their hashed versions. Useful when you want to generate your own HTML
2793
- * instead of using the one generated by Vite.
2794
- *
2795
- * Example:
2880
+ * chokidar watcher instance
2881
+ * https://github.com/paulmillr/chokidar#api
2882
+ */
2883
+ watcher: FSWatcher;
2884
+ /**
2885
+ * web socket server with `send(payload)` method
2886
+ */
2887
+ ws: WebSocketServer;
2888
+ /**
2889
+ * HMR broadcaster that can be used to send custom HMR messages to the client
2796
2890
  *
2797
- * ```json
2798
- * {
2799
- * "main.js": {
2800
- * "file": "main.68fe3fad.js",
2801
- * "css": "main.e6b63442.css",
2802
- * "imports": [...],
2803
- * "dynamicImports": [...]
2804
- * }
2805
- * }
2806
- * ```
2807
- * @default false
2891
+ * Always sends a message to at least a WebSocket client. Any third party can
2892
+ * add a channel to the broadcaster to process messages
2808
2893
  */
2809
- manifest?: boolean | string;
2894
+ hot: HotBroadcaster;
2810
2895
  /**
2811
- * Produce SSR oriented build. Note this requires specifying SSR entry via
2812
- * `rollupOptions.input`.
2813
- * @default false
2896
+ * Rollup plugin container that can run plugin hooks on a given file
2814
2897
  */
2815
- ssr?: boolean | string;
2898
+ pluginContainer: PluginContainer;
2816
2899
  /**
2817
- * Generate SSR manifest for determining style links and asset preload
2818
- * directives in production.
2819
- * @default false
2900
+ * Module execution environments attached to the Vite server.
2901
+ */
2902
+ environments: Record<'client' | 'ssr' | (string & {}), DevEnvironment>;
2903
+ /**
2904
+ * Module graph that tracks the import relationships, url to file mapping
2905
+ * and hmr state.
2906
+ */
2907
+ moduleGraph: ModuleGraph;
2908
+ /**
2909
+ * The resolved urls Vite prints on the CLI. null in middleware mode or
2910
+ * before `server.listen` is called.
2911
+ */
2912
+ resolvedUrls: ResolvedServerUrls | null;
2913
+ /**
2914
+ * Programmatically resolve, load and transform a URL and get the result
2915
+ * without going through the http request pipeline.
2916
+ */
2917
+ transformRequest(url: string, options?: TransformOptions): Promise<TransformResult | null>;
2918
+ /**
2919
+ * Same as `transformRequest` but only warm up the URLs so the next request
2920
+ * will already be cached. The function will never throw as it handles and
2921
+ * reports errors internally.
2820
2922
  */
2821
- ssrManifest?: boolean | string;
2923
+ warmupRequest(url: string, options?: TransformOptions): Promise<void>;
2822
2924
  /**
2823
- * Emit assets during SSR.
2824
- * @default false
2825
- * @deprecated use emitAssets
2925
+ * Apply vite built-in HTML transforms and any plugin HTML transforms.
2826
2926
  */
2827
- ssrEmitAssets?: boolean;
2927
+ transformIndexHtml(url: string, html: string, originalUrl?: string): Promise<string>;
2828
2928
  /**
2829
- * Emit assets during build. Frameworks can set environments.ssr.build.emitAssets
2830
- * By default, it is true for the client and false for other environments.
2831
- * TODO: Should this be true for all environments by default? Or should this be
2832
- * controlled by the builder so so we can avoid emitting duplicated assets.
2929
+ * Transform module code into SSR format.
2833
2930
  */
2834
- emitAssets?: boolean;
2931
+ ssrTransform(code: string, inMap: SourceMap | {
2932
+ mappings: '';
2933
+ } | null, url: string, originalCode?: string): Promise<TransformResult | null>;
2835
2934
  /**
2836
- * Set to false to disable reporting compressed chunk sizes.
2837
- * Can slightly improve build speed.
2838
- * @default true
2935
+ * Load a given URL as an instantiated module for SSR.
2839
2936
  */
2840
- reportCompressedSize?: boolean;
2937
+ ssrLoadModule(url: string, opts?: {
2938
+ fixStacktrace?: boolean;
2939
+ }): Promise<Record<string, any>>;
2841
2940
  /**
2842
- * Adjust chunk size warning limit (in kB).
2843
- * @default 500
2941
+ * Returns a fixed version of the given stack
2844
2942
  */
2845
- chunkSizeWarningLimit?: number;
2943
+ ssrRewriteStacktrace(stack: string): string;
2846
2944
  /**
2847
- * Rollup watch options
2848
- * https://rollupjs.org/configuration-options/#watch
2849
- * @default null
2945
+ * Mutates the given SSR error by rewriting the stacktrace
2850
2946
  */
2851
- watch?: WatcherOptions | null;
2947
+ ssrFixStacktrace(e: Error): void;
2852
2948
  /**
2853
- * create the Build Environment instance
2949
+ * Triggers HMR for a module in the module graph. You can use the `server.moduleGraph`
2950
+ * API to retrieve the module to be reloaded. If `hmr` is false, this is a no-op.
2854
2951
  */
2855
- createEnvironment?: (name: string, config: ResolvedConfig) => Promise<BuildEnvironment> | BuildEnvironment;
2856
- }
2857
- interface BuildOptions extends BuildEnvironmentOptions {
2952
+ reloadModule(module: ModuleNode): Promise<void>;
2858
2953
  /**
2859
- * Build in library mode. The value should be the global name of the lib in
2860
- * UMD mode. This will produce esm + cjs + umd bundle formats with default
2861
- * configurations that are suitable for distributing libraries.
2862
- * @default false
2954
+ * Start the server.
2863
2955
  */
2864
- lib?: LibraryOptions | false;
2865
- }
2866
- interface LibraryOptions {
2956
+ listen(port?: number, isRestart?: boolean): Promise<ViteDevServer>;
2867
2957
  /**
2868
- * Path of library entry
2958
+ * Stop the server.
2869
2959
  */
2870
- entry: InputOption;
2960
+ close(): Promise<void>;
2871
2961
  /**
2872
- * The name of the exposed global variable. Required when the `formats` option includes
2873
- * `umd` or `iife`
2962
+ * Print server urls
2874
2963
  */
2875
- name?: string;
2964
+ printUrls(): void;
2876
2965
  /**
2877
- * Output bundle formats
2878
- * @default ['es', 'umd']
2966
+ * Bind CLI shortcuts
2879
2967
  */
2880
- formats?: LibraryFormats[];
2968
+ bindCLIShortcuts(options?: BindCLIShortcutsOptions<ViteDevServer>): void;
2881
2969
  /**
2882
- * The name of the package file output. The default file name is the name option
2883
- * of the project package.json. It can also be defined as a function taking the
2884
- * format as an argument.
2970
+ * Restart the server.
2971
+ *
2972
+ * @param forceOptimize - force the optimizer to re-bundle, same as --force cli flag
2885
2973
  */
2886
- fileName?: string | ((format: ModuleFormat, entryName: string) => string);
2887
- }
2888
- type LibraryFormats = 'es' | 'cjs' | 'umd' | 'iife';
2889
- interface ModulePreloadOptions {
2974
+ restart(forceOptimize?: boolean): Promise<void>;
2890
2975
  /**
2891
- * Whether to inject a module preload polyfill.
2892
- * Note: does not apply to library mode.
2893
- * @default true
2976
+ * Open browser
2894
2977
  */
2895
- polyfill?: boolean;
2978
+ openBrowser(): void;
2896
2979
  /**
2897
- * Resolve the list of dependencies to preload for a given dynamic import
2898
- * @experimental
2980
+ * Calling `await server.waitForRequestsIdle(id)` will wait until all static imports
2981
+ * are processed. If called from a load or transform plugin hook, the id needs to be
2982
+ * passed as a parameter to avoid deadlocks. Calling this function after the first
2983
+ * static imports section of the module graph has been processed will resolve immediately.
2899
2984
  */
2900
- resolveDependencies?: ResolveModulePreloadDependenciesFn;
2901
- }
2902
- interface ResolvedModulePreloadOptions {
2903
- polyfill: boolean;
2904
- resolveDependencies?: ResolveModulePreloadDependenciesFn;
2905
- }
2906
- type ResolveModulePreloadDependenciesFn = (filename: string, deps: string[], context: {
2907
- hostId: string;
2908
- hostType: 'html' | 'js';
2909
- }) => string[];
2910
- interface ResolvedBuildEnvironmentOptions extends Required<Omit<BuildEnvironmentOptions, 'polyfillModulePreload'>> {
2911
- modulePreload: false | ResolvedModulePreloadOptions;
2912
- }
2913
- interface ResolvedBuildOptions extends Required<Omit<BuildOptions, 'polyfillModulePreload'>> {
2914
- modulePreload: false | ResolvedModulePreloadOptions;
2915
- }
2916
- /**
2917
- * Bundles the app for production.
2918
- * Returns a Promise containing the build result.
2919
- */
2920
- declare function build(inlineConfig?: InlineConfig): Promise<RollupOutput | RollupOutput[] | RollupWatcher>;
2921
- type RenderBuiltAssetUrl = (filename: string, type: {
2922
- type: 'asset' | 'public';
2923
- hostId: string;
2924
- hostType: 'js' | 'css' | 'html';
2925
- ssr: boolean;
2926
- }) => string | {
2927
- relative?: boolean;
2928
- runtime?: string;
2929
- } | undefined;
2930
- declare class BuildEnvironment extends Environment {
2931
- mode: "build";
2932
- constructor(name: string, config: ResolvedConfig, setup?: {
2933
- options?: EnvironmentOptions;
2934
- });
2935
- init(): Promise<void>;
2936
- }
2937
- interface ViteBuilder {
2938
- environments: Record<string, BuildEnvironment>;
2939
- config: ResolvedConfig;
2940
- buildApp(): Promise<void>;
2941
- build(environment: BuildEnvironment): Promise<RollupOutput | RollupOutput[] | RollupWatcher>;
2985
+ waitForRequestsIdle: (ignoredId?: string) => Promise<void>;
2942
2986
  }
2943
- interface BuilderOptions {
2944
- sharedConfigBuild?: boolean;
2945
- sharedPlugins?: boolean;
2946
- entireApp?: boolean;
2947
- buildApp?: (builder: ViteBuilder) => Promise<void>;
2987
+ interface ResolvedServerUrls {
2988
+ local: string[];
2989
+ network: string[];
2948
2990
  }
2949
- type ResolvedBuilderOptions = Required<BuilderOptions>;
2950
- declare function createBuilder(inlineConfig?: InlineConfig): Promise<ViteBuilder>;
2991
+ declare function createServer(inlineConfig?: InlineConfig): Promise<ViteDevServer>;
2951
2992
 
2952
2993
  interface ESBuildOptions extends esbuild_TransformOptions {
2953
2994
  include?: string | RegExp | string[] | RegExp[];
@@ -2961,7 +3002,7 @@ interface ESBuildOptions extends esbuild_TransformOptions {
2961
3002
  type ESBuildTransformResult = Omit<esbuild_TransformResult, 'map'> & {
2962
3003
  map: SourceMap;
2963
3004
  };
2964
- declare function transformWithEsbuild(code: string, filename: string, options?: esbuild_TransformOptions, inMap?: object, root?: string, watcher?: any): Promise<ESBuildTransformResult>;
3005
+ declare function transformWithEsbuild(code: string, filename: string, options?: esbuild_TransformOptions, inMap?: object): Promise<ESBuildTransformResult>;
2965
3006
 
2966
3007
  interface FsUtils {
2967
3008
  existsSync: (path: string) => boolean;
@@ -2975,7 +3016,7 @@ interface FsUtils {
2975
3016
  initWatcher?: (watcher: FSWatcher) => void;
2976
3017
  }
2977
3018
 
2978
- interface ResolveOptions {
3019
+ interface EnvironmentResolveOptions {
2979
3020
  /**
2980
3021
  * @default ['browser', 'module', 'jsnext:main', 'jsnext']
2981
3022
  */
@@ -2987,10 +3028,6 @@ interface ResolveOptions {
2987
3028
  */
2988
3029
  extensions?: string[];
2989
3030
  dedupe?: string[];
2990
- /**
2991
- * @default false
2992
- */
2993
- preserveSymlinks?: boolean;
2994
3031
  /**
2995
3032
  * external/noExternal logic, this only works for certain environments
2996
3033
  * Previously this was ssr.external/ssr.noExternal
@@ -2999,6 +3036,12 @@ interface ResolveOptions {
2999
3036
  noExternal?: string | RegExp | (string | RegExp)[] | true;
3000
3037
  external?: string[] | true;
3001
3038
  }
3039
+ interface ResolveOptions extends EnvironmentResolveOptions {
3040
+ /**
3041
+ * @default false
3042
+ */
3043
+ preserveSymlinks?: boolean;
3044
+ }
3002
3045
  interface ResolvePluginOptions {
3003
3046
  root: string;
3004
3047
  isBuild: boolean;
@@ -3015,14 +3058,13 @@ interface ResolvePluginOptions {
3015
3058
  tryPrefix?: string;
3016
3059
  preferRelative?: boolean;
3017
3060
  isRequire?: boolean;
3018
- nodeCompatible?: boolean;
3019
3061
  webCompatible?: boolean;
3020
3062
  isFromTsImporter?: boolean;
3021
3063
  tryEsmOnly?: boolean;
3022
3064
  scan?: boolean;
3023
3065
  ssrOptimizeCheck?: boolean;
3024
3066
  /**
3025
- * @deprecated environment.options are used instead
3067
+ * @deprecated environment.config are used instead
3026
3068
  */
3027
3069
  ssrConfig?: SSROptions;
3028
3070
  }
@@ -3081,6 +3123,7 @@ type LightningCSSOptions = {
3081
3123
  pseudoClasses?: PseudoClasses
3082
3124
  unusedSymbols?: string[]
3083
3125
  cssModules?: CSSModulesConfig
3126
+ errorRecovery?: boolean
3084
3127
  }
3085
3128
 
3086
3129
  interface CSSOptions {
@@ -3119,7 +3162,6 @@ interface CSSOptions {
3119
3162
  * Enables css sourcemaps during dev
3120
3163
  * @default false
3121
3164
  * @experimental
3122
- * @deprecated use dev.sourcemap instead
3123
3165
  */
3124
3166
  devSourcemap?: boolean;
3125
3167
  /**
@@ -3153,7 +3195,7 @@ interface PreprocessCSSResult {
3153
3195
  /**
3154
3196
  * @experimental
3155
3197
  */
3156
- declare function preprocessCSS(code: string, filename: string, config: ResolvedConfig, environment?: Environment): Promise<PreprocessCSSResult>;
3198
+ declare function preprocessCSS(code: string, filename: string, config: ResolvedConfig): Promise<PreprocessCSSResult>;
3157
3199
  declare function formatPostcssSourceMap(rawMap: ExistingRawSourceMap, file: string): Promise<ExistingRawSourceMap>;
3158
3200
 
3159
3201
  interface HtmlTagDescriptor {
@@ -3224,23 +3266,29 @@ type IndexHtmlTransform = IndexHtmlTransformHook | {
3224
3266
  * If a plugin should be applied only for server or build, a function format
3225
3267
  * config file can be used to conditional determine the plugins to use.
3226
3268
  *
3227
- * The current module environment can be accessed from the context for the
3228
- * buildStart, resolveId, transform, load, and buildEnd, hooks
3229
- *
3230
- * The current environment can be accessed from the context for the
3231
- * buildStart, resolveId, transform, load, and buildEnd, hooks. It can be a dev
3232
- * or a build environment. Plugins can use this.environment.mode === 'dev' to
3233
- * check if they have access to dev specific APIs.
3269
+ * The current environment can be accessed from the context for the all non-global
3270
+ * hooks (it is not available in config, configResolved, configureServer, etc).
3271
+ * It can be a dev, build, or scan environment.
3272
+ * Plugins can use this.environment.mode === 'dev' to guard for dev specific APIs.
3234
3273
  */
3235
- type PluginEnvironment = DevEnvironment | BuildEnvironment | ScanEnvironment;
3236
- interface PluginContext extends rollup.PluginContext {
3237
- environment?: PluginEnvironment;
3274
+ interface PluginContextExtension {
3275
+ /**
3276
+ * Vite-specific environment instance
3277
+ */
3278
+ environment: Environment;
3238
3279
  }
3239
- interface ResolveIdPluginContext extends rollup.PluginContext {
3240
- environment?: PluginEnvironment;
3280
+ interface HotUpdatePluginContext {
3281
+ environment: DevEnvironment;
3282
+ }
3283
+ interface PluginContext extends rollup.PluginContext, PluginContextExtension {
3284
+ }
3285
+ interface ResolveIdPluginContext extends rollup.PluginContext, PluginContextExtension {
3286
+ }
3287
+ interface TransformPluginContext extends rollup.TransformPluginContext, PluginContextExtension {
3241
3288
  }
3242
- interface TransformPluginContext extends rollup.TransformPluginContext {
3243
- environment?: PluginEnvironment;
3289
+ declare module 'rollup' {
3290
+ interface PluginContext extends PluginContextExtension {
3291
+ }
3244
3292
  }
3245
3293
  /**
3246
3294
  * There are two types of plugins in Vite. App plugins and environment plugins.
@@ -3248,37 +3296,14 @@ interface TransformPluginContext extends rollup.TransformPluginContext {
3248
3296
  * once per each environment allowing users to have completely different plugins
3249
3297
  * for each of them. The constructor gets the resolved environment after the server
3250
3298
  * and builder has already been created simplifying config access and cache
3251
- * managementfor for environment specific plugins.
3299
+ * management for for environment specific plugins.
3252
3300
  * Environment Plugins are closer to regular rollup plugins. They can't define
3253
3301
  * app level hooks (like config, configResolved, configureServer, etc).
3254
3302
  */
3255
- type ModifyFunctionContext<Function_, NewContext> = Function_ extends (this: infer This, ...parameters: infer Arguments) => infer Return ? (this: NewContext, ...parameters: Arguments) => Return : never;
3256
- type ModifyObjectHookContext<Handler, Object_ extends {
3257
- handler: Handler;
3258
- }, NewContext> = Object_ & {
3259
- handler: ModifyFunctionContext<Handler, NewContext>;
3260
- };
3261
- type ModifyHookContext<Hook, NewContext> = Hook extends {
3262
- handler: infer Handler;
3263
- } ? ModifyObjectHookContext<Handler, Hook, NewContext> : ModifyFunctionContext<Hook, NewContext>;
3264
- interface BasePlugin<A = any> extends rollup.Plugin<A> {
3265
- /**
3266
- * Enforce plugin invocation tier similar to webpack loaders. Hooks ordering
3267
- * is still subject to the `order` property in the hook object.
3268
- *
3269
- * Plugin invocation order:
3270
- * - alias resolution
3271
- * - `enforce: 'pre'` plugins
3272
- * - vite core plugins
3273
- * - normal plugins
3274
- * - vite build plugins
3275
- * - `enforce: 'post'` plugins
3276
- * - vite build post plugins
3277
- */
3278
- enforce?: 'pre' | 'post';
3303
+ interface Plugin<A = any> extends rollup.Plugin<A> {
3279
3304
  /**
3280
3305
  * Perform custom handling of HMR updates.
3281
- * The handler receives a context containing changed filename, timestamp, a
3306
+ * The handler receives an options containing changed filename, timestamp, a
3282
3307
  * list of modules affected by the file change, and the dev server instance.
3283
3308
  *
3284
3309
  * - The hook can return a filtered list of modules to narrow down the update.
@@ -3286,42 +3311,27 @@ interface BasePlugin<A = any> extends rollup.Plugin<A> {
3286
3311
  * the descriptors.
3287
3312
  *
3288
3313
  * - The hook can also return an empty array and then perform custom updates
3289
- * by sending a custom hmr payload via server.hot.send().
3314
+ * by sending a custom hmr payload via environment.hot.send().
3290
3315
  *
3291
3316
  * - If the hook doesn't return a value, the hmr update will be performed as
3292
3317
  * normal.
3293
3318
  */
3294
- hotUpdate?: ObjectHook<(this: void, ctx: HotUpdateContext) => Array<EnvironmentModuleNode> | void | Promise<Array<EnvironmentModuleNode> | void>>;
3319
+ hotUpdate?: ObjectHook<(this: HotUpdatePluginContext, options: HotUpdateOptions) => Array<EnvironmentModuleNode> | void | Promise<Array<EnvironmentModuleNode> | void>>;
3295
3320
  /**
3296
3321
  * extend hooks with ssr flag
3297
3322
  */
3298
3323
  resolveId?: ObjectHook<(this: ResolveIdPluginContext, source: string, importer: string | undefined, options: {
3299
3324
  attributes: Record<string, string>;
3300
3325
  custom?: CustomPluginOptions;
3301
- /**
3302
- * @deprecated use this.environment
3303
- */
3304
3326
  ssr?: boolean;
3305
3327
  isEntry: boolean;
3306
3328
  }) => Promise<ResolveIdResult> | ResolveIdResult>;
3307
3329
  load?: ObjectHook<(this: PluginContext, id: string, options?: {
3308
- /**
3309
- * @deprecated use this.environment
3310
- */
3311
3330
  ssr?: boolean;
3312
3331
  }) => Promise<LoadResult> | LoadResult>;
3313
3332
  transform?: ObjectHook<(this: TransformPluginContext, code: string, id: string, options?: {
3314
- /**
3315
- * @deprecated use this.environment
3316
- */
3317
3333
  ssr?: boolean;
3318
3334
  }) => Promise<rollup.TransformResult> | rollup.TransformResult>;
3319
- buildStart?: ModifyHookContext<rollup.Plugin<A>['buildStart'], PluginContext>;
3320
- generateBundle?: ModifyHookContext<rollup.Plugin<A>['generateBundle'], PluginContext>;
3321
- renderChunk?: ModifyHookContext<rollup.Plugin<A>['renderChunk'], PluginContext>;
3322
- }
3323
- type BoundedPlugin<A = any> = BasePlugin<A>;
3324
- interface Plugin<A = any> extends BasePlugin<A> {
3325
3335
  /**
3326
3336
  * Opt-in this plugin into the shared plugins pipeline.
3327
3337
  * For backward-compatibility, plugins are re-recreated for each environment
@@ -3331,10 +3341,37 @@ interface Plugin<A = any> extends BasePlugin<A> {
3331
3341
  * @experimental
3332
3342
  */
3333
3343
  sharedDuringBuild?: boolean;
3344
+ /**
3345
+ * Opt-in this plugin into per-environment buildStart and buildEnd during dev.
3346
+ * For backward-compatibility, the buildStart hook is called only once during
3347
+ * dev, for the client environment. Plugins can opt-in to be called
3348
+ * per-environment, aligning with the build hook behavior.
3349
+ * @experimental
3350
+ */
3351
+ perEnvironmentStartEndDuringDev?: boolean;
3352
+ /**
3353
+ * Enforce plugin invocation tier similar to webpack loaders. Hooks ordering
3354
+ * is still subject to the `order` property in the hook object.
3355
+ *
3356
+ * Plugin invocation order:
3357
+ * - alias resolution
3358
+ * - `enforce: 'pre'` plugins
3359
+ * - vite core plugins
3360
+ * - normal plugins
3361
+ * - vite build plugins
3362
+ * - `enforce: 'post'` plugins
3363
+ * - vite build post plugins
3364
+ */
3365
+ enforce?: 'pre' | 'post';
3334
3366
  /**
3335
3367
  * Apply the plugin only for serve or build, or on certain conditions.
3336
3368
  */
3337
3369
  apply?: 'serve' | 'build' | ((this: void, config: UserConfig, env: ConfigEnv) => boolean);
3370
+ /**
3371
+ * Define environments where this plugin should be active
3372
+ * By default, the plugin is active in all environments
3373
+ */
3374
+ applyToEnvironment?: (environment: Environment) => boolean;
3338
3375
  /**
3339
3376
  * Modify vite config before it's resolved. The hook can either mutate the
3340
3377
  * passed-in config directly, or return a partial config object that will be
@@ -3396,9 +3433,19 @@ interface Plugin<A = any> extends BasePlugin<A> {
3396
3433
  */
3397
3434
  transformIndexHtml?: IndexHtmlTransform;
3398
3435
  /**
3399
- * @deprecated
3400
- * Compat support, ctx.modules is a backward compatible ModuleNode array
3401
- * with the mixed client and ssr moduleGraph. Use hotUpdate instead
3436
+ * Perform custom handling of HMR updates.
3437
+ * The handler receives a context containing changed filename, timestamp, a
3438
+ * list of modules affected by the file change, and the dev server instance.
3439
+ *
3440
+ * - The hook can return a filtered list of modules to narrow down the update.
3441
+ * e.g. for a Vue SFC, we can narrow down the part to update by comparing
3442
+ * the descriptors.
3443
+ *
3444
+ * - The hook can also return an empty array and then perform custom updates
3445
+ * by sending a custom hmr payload via server.ws.send().
3446
+ *
3447
+ * - If the hook doesn't return a value, the hmr update will be performed as
3448
+ * normal.
3402
3449
  */
3403
3450
  handleHotUpdate?: ObjectHook<(this: void, ctx: HmrContext) => Array<ModuleNode> | void | Promise<Array<ModuleNode> | void>>;
3404
3451
  }
@@ -3406,11 +3453,9 @@ type HookHandler<T> = T extends ObjectHook<infer H> ? H : T;
3406
3453
  type PluginWithRequiredHook<K extends keyof Plugin> = Plugin & {
3407
3454
  [P in K]: NonNullable<Plugin[P]>;
3408
3455
  };
3409
- type BoundedPluginConstructor = (Environment: PluginEnvironment) => BoundedPluginOption;
3410
- type MaybeBoundedPlugin = BoundedPlugin | false | null | undefined;
3411
- type BoundedPluginOption = MaybeBoundedPlugin | BoundedPluginOption[] | Promise<MaybeBoundedPlugin | BoundedPluginOption[]>;
3412
- type MaybePlugin = Plugin | BoundedPluginConstructor | false | null | undefined;
3413
- type PluginOption = MaybePlugin | PluginOption[] | Promise<MaybePlugin | PluginOption[]>;
3456
+ type Thenable<T> = T | Promise<T>;
3457
+ type FalsyPlugin = false | null | undefined;
3458
+ type PluginOption = Thenable<Plugin | FalsyPlugin | PluginOption[]>;
3414
3459
 
3415
3460
  interface JsonOptions {
3416
3461
  /**
@@ -3427,31 +3472,15 @@ interface JsonOptions {
3427
3472
  }
3428
3473
 
3429
3474
  type SSRTarget = 'node' | 'webworker';
3430
- type SsrDepOptimizationOptions = DepOptimizationConfig;
3431
- /**
3432
- * @deprecated use environments.ssr
3433
- */
3475
+ type SsrDepOptimizationConfig = DepOptimizationConfig;
3434
3476
  interface SSROptions {
3435
- /**
3436
- * @deprecated use environment.resolve.noExternal
3437
- */
3438
3477
  noExternal?: string | RegExp | (string | RegExp)[] | true;
3439
- /**
3440
- * @deprecated use environment.resolve.external
3441
- */
3442
3478
  external?: string[] | true;
3443
3479
  /**
3444
3480
  * Define the target for the ssr build. The browser field in package.json
3445
3481
  * is ignored for node but used if webworker is the target
3446
- *
3447
- * if (ssr.target === 'webworker') {
3448
- * build.rollupOptions.entryFileNames = '[name].js'
3449
- * build.rollupOptions.inlineDynamicImports = (typeof input === 'string' || Object.keys(input).length === 1))
3450
- * webCompatible = true
3451
- * }
3452
- *
3482
+ * This option may be replaced by the experimental `environmentOptions.webCompatible`
3453
3483
  * @default 'node'
3454
- * @deprecated use environment.webCompatible
3455
3484
  */
3456
3485
  target?: SSRTarget;
3457
3486
  /**
@@ -3461,12 +3490,8 @@ interface SSROptions {
3461
3490
  * During dev:
3462
3491
  * explicit no external CJS dependencies are optimized by default
3463
3492
  * @experimental
3464
- * @deprecated
3465
- */
3466
- optimizeDeps?: SsrDepOptimizationOptions;
3467
- /**
3468
- * @deprecated
3469
3493
  */
3494
+ optimizeDeps?: SsrDepOptimizationConfig;
3470
3495
  resolve?: {
3471
3496
  /**
3472
3497
  * Conditions that are used in the plugin pipeline. The default value is the root config's `resolve.conditions`.
@@ -3474,21 +3499,19 @@ interface SSROptions {
3474
3499
  * Use this to override the default ssr conditions for the ssr build.
3475
3500
  *
3476
3501
  * @default rootConfig.resolve.conditions
3477
- * @deprecated
3478
3502
  */
3479
3503
  conditions?: string[];
3480
3504
  /**
3481
3505
  * Conditions that are used during ssr import (including `ssrLoadModule`) of externalized dependencies.
3482
3506
  *
3483
3507
  * @default []
3484
- * @deprecated
3485
3508
  */
3486
3509
  externalConditions?: string[];
3487
3510
  };
3488
3511
  }
3489
3512
  interface ResolvedSSROptions extends SSROptions {
3490
3513
  target: SSRTarget;
3491
- optimizeDeps: SsrDepOptimizationOptions;
3514
+ optimizeDeps: SsrDepOptimizationConfig;
3492
3515
  }
3493
3516
 
3494
3517
  interface ConfigEnv {
@@ -3522,9 +3545,12 @@ declare function defineConfig(config: UserConfig): UserConfig;
3522
3545
  declare function defineConfig(config: Promise<UserConfig>): Promise<UserConfig>;
3523
3546
  declare function defineConfig(config: UserConfigFnObject): UserConfigFnObject;
3524
3547
  declare function defineConfig(config: UserConfigExport): UserConfigExport;
3548
+ interface CreateDevEnvironmentContext {
3549
+ ws: WebSocketServer;
3550
+ }
3525
3551
  interface DevEnvironmentOptions {
3526
3552
  /**
3527
- * Files tßo be pre-transformed. Supports glob patterns.
3553
+ * Files to be pre-transformed. Supports glob patterns.
3528
3554
  */
3529
3555
  warmup?: string[];
3530
3556
  /**
@@ -3553,11 +3579,11 @@ interface DevEnvironmentOptions {
3553
3579
  /**
3554
3580
  * Optimize deps config
3555
3581
  */
3556
- optimizeDeps?: DepOptimizationConfig;
3582
+ optimizeDeps?: DepOptimizationOptions;
3557
3583
  /**
3558
3584
  * create the Dev Environment instance
3559
3585
  */
3560
- createEnvironment?: (name: string, config: ResolvedConfig) => Promise<DevEnvironment> | DevEnvironment;
3586
+ createEnvironment?: (name: string, config: ResolvedConfig, context: CreateDevEnvironmentContext) => Promise<DevEnvironment> | DevEnvironment;
3561
3587
  /**
3562
3588
  * For environments that support a full-reload, like the client, we can short-circuit when
3563
3589
  * restarting the server throwing early to stop processing current files. We avoided this for
@@ -3572,30 +3598,30 @@ interface DevEnvironmentOptions {
3572
3598
  */
3573
3599
  moduleRunnerTransform?: boolean;
3574
3600
  }
3575
- type ResolvedDevEnvironmentOptions = Required<Omit<DevEnvironmentOptions, 'createEnvironment'>> & {
3576
- createEnvironment: ((name: string, config: ResolvedConfig) => Promise<DevEnvironment> | DevEnvironment) | undefined;
3577
- };
3578
- type EnvironmentResolveOptions = ResolveOptions & {
3601
+ type ResolvedDevEnvironmentOptions = Required<DevEnvironmentOptions>;
3602
+ type AllResolveOptions = ResolveOptions & {
3579
3603
  alias?: AliasOptions;
3580
3604
  };
3581
3605
  interface SharedEnvironmentOptions {
3606
+ /**
3607
+ * Define global variable replacements.
3608
+ * Entries will be defined on `window` during dev and replaced during build.
3609
+ */
3610
+ define?: Record<string, any>;
3582
3611
  /**
3583
3612
  * Configure resolver
3584
3613
  */
3585
3614
  resolve?: EnvironmentResolveOptions;
3615
+ /**
3616
+ * Define if this environment is used for Server Side Rendering
3617
+ * @default 'server' if it isn't the client environment
3618
+ */
3619
+ consumer?: 'client' | 'server';
3586
3620
  /**
3587
3621
  * Runtime Compatibility
3588
3622
  * Temporal options, we should remove these in favor of fine-grained control
3589
3623
  */
3590
- nodeCompatible?: boolean;
3591
3624
  webCompatible?: boolean;
3592
- /**
3593
- * Should Vite inject timestamp if module is invalidated
3594
- * Disabling this will break built-in HMR support
3595
- * @experimental
3596
- * @default true
3597
- */
3598
- injectInvalidationTimestamp?: boolean;
3599
3625
  }
3600
3626
  interface EnvironmentOptions extends SharedEnvironmentOptions {
3601
3627
  /**
@@ -3607,17 +3633,17 @@ interface EnvironmentOptions extends SharedEnvironmentOptions {
3607
3633
  */
3608
3634
  build?: BuildEnvironmentOptions;
3609
3635
  }
3610
- type ResolvedEnvironmentResolveOptions = Required<EnvironmentResolveOptions>;
3636
+ type ResolvedResolveOptions = Required<ResolveOptions>;
3611
3637
  type ResolvedEnvironmentOptions = {
3612
- resolve: ResolvedEnvironmentResolveOptions;
3613
- nodeCompatible: boolean;
3638
+ define?: Record<string, any>;
3639
+ resolve: ResolvedResolveOptions;
3640
+ consumer: 'client' | 'server';
3614
3641
  webCompatible: boolean;
3615
- injectInvalidationTimestamp: boolean;
3616
3642
  dev: ResolvedDevEnvironmentOptions;
3617
3643
  build: ResolvedBuildEnvironmentOptions;
3618
3644
  };
3619
- type DefaultEnvironmentOptions = Omit<EnvironmentOptions, 'build' | 'nodeCompatible' | 'webCompatible'> & {
3620
- build?: BuildOptions;
3645
+ type DefaultEnvironmentOptions = Omit<EnvironmentOptions, 'consumer' | 'webCompatible' | 'resolve'> & {
3646
+ resolve?: AllResolveOptions;
3621
3647
  };
3622
3648
  interface UserConfig extends DefaultEnvironmentOptions {
3623
3649
  /**
@@ -3655,11 +3681,6 @@ interface UserConfig extends DefaultEnvironmentOptions {
3655
3681
  * each command, and can be overridden by the command line --mode option.
3656
3682
  */
3657
3683
  mode?: string;
3658
- /**
3659
- * Define global variable replacements.
3660
- * Entries will be defined on `window` during dev and replaced during build.
3661
- */
3662
- define?: Record<string, any>;
3663
3684
  /**
3664
3685
  * Array of vite plugins to use.
3665
3686
  */
@@ -3705,6 +3726,10 @@ interface UserConfig extends DefaultEnvironmentOptions {
3705
3726
  * @experimental
3706
3727
  */
3707
3728
  experimental?: ExperimentalOptions;
3729
+ /**
3730
+ * Options to opt-in to future behavior
3731
+ */
3732
+ future?: FutureOptions;
3708
3733
  /**
3709
3734
  * Legacy options
3710
3735
  *
@@ -3786,6 +3811,14 @@ interface HTMLOptions {
3786
3811
  */
3787
3812
  cspNonce?: string;
3788
3813
  }
3814
+ interface FutureOptions {
3815
+ removePluginHookHandleHotUpdate?: 'warn';
3816
+ removePluginHookSsrArgument?: 'warn';
3817
+ removeServerModuleGraph?: 'warn';
3818
+ removeServerHot?: 'warn';
3819
+ removeServerTransformRequest?: 'warn';
3820
+ removeSsrLoadModule?: 'warn';
3821
+ }
3789
3822
  interface ExperimentalOptions {
3790
3823
  /**
3791
3824
  * Append fake `&lang.(ext)` when queries are specified, to preserve the file extension for following plugins to process.
@@ -3859,7 +3892,6 @@ type ResolvedConfig = Readonly<Omit<UserConfig, 'plugins' | 'css' | 'assetsInclu
3859
3892
  alias: Alias[];
3860
3893
  };
3861
3894
  plugins: readonly Plugin[];
3862
- rawPlugins: readonly (Plugin | BoundedPluginConstructor)[];
3863
3895
  css: ResolvedCSSOptions;
3864
3896
  esbuild: ESBuildOptions | false;
3865
3897
  server: ResolvedServerOptions;
@@ -3882,7 +3914,9 @@ interface PluginHookUtils {
3882
3914
  getSortedPluginHooks: <K extends keyof Plugin>(hookName: K) => NonNullable<HookHandler<Plugin[K]>>[];
3883
3915
  }
3884
3916
  type ResolveFn = (id: string, importer?: string, aliasOnly?: boolean, ssr?: boolean) => Promise<string | undefined>;
3885
- declare function resolveConfig(inlineConfig: InlineConfig, command: 'build' | 'serve', defaultMode?: string, defaultNodeEnv?: string, isPreview?: boolean, patchConfig?: ((config: ResolvedConfig) => void) | undefined, patchPlugins?: ((plugins: (Plugin | BoundedPluginConstructor)[]) => void) | undefined): Promise<ResolvedConfig>;
3917
+ declare function resolveConfig(inlineConfig: InlineConfig, command: 'build' | 'serve', defaultMode?: string, defaultNodeEnv?: string, isPreview?: boolean,
3918
+
3919
+ ): Promise<ResolvedConfig>;
3886
3920
  declare function sortUserPlugins(plugins: (Plugin | Plugin[])[] | undefined): [Plugin[], Plugin[], Plugin[]];
3887
3921
  declare function loadConfigFromFile(configEnv: ConfigEnv, configFile?: string, configRoot?: string, logLevel?: LogLevel, customLogger?: Logger): Promise<{
3888
3922
  path: string;
@@ -3890,9 +3924,16 @@ declare function loadConfigFromFile(configEnv: ConfigEnv, configFile?: string, c
3890
3924
  dependencies: string[];
3891
3925
  } | null>;
3892
3926
 
3927
+ type ResolveIdFn = (environment: PartialEnvironment, id: string, importer?: string, aliasOnly?: boolean) => Promise<string | undefined>;
3928
+ /**
3929
+ * Create an internal resolver to be used in special scenarios, e.g.
3930
+ * optimizer and handling css @imports
3931
+ */
3932
+ declare function createIdResolver(config: ResolvedConfig, options?: Partial<InternalResolveOptions>): ResolveIdFn;
3933
+
3893
3934
  declare function buildErrorMessage(err: RollupError, args?: string[], includeStack?: boolean): string;
3894
3935
 
3895
- declare function createNodeDevEnvironment(name: string, config: ResolvedConfig, options?: DevEnvironmentSetup): DevEnvironment;
3936
+ declare function createNodeDevEnvironment(name: string, config: ResolvedConfig, context: DevEnvironmentContext): DevEnvironment;
3896
3937
 
3897
3938
  /**
3898
3939
  * @experimental
@@ -3921,21 +3962,30 @@ declare function createServerModuleRunner(environment: DevEnvironment, options?:
3921
3962
  * @experimental
3922
3963
  */
3923
3964
  declare class ServerHMRConnector implements ModuleRunnerHMRConnection {
3924
- private hmrChannel;
3965
+ private hotChannel;
3925
3966
  private handlers;
3926
3967
  private hmrClient;
3927
3968
  private connected;
3928
- constructor(hmrChannel: ServerHMRChannel);
3969
+ constructor(hotChannel: ServerHotChannel);
3929
3970
  isReady(): boolean;
3930
3971
  send(message: string): void;
3931
- onUpdate(handler: (payload: HMRPayload) => void): void;
3972
+ onUpdate(handler: (payload: HotPayload) => void): void;
3973
+ }
3974
+
3975
+ interface ModuleRunnerTransformOptions {
3976
+ json?: {
3977
+ stringify?: boolean;
3978
+ };
3932
3979
  }
3980
+ declare function ssrTransform(code: string, inMap: SourceMap | {
3981
+ mappings: '';
3982
+ } | null, url: string, originalCode: string, options?: ModuleRunnerTransformOptions): Promise<TransformResult | null>;
3933
3983
 
3934
3984
  declare const VERSION: string;
3935
3985
 
3936
3986
  declare const isCSSRequest: (request: string) => boolean;
3937
3987
  /**
3938
- * @deprecated use build.rollupOutput.manualChunks or framework specific configuration
3988
+ * @deprecated use build.rollupOptions.output.manualChunks or framework specific configuration
3939
3989
  */
3940
3990
  declare class SplitVendorChunkCache {
3941
3991
  cache: Map<string, boolean>;
@@ -3943,13 +3993,13 @@ declare class SplitVendorChunkCache {
3943
3993
  reset(): void;
3944
3994
  }
3945
3995
  /**
3946
- * @deprecated use build.rollupOutput.manualChunks or framework specific configuration
3996
+ * @deprecated use build.rollupOptions.output.manualChunks or framework specific configuration
3947
3997
  */
3948
3998
  declare function splitVendorChunk(options?: {
3949
3999
  cache?: SplitVendorChunkCache;
3950
4000
  }): GetManualChunk;
3951
4001
  /**
3952
- * @deprecated use build.rollupOutput.manualChunks or framework specific configuration
4002
+ * @deprecated use build.rollupOptions.output.manualChunks or framework specific configuration
3953
4003
  */
3954
4004
  declare function splitVendorChunkPlugin(): Plugin;
3955
4005
 
@@ -3982,9 +4032,13 @@ declare function searchForWorkspaceRoot(current: string, root?: string): string;
3982
4032
 
3983
4033
  /**
3984
4034
  * Check if the url is allowed to be served, via the `server.fs` config.
3985
- * @deprecate use isFileLoadingAllowed
4035
+ */
4036
+ declare function isFileServingAllowed(config: ResolvedConfig, url: string): boolean;
4037
+ /**
4038
+ * @deprecated Use the `isFileServingAllowed(config, url)` signature instead.
3986
4039
  */
3987
4040
  declare function isFileServingAllowed(url: string, server: ViteDevServer): boolean;
4041
+ declare function isFileLoadingAllowed(config: ResolvedConfig, filePath: string): boolean;
3988
4042
 
3989
4043
  declare function loadEnv(mode: string, envDir: string, prefixes?: string | string[]): Record<string, string>;
3990
4044
  declare function resolveEnvPrefix({ envPrefix, }: UserConfig): string[];
@@ -4002,4 +4056,4 @@ interface ManifestChunk {
4002
4056
  dynamicImports?: string[];
4003
4057
  }
4004
4058
 
4005
- export { type Alias, type AliasOptions, type AnymatchFn, type AnymatchPattern, type AppType, type AwaitWriteFinishOptions, type BindCLIShortcutsOptions, type BoundedPlugin, type BoundedPluginConstructor, BuildEnvironment, type BuildEnvironmentOptions, type BuildOptions, type BuilderOptions, type CLIShortcut, type CSSModulesOptions, type CSSOptions, type CommonServerOptions, type ConfigEnv, Connect, type CorsOptions, type CorsOrigin, type DepOptimizationConfig, type DepOptimizationMetadata, type DepOptimizationOptions, DevEnvironment, type DevEnvironmentOptions, type DevEnvironmentSetup, type ESBuildOptions, type ESBuildTransformResult, EnvironmentModuleGraph, EnvironmentModuleNode, type ExperimentalOptions, type ExportsData, FSWatcher, type FetchModuleOptions, type FileSystemServeOptions, type FilterPattern, type HMRBroadcaster, type HMRBroadcasterClient, type HMRChannel, type HTMLOptions, type HmrContext, type HmrOptions, type HookHandler, type HotUpdateContext, type HtmlTagDescriptor, HttpProxy, type IndexHtmlTransform, type IndexHtmlTransformContext, type IndexHtmlTransformHook, type IndexHtmlTransformResult, type InlineConfig, type InternalResolveOptions, type JsonOptions, type LegacyOptions, type LibraryFormats, type LibraryOptions, type LightningCSSOptions, type LogErrorOptions, type LogLevel, type LogOptions, type LogType, type Logger, type LoggerOptions, type Manifest, type ManifestChunk, type MapToFunction, type AnymatchMatcher as Matcher, ModuleGraph, ModuleNode, type ModulePreloadOptions, type OptimizedDepInfo, type Plugin, type PluginContainer, type PluginHookUtils, type PluginOption, type PreprocessCSSResult, type PreviewOptions, type PreviewServer, type PreviewServerHook, type ProxyOptions, RemoteEnvironmentTransport, type RenderBuiltAssetUrl, type ResolveFn, type ResolveModulePreloadDependenciesFn, type ResolveOptions, type ResolvedBuildEnvironmentOptions, type ResolvedBuildOptions, type ResolvedCSSOptions, type ResolvedConfig, type ResolvedDevEnvironmentOptions, type ResolvedModulePreloadOptions, type ResolvedPreviewOptions, type ResolvedSSROptions, type ResolvedServerOptions, type ResolvedServerUrls, type ResolvedUrl, type ResolvedWorkerOptions, type ResolverFunction, type ResolverObject, type RollupCommonJSOptions, type RollupDynamicImportVarsOptions, type SSROptions, type SSRTarget, type SendOptions, type ServerHMRChannel, ServerHMRConnector, type ServerHook, type ServerModuleRunnerOptions, type ServerOptions, SplitVendorChunkCache, type SsrDepOptimizationOptions, Terser, type TerserOptions, type TransformOptions, type TransformResult, type UserConfig, type UserConfigExport, type UserConfigFn, type UserConfigFnObject, type UserConfigFnPromise, type ViteBuilder, type ViteDevServer, type WatchOptions, WebSocket, WebSocketAlias, type WebSocketClient, type WebSocketCustomListener, WebSocketServer, build, buildErrorMessage, createBuilder, createFilter, createLogger, createNodeDevEnvironment, createServer, createServerModuleRunner, defineConfig, fetchModule, formatPostcssSourceMap, isCSSRequest, isFileServingAllowed, loadConfigFromFile, loadEnv, mergeAlias, mergeConfig, normalizePath, preprocessCSS, preview, resolveConfig, resolveEnvPrefix, rollupVersion, searchForWorkspaceRoot, send, sortUserPlugins, splitVendorChunk, splitVendorChunkPlugin, transformWithEsbuild, VERSION as version };
4059
+ export { type Alias, type AliasOptions, type AnymatchFn, type AnymatchPattern, type AppType, type AwaitWriteFinishOptions, type BindCLIShortcutsOptions, BuildEnvironment, type BuildEnvironmentOptions, type BuildOptions, type BuilderOptions, type CLIShortcut, type CSSModulesOptions, type CSSOptions, type CommonServerOptions, type ConfigEnv, Connect, type CorsOptions, type CorsOrigin, type DepOptimizationConfig, type DepOptimizationMetadata, type DepOptimizationOptions, DevEnvironment, type DevEnvironmentContext, type DevEnvironmentOptions, type ESBuildOptions, type ESBuildTransformResult, type Environment, EnvironmentModuleGraph, EnvironmentModuleNode, type EnvironmentOptions, type ExperimentalOptions, type ExportsData, FSWatcher, type FetchModuleOptions, type FileSystemServeOptions, type FilterPattern, type HMRBroadcaster, type HMRBroadcasterClient, type HMRChannel, type HTMLOptions, type HmrContext, type HmrOptions, type HookHandler, type HotChannel, type HotChannelClient, type HotUpdateOptions, type HtmlTagDescriptor, HttpProxy, type HttpServer, type IndexHtmlTransform, type IndexHtmlTransformContext, type IndexHtmlTransformHook, type IndexHtmlTransformResult, type InlineConfig, type InternalResolveOptions, type JsonOptions, type LegacyOptions, type LibraryFormats, type LibraryOptions, type LightningCSSOptions, type LogErrorOptions, type LogLevel, type LogOptions, type LogType, type Logger, type LoggerOptions, type Manifest, type ManifestChunk, type MapToFunction, type AnymatchMatcher as Matcher, ModuleGraph, ModuleNode, type ModulePreloadOptions, type ModuleRunnerTransformOptions, type OptimizedDepInfo, type Plugin, PluginContainer, type PluginHookUtils, type PluginOption, type PreprocessCSSResult, type PreviewOptions, type PreviewServer, type PreviewServerHook, type ProxyOptions, RemoteEnvironmentTransport, type RenderBuiltAssetUrl, type ResolveFn, type ResolveModulePreloadDependenciesFn, type ResolveOptions, type ResolvedBuildEnvironmentOptions, type ResolvedBuildOptions, type ResolvedCSSOptions, type ResolvedConfig, type ResolvedDevEnvironmentOptions, type ResolvedModulePreloadOptions, type ResolvedPreviewOptions, type ResolvedSSROptions, type ResolvedServerOptions, type ResolvedServerUrls, type ResolvedUrl, type ResolvedWorkerOptions, type ResolverFunction, type ResolverObject, type RollupCommonJSOptions, type RollupDynamicImportVarsOptions, type SSROptions, type SSRTarget, type SendOptions, type ServerHMRChannel, ServerHMRConnector, type ServerHook, type ServerHotChannel, type ServerModuleRunnerOptions, type ServerOptions, SplitVendorChunkCache, type SsrDepOptimizationConfig, Terser, type TerserOptions, type TransformOptions, type TransformResult, type UserConfig, type UserConfigExport, type UserConfigFn, type UserConfigFnObject, type UserConfigFnPromise, type ViteBuilder, type ViteDevServer, type WatchOptions, WebSocket, WebSocketAlias, type WebSocketClient, type WebSocketCustomListener, WebSocketServer, build, buildErrorMessage, createBuilder, createFilter, createIdResolver, createLogger, createNodeDevEnvironment, createServer, createServerHotChannel, createServerModuleRunner, defineConfig, fetchModule, formatPostcssSourceMap, isCSSRequest, isFileLoadingAllowed, isFileServingAllowed, loadConfigFromFile, loadEnv, mergeAlias, mergeConfig, ssrTransform as moduleRunnerTransform, normalizePath, optimizeDeps, preprocessCSS, preview, resolveConfig, resolveEnvPrefix, rollupVersion, searchForWorkspaceRoot, send, sortUserPlugins, splitVendorChunk, splitVendorChunkPlugin, transformWithEsbuild, VERSION as version };