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