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