vite 2.7.0 → 2.7.4
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.
Potentially problematic release.
This version of vite might be problematic. Click here for more details.
- package/CHANGELOG.md +78 -29
- package/LICENSE.md +41 -11
- package/dist/client/client.mjs.map +1 -1
- package/dist/node/build.d.ts +200 -0
- package/dist/node/chunks/{dep-58399509.js → dep-2d8e2cb1.js} +1 -1
- package/dist/node/chunks/dep-2d8e2cb1.js.map +1 -0
- package/dist/node/chunks/{dep-4dd87a09.js → dep-a89a79de.js} +2 -2
- package/dist/node/chunks/{dep-4dd87a09.js.map → dep-a89a79de.js.map} +1 -1
- package/dist/node/chunks/{dep-7e125991.js → dep-cb6d7f22.js} +660 -209
- package/dist/node/chunks/dep-cb6d7f22.js.map +1 -0
- package/dist/node/chunks/{dep-1ce37657.js → dep-ef3cdce0.js} +79 -61
- package/dist/node/chunks/dep-ef3cdce0.js.map +1 -0
- package/dist/node/chunks/{dep-4619561c.js → dep-fd7e14cf.js} +2 -2
- package/dist/node/chunks/dep-fd7e14cf.js.map +1 -0
- package/dist/node/cli.d.ts +1 -0
- package/dist/node/cli.js +4 -4
- package/dist/node/cli.js.map +1 -1
- package/dist/node/config.d.ts +202 -0
- package/dist/node/constants.d.ts +33 -0
- package/dist/node/http.d.ts +84 -0
- package/dist/node/importGlob.d.ts +9 -0
- package/dist/node/index.d.ts +317 -322
- package/dist/node/index.js +1 -1
- package/dist/node/logger.d.ts +35 -0
- package/dist/node/optimizer/esbuildDepPlugin.d.ts +4 -0
- package/dist/node/optimizer/index.d.ts +66 -0
- package/dist/node/optimizer/registerMissing.d.ts +2 -0
- package/dist/node/optimizer/scan.d.ts +9 -0
- package/dist/node/packages.d.ts +25 -0
- package/dist/node/plugin.d.ts +115 -0
- package/dist/node/plugins/asset.d.ts +40 -0
- package/dist/node/plugins/assetImportMetaUrl.d.ts +13 -0
- package/dist/node/plugins/clientInjections.d.ts +7 -0
- package/dist/node/plugins/css.d.ts +70 -0
- package/dist/node/plugins/dataUri.d.ts +5 -0
- package/dist/node/plugins/define.d.ts +3 -0
- package/dist/node/plugins/esbuild.d.ts +15 -0
- package/dist/node/plugins/html.d.ts +102 -0
- package/dist/node/plugins/importAnalysis.d.ts +46 -0
- package/dist/node/plugins/importAnalysisBuild.d.ts +15 -0
- package/dist/node/plugins/index.d.ts +3 -0
- package/dist/node/plugins/json.d.ts +22 -0
- package/dist/node/plugins/loadFallback.d.ts +5 -0
- package/dist/node/plugins/manifest.d.ts +14 -0
- package/dist/node/plugins/modulePreloadPolyfill.d.ts +4 -0
- package/dist/node/plugins/preAlias.d.ts +5 -0
- package/dist/node/plugins/reporter.d.ts +3 -0
- package/dist/node/plugins/resolve.d.ts +38 -0
- package/dist/node/plugins/ssrRequireHook.d.ts +12 -0
- package/dist/node/plugins/terser.d.ts +3 -0
- package/dist/node/plugins/wasm.d.ts +3 -0
- package/dist/node/plugins/worker.d.ts +3 -0
- package/dist/node/preview.d.ts +31 -0
- package/dist/node/server/hmr.d.ts +37 -0
- package/dist/node/server/index.d.ts +215 -0
- package/dist/node/server/middlewares/base.d.ts +3 -0
- package/dist/node/server/middlewares/error.d.ts +8 -0
- package/dist/node/server/middlewares/indexHtml.d.ts +4 -0
- package/dist/node/server/middlewares/proxy.d.ts +20 -0
- package/dist/node/server/middlewares/spaFallback.d.ts +2 -0
- package/dist/node/server/middlewares/static.d.ts +6 -0
- package/dist/node/server/middlewares/time.d.ts +2 -0
- package/dist/node/server/middlewares/transform.d.ts +3 -0
- package/dist/node/server/moduleGraph.d.ts +53 -0
- package/dist/node/server/openBrowser.d.ts +15 -0
- package/dist/node/server/pluginContainer.d.ts +37 -0
- package/dist/node/server/searchRoot.d.ts +8 -0
- package/dist/node/server/send.d.ts +4 -0
- package/dist/node/server/sourcemap.d.ts +8 -0
- package/dist/node/server/transformRequest.d.ts +14 -0
- package/dist/node/server/ws.d.ts +14 -0
- package/dist/node/ssr/ssrExternal.d.ts +7 -0
- package/dist/node/ssr/ssrManifestPlugin.d.ts +3 -0
- package/dist/node/ssr/ssrModuleLoader.d.ts +7 -0
- package/dist/node/ssr/ssrStacktrace.d.ts +3 -0
- package/dist/node/ssr/ssrTransform.d.ts +8 -0
- package/dist/node/utils.d.ts +114 -0
- package/package.json +15 -15
- package/src/client/client.ts +2 -2
- package/src/client/overlay.ts +1 -1
- package/types/alias.d.ts +1 -1
- package/types/chokidar.d.ts +2 -2
- package/types/http-proxy.d.ts +4 -4
- package/types/importMeta.d.ts +13 -14
- package/types/shims.d.ts +5 -5
- package/types/ws.d.ts +284 -288
- package/dist/node/chunks/dep-1ce37657.js.map +0 -1
- package/dist/node/chunks/dep-4619561c.js.map +0 -1
- package/dist/node/chunks/dep-58399509.js.map +0 -1
- package/dist/node/chunks/dep-7e125991.js.map +0 -1
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Plugin } from '../plugin';
|
|
2
|
+
import type { ViteDevServer, SSROptions } from '..';
|
|
3
|
+
import type { PartialResolvedId } from 'rollup';
|
|
4
|
+
import type { PackageCache, PackageData } from '../packages';
|
|
5
|
+
export declare const browserExternalId = "__vite-browser-external";
|
|
6
|
+
export interface ResolveOptions {
|
|
7
|
+
mainFields?: string[];
|
|
8
|
+
conditions?: string[];
|
|
9
|
+
extensions?: string[];
|
|
10
|
+
dedupe?: string[];
|
|
11
|
+
preserveSymlinks?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface InternalResolveOptions extends ResolveOptions {
|
|
14
|
+
root: string;
|
|
15
|
+
isBuild: boolean;
|
|
16
|
+
isProduction: boolean;
|
|
17
|
+
ssrConfig?: SSROptions;
|
|
18
|
+
packageCache?: PackageCache;
|
|
19
|
+
/**
|
|
20
|
+
* src code mode also attempts the following:
|
|
21
|
+
* - resolving /xxx as URLs
|
|
22
|
+
* - resolving bare imports from optimized deps
|
|
23
|
+
*/
|
|
24
|
+
asSrc?: boolean;
|
|
25
|
+
tryIndex?: boolean;
|
|
26
|
+
tryPrefix?: string;
|
|
27
|
+
skipPackageJson?: boolean;
|
|
28
|
+
preferRelative?: boolean;
|
|
29
|
+
preserveSymlinks?: boolean;
|
|
30
|
+
isRequire?: boolean;
|
|
31
|
+
isFromTsImporter?: boolean;
|
|
32
|
+
tryEsmOnly?: boolean;
|
|
33
|
+
}
|
|
34
|
+
export declare function resolvePlugin(baseOptions: InternalResolveOptions): Plugin;
|
|
35
|
+
export declare const idToPkgMap: Map<string, PackageData>;
|
|
36
|
+
export declare function tryNodeResolve(id: string, importer: string | null | undefined, options: InternalResolveOptions, targetWeb: boolean, server?: ViteDevServer, ssr?: boolean): PartialResolvedId | undefined;
|
|
37
|
+
export declare function tryOptimizedResolve(id: string, server: ViteDevServer, importer?: string): string | undefined;
|
|
38
|
+
export declare function resolvePackageEntry(id: string, { dir, data, setResolvedCache, getResolvedCache }: PackageData, targetWeb: boolean, options: InternalResolveOptions): string | undefined;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { ResolvedConfig } from '..';
|
|
3
|
+
import type { Plugin } from '../plugin';
|
|
4
|
+
/**
|
|
5
|
+
* This plugin hooks into Node's module resolution algorithm at runtime,
|
|
6
|
+
* so that SSR builds can benefit from `resolve.dedupe` like they do
|
|
7
|
+
* in development.
|
|
8
|
+
*/
|
|
9
|
+
export declare function ssrRequireHookPlugin(config: ResolvedConfig): Plugin | null;
|
|
10
|
+
declare type NodeResolveFilename = (request: string, parent: NodeModule, isMain: boolean, options?: Record<string, any>) => string;
|
|
11
|
+
export declare function hookNodeResolve(getResolver: (resolveFilename: NodeResolveFilename) => NodeResolveFilename): () => void;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { Server } from 'http';
|
|
3
|
+
import type { InlineConfig, ResolvedConfig } from '.';
|
|
4
|
+
import type { ResolvedServerOptions } from './server';
|
|
5
|
+
import type { CommonServerOptions } from './http';
|
|
6
|
+
export interface PreviewOptions extends CommonServerOptions {
|
|
7
|
+
}
|
|
8
|
+
export interface ResolvedPreviewOptions extends PreviewOptions {
|
|
9
|
+
}
|
|
10
|
+
export declare function resolvePreviewOptions(preview: PreviewOptions | undefined, server: ResolvedServerOptions): ResolvedPreviewOptions;
|
|
11
|
+
export interface PreviewServer {
|
|
12
|
+
/**
|
|
13
|
+
* The resolved vite config object
|
|
14
|
+
*/
|
|
15
|
+
config: ResolvedConfig;
|
|
16
|
+
/**
|
|
17
|
+
* native Node http server instance
|
|
18
|
+
*/
|
|
19
|
+
httpServer: Server;
|
|
20
|
+
/**
|
|
21
|
+
* Print server urls
|
|
22
|
+
*/
|
|
23
|
+
printUrls: () => void;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Starts the Vite server in preview mode, to simulate a production deployment
|
|
27
|
+
* @param config - the resolved Vite config
|
|
28
|
+
* @param serverOptions - what host and port to use
|
|
29
|
+
* @experimental
|
|
30
|
+
*/
|
|
31
|
+
export declare function preview(inlineConfig: InlineConfig): Promise<PreviewServer>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { ViteDevServer } from '..';
|
|
3
|
+
import type { ModuleNode } from './moduleGraph';
|
|
4
|
+
import type { Server } from 'http';
|
|
5
|
+
export declare const debugHmr: (...args: any[]) => any;
|
|
6
|
+
export interface HmrOptions {
|
|
7
|
+
protocol?: string;
|
|
8
|
+
host?: string;
|
|
9
|
+
port?: number;
|
|
10
|
+
clientPort?: number;
|
|
11
|
+
path?: string;
|
|
12
|
+
timeout?: number;
|
|
13
|
+
overlay?: boolean;
|
|
14
|
+
server?: Server;
|
|
15
|
+
}
|
|
16
|
+
export interface HmrContext {
|
|
17
|
+
file: string;
|
|
18
|
+
timestamp: number;
|
|
19
|
+
modules: Array<ModuleNode>;
|
|
20
|
+
read: () => string | Promise<string>;
|
|
21
|
+
server: ViteDevServer;
|
|
22
|
+
}
|
|
23
|
+
export declare function handleHMRUpdate(file: string, server: ViteDevServer): Promise<any>;
|
|
24
|
+
export declare function handleFileAddUnlink(file: string, server: ViteDevServer, isUnlink?: boolean): Promise<void>;
|
|
25
|
+
export declare function handlePrunedModules(mods: Set<ModuleNode>, { ws }: ViteDevServer): void;
|
|
26
|
+
/**
|
|
27
|
+
* Lex import.meta.hot.accept() for accepted deps.
|
|
28
|
+
* Since hot.accept() can only accept string literals or array of string
|
|
29
|
+
* literals, we don't really need a heavy @babel/parse call on the entire source.
|
|
30
|
+
*
|
|
31
|
+
* @returns selfAccepts
|
|
32
|
+
*/
|
|
33
|
+
export declare function lexAcceptedHmrDeps(code: string, start: number, urls: Set<{
|
|
34
|
+
url: string;
|
|
35
|
+
start: number;
|
|
36
|
+
end: number;
|
|
37
|
+
}>): boolean;
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type * as http from 'http';
|
|
3
|
+
import type { CommonServerOptions } from '../http';
|
|
4
|
+
import type { InlineConfig, ResolvedConfig } from '../config';
|
|
5
|
+
import type { PluginContainer } from './pluginContainer';
|
|
6
|
+
import type { FSWatcher, WatchOptions } from 'types/chokidar';
|
|
7
|
+
import type { WebSocketServer } from './ws';
|
|
8
|
+
import type { ModuleNode } from './moduleGraph';
|
|
9
|
+
import { ModuleGraph } from './moduleGraph';
|
|
10
|
+
import type { Connect } from 'types/connect';
|
|
11
|
+
import type { HmrOptions } from './hmr';
|
|
12
|
+
import type { TransformOptions, TransformResult } from './transformRequest';
|
|
13
|
+
import type { ESBuildTransformResult } from '../plugins/esbuild';
|
|
14
|
+
import type { TransformOptions as EsbuildTransformOptions } from 'esbuild';
|
|
15
|
+
import type { DepOptimizationMetadata } from '../optimizer';
|
|
16
|
+
import type { SourceMap } from 'rollup';
|
|
17
|
+
export { searchForWorkspaceRoot } from './searchRoot';
|
|
18
|
+
export interface ServerOptions extends CommonServerOptions {
|
|
19
|
+
/**
|
|
20
|
+
* Force dep pre-optimization regardless of whether deps have changed.
|
|
21
|
+
*/
|
|
22
|
+
force?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Configure HMR-specific options (port, host, path & protocol)
|
|
25
|
+
*/
|
|
26
|
+
hmr?: HmrOptions | boolean;
|
|
27
|
+
/**
|
|
28
|
+
* chokidar watch options
|
|
29
|
+
* https://github.com/paulmillr/chokidar#api
|
|
30
|
+
*/
|
|
31
|
+
watch?: WatchOptions;
|
|
32
|
+
/**
|
|
33
|
+
* Create Vite dev server to be used as a middleware in an existing server
|
|
34
|
+
*/
|
|
35
|
+
middlewareMode?: boolean | 'html' | 'ssr';
|
|
36
|
+
/**
|
|
37
|
+
* Prepend this folder to http requests, for use when proxying vite as a subfolder
|
|
38
|
+
* Should start and end with the `/` character
|
|
39
|
+
*/
|
|
40
|
+
base?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Options for files served via '/\@fs/'.
|
|
43
|
+
*/
|
|
44
|
+
fs?: FileSystemServeOptions;
|
|
45
|
+
/**
|
|
46
|
+
* Origin for the generated asset URLs.
|
|
47
|
+
*/
|
|
48
|
+
origin?: string;
|
|
49
|
+
}
|
|
50
|
+
export interface ResolvedServerOptions extends ServerOptions {
|
|
51
|
+
fs: Required<FileSystemServeOptions>;
|
|
52
|
+
}
|
|
53
|
+
export interface FileSystemServeOptions {
|
|
54
|
+
/**
|
|
55
|
+
* Strictly restrict file accessing outside of allowing paths.
|
|
56
|
+
*
|
|
57
|
+
* Set to `false` to disable the warning
|
|
58
|
+
*
|
|
59
|
+
* @default true
|
|
60
|
+
*/
|
|
61
|
+
strict?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Restrict accessing files outside the allowed directories.
|
|
64
|
+
*
|
|
65
|
+
* Accepts absolute path or a path relative to project root.
|
|
66
|
+
* Will try to search up for workspace root by default.
|
|
67
|
+
*/
|
|
68
|
+
allow?: string[];
|
|
69
|
+
/**
|
|
70
|
+
* Restrict accessing files that matches the patterns.
|
|
71
|
+
*
|
|
72
|
+
* This will have higher priority than `allow`.
|
|
73
|
+
* Glob patterns are supported.
|
|
74
|
+
*
|
|
75
|
+
* @default ['.env', '.env.*', '*.crt', '*.pem']
|
|
76
|
+
*
|
|
77
|
+
* @experimental
|
|
78
|
+
*/
|
|
79
|
+
deny?: string[];
|
|
80
|
+
}
|
|
81
|
+
export declare type ServerHook = (server: ViteDevServer) => (() => void) | void | Promise<(() => void) | void>;
|
|
82
|
+
export interface ViteDevServer {
|
|
83
|
+
/**
|
|
84
|
+
* The resolved vite config object
|
|
85
|
+
*/
|
|
86
|
+
config: ResolvedConfig;
|
|
87
|
+
/**
|
|
88
|
+
* A connect app instance.
|
|
89
|
+
* - Can be used to attach custom middlewares to the dev server.
|
|
90
|
+
* - Can also be used as the handler function of a custom http server
|
|
91
|
+
* or as a middleware in any connect-style Node.js frameworks
|
|
92
|
+
*
|
|
93
|
+
* https://github.com/senchalabs/connect#use-middleware
|
|
94
|
+
*/
|
|
95
|
+
middlewares: Connect.Server;
|
|
96
|
+
/**
|
|
97
|
+
* @deprecated use `server.middlewares` instead
|
|
98
|
+
*/
|
|
99
|
+
app: Connect.Server;
|
|
100
|
+
/**
|
|
101
|
+
* native Node http server instance
|
|
102
|
+
* will be null in middleware mode
|
|
103
|
+
*/
|
|
104
|
+
httpServer: http.Server | null;
|
|
105
|
+
/**
|
|
106
|
+
* chokidar watcher instance
|
|
107
|
+
* https://github.com/paulmillr/chokidar#api
|
|
108
|
+
*/
|
|
109
|
+
watcher: FSWatcher;
|
|
110
|
+
/**
|
|
111
|
+
* web socket server with `send(payload)` method
|
|
112
|
+
*/
|
|
113
|
+
ws: WebSocketServer;
|
|
114
|
+
/**
|
|
115
|
+
* Rollup plugin container that can run plugin hooks on a given file
|
|
116
|
+
*/
|
|
117
|
+
pluginContainer: PluginContainer;
|
|
118
|
+
/**
|
|
119
|
+
* Module graph that tracks the import relationships, url to file mapping
|
|
120
|
+
* and hmr state.
|
|
121
|
+
*/
|
|
122
|
+
moduleGraph: ModuleGraph;
|
|
123
|
+
/**
|
|
124
|
+
* Programmatically resolve, load and transform a URL and get the result
|
|
125
|
+
* without going through the http request pipeline.
|
|
126
|
+
*/
|
|
127
|
+
transformRequest(url: string, options?: TransformOptions): Promise<TransformResult | null>;
|
|
128
|
+
/**
|
|
129
|
+
* Apply vite built-in HTML transforms and any plugin HTML transforms.
|
|
130
|
+
*/
|
|
131
|
+
transformIndexHtml(url: string, html: string, originalUrl?: string): Promise<string>;
|
|
132
|
+
/**
|
|
133
|
+
* Util for transforming a file with esbuild.
|
|
134
|
+
* Can be useful for certain plugins.
|
|
135
|
+
*
|
|
136
|
+
* @deprecated import `transformWithEsbuild` from `vite` instead
|
|
137
|
+
*/
|
|
138
|
+
transformWithEsbuild(code: string, filename: string, options?: EsbuildTransformOptions, inMap?: object): Promise<ESBuildTransformResult>;
|
|
139
|
+
/**
|
|
140
|
+
* Transform module code into SSR format.
|
|
141
|
+
* @experimental
|
|
142
|
+
*/
|
|
143
|
+
ssrTransform(code: string, inMap: SourceMap | null, url: string): Promise<TransformResult | null>;
|
|
144
|
+
/**
|
|
145
|
+
* Load a given URL as an instantiated module for SSR.
|
|
146
|
+
*/
|
|
147
|
+
ssrLoadModule(url: string): Promise<Record<string, any>>;
|
|
148
|
+
/**
|
|
149
|
+
* Fix ssr error stacktrace
|
|
150
|
+
*/
|
|
151
|
+
ssrFixStacktrace(e: Error): void;
|
|
152
|
+
/**
|
|
153
|
+
* Start the server.
|
|
154
|
+
*/
|
|
155
|
+
listen(port?: number, isRestart?: boolean): Promise<ViteDevServer>;
|
|
156
|
+
/**
|
|
157
|
+
* Stop the server.
|
|
158
|
+
*/
|
|
159
|
+
close(): Promise<void>;
|
|
160
|
+
/**
|
|
161
|
+
* Print server urls
|
|
162
|
+
*/
|
|
163
|
+
printUrls(): void;
|
|
164
|
+
/**
|
|
165
|
+
* Restart the server.
|
|
166
|
+
*
|
|
167
|
+
* @param forceOptimize - force the optimizer to re-bundle, same as --force cli flag
|
|
168
|
+
*/
|
|
169
|
+
restart(forceOptimize?: boolean): Promise<void>;
|
|
170
|
+
/**
|
|
171
|
+
* @internal
|
|
172
|
+
*/
|
|
173
|
+
_optimizeDepsMetadata: DepOptimizationMetadata | null;
|
|
174
|
+
/**
|
|
175
|
+
* Deps that are externalized
|
|
176
|
+
* @internal
|
|
177
|
+
*/
|
|
178
|
+
_ssrExternals: string[] | null;
|
|
179
|
+
/**
|
|
180
|
+
* @internal
|
|
181
|
+
*/
|
|
182
|
+
_globImporters: Record<string, {
|
|
183
|
+
module: ModuleNode;
|
|
184
|
+
importGlobs: {
|
|
185
|
+
base: string;
|
|
186
|
+
pattern: string;
|
|
187
|
+
}[];
|
|
188
|
+
}>;
|
|
189
|
+
/**
|
|
190
|
+
* @internal
|
|
191
|
+
*/
|
|
192
|
+
_restartPromise: Promise<void> | null;
|
|
193
|
+
/**
|
|
194
|
+
* @internal
|
|
195
|
+
*/
|
|
196
|
+
_forceOptimizeOnRestart: boolean;
|
|
197
|
+
/**
|
|
198
|
+
* @internal
|
|
199
|
+
*/
|
|
200
|
+
_isRunningOptimizer: boolean;
|
|
201
|
+
/**
|
|
202
|
+
* @internal
|
|
203
|
+
*/
|
|
204
|
+
_registerMissingImport: ((id: string, resolved: string, ssr: boolean | undefined) => void) | null;
|
|
205
|
+
/**
|
|
206
|
+
* @internal
|
|
207
|
+
*/
|
|
208
|
+
_pendingReload: Promise<void> | null;
|
|
209
|
+
/**
|
|
210
|
+
* @internal
|
|
211
|
+
*/
|
|
212
|
+
_pendingRequests: Map<string, Promise<TransformResult | null>>;
|
|
213
|
+
}
|
|
214
|
+
export declare function createServer(inlineConfig?: InlineConfig): Promise<ViteDevServer>;
|
|
215
|
+
export declare function resolveServerOptions(root: string, raw?: ServerOptions): ResolvedServerOptions;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { RollupError } from 'rollup';
|
|
2
|
+
import type { ViteDevServer } from '../..';
|
|
3
|
+
import type { Connect } from 'types/connect';
|
|
4
|
+
import type { ErrorPayload } from 'types/hmrPayload';
|
|
5
|
+
export declare function prepareError(err: Error | RollupError): ErrorPayload['err'];
|
|
6
|
+
export declare function buildErrorMessage(err: RollupError, args?: string[], includeStack?: boolean): string;
|
|
7
|
+
export declare function logError(server: ViteDevServer, err: RollupError): void;
|
|
8
|
+
export declare function errorMiddleware(server: ViteDevServer, allowNext?: boolean): Connect.ErrorHandleFunction;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Connect } from 'types/connect';
|
|
2
|
+
import type { ViteDevServer } from '../..';
|
|
3
|
+
export declare function createDevHtmlTransformFn(server: ViteDevServer): (url: string, html: string, originalUrl: string) => Promise<string>;
|
|
4
|
+
export declare function indexHtmlMiddleware(server: ViteDevServer): Connect.NextHandleFunction;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type * as http from 'http';
|
|
3
|
+
import type { Connect } from 'types/connect';
|
|
4
|
+
import type { HttpProxy } from 'types/http-proxy';
|
|
5
|
+
import type { ResolvedConfig } from '../..';
|
|
6
|
+
export interface ProxyOptions extends HttpProxy.ServerOptions {
|
|
7
|
+
/**
|
|
8
|
+
* rewrite path
|
|
9
|
+
*/
|
|
10
|
+
rewrite?: (path: string) => string;
|
|
11
|
+
/**
|
|
12
|
+
* configure the proxy server (e.g. listen to events)
|
|
13
|
+
*/
|
|
14
|
+
configure?: (proxy: HttpProxy.Server, options: ProxyOptions) => void;
|
|
15
|
+
/**
|
|
16
|
+
* webpack-dev-server style bypass function
|
|
17
|
+
*/
|
|
18
|
+
bypass?: (req: http.IncomingMessage, res: http.ServerResponse, options: ProxyOptions) => void | null | undefined | false | string;
|
|
19
|
+
}
|
|
20
|
+
export declare function proxyMiddleware(httpServer: http.Server | null, config: ResolvedConfig): Connect.NextHandleFunction;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Connect } from 'types/connect';
|
|
2
|
+
import type { ViteDevServer } from '../..';
|
|
3
|
+
export declare function servePublicMiddleware(dir: string): Connect.NextHandleFunction;
|
|
4
|
+
export declare function serveStaticMiddleware(dir: string, server: ViteDevServer): Connect.NextHandleFunction;
|
|
5
|
+
export declare function serveRawFsMiddleware(server: ViteDevServer): Connect.NextHandleFunction;
|
|
6
|
+
export declare function isFileServingAllowed(url: string, server: ViteDevServer): boolean;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { ModuleInfo, PartialResolvedId } from 'rollup';
|
|
2
|
+
import type { TransformResult } from './transformRequest';
|
|
3
|
+
export declare class ModuleNode {
|
|
4
|
+
/**
|
|
5
|
+
* Public served url path, starts with /
|
|
6
|
+
*/
|
|
7
|
+
url: string;
|
|
8
|
+
/**
|
|
9
|
+
* Resolved file system path + query
|
|
10
|
+
*/
|
|
11
|
+
id: string | null;
|
|
12
|
+
file: string | null;
|
|
13
|
+
type: 'js' | 'css';
|
|
14
|
+
info?: ModuleInfo;
|
|
15
|
+
meta?: Record<string, any>;
|
|
16
|
+
importers: Set<ModuleNode>;
|
|
17
|
+
importedModules: Set<ModuleNode>;
|
|
18
|
+
acceptedHmrDeps: Set<ModuleNode>;
|
|
19
|
+
isSelfAccepting: boolean;
|
|
20
|
+
transformResult: TransformResult | null;
|
|
21
|
+
ssrTransformResult: TransformResult | null;
|
|
22
|
+
ssrModule: Record<string, any> | null;
|
|
23
|
+
lastHMRTimestamp: number;
|
|
24
|
+
constructor(url: string);
|
|
25
|
+
}
|
|
26
|
+
export declare type ResolvedUrl = [
|
|
27
|
+
url: string,
|
|
28
|
+
resolvedId: string,
|
|
29
|
+
meta: object | null | undefined
|
|
30
|
+
];
|
|
31
|
+
export declare class ModuleGraph {
|
|
32
|
+
private resolveId;
|
|
33
|
+
urlToModuleMap: Map<string, ModuleNode>;
|
|
34
|
+
idToModuleMap: Map<string, ModuleNode>;
|
|
35
|
+
fileToModulesMap: Map<string, Set<ModuleNode>>;
|
|
36
|
+
safeModulesPath: Set<string>;
|
|
37
|
+
constructor(resolveId: (url: string) => Promise<PartialResolvedId | null>);
|
|
38
|
+
getModuleByUrl(rawUrl: string): Promise<ModuleNode | undefined>;
|
|
39
|
+
getModuleById(id: string): ModuleNode | undefined;
|
|
40
|
+
getModulesByFile(file: string): Set<ModuleNode> | undefined;
|
|
41
|
+
onFileChange(file: string): void;
|
|
42
|
+
invalidateModule(mod: ModuleNode, seen?: Set<ModuleNode>): void;
|
|
43
|
+
invalidateAll(): void;
|
|
44
|
+
/**
|
|
45
|
+
* Update the module graph based on a module's updated imports information
|
|
46
|
+
* If there are dependencies that no longer have any importers, they are
|
|
47
|
+
* returned as a Set.
|
|
48
|
+
*/
|
|
49
|
+
updateModuleInfo(mod: ModuleNode, importedModules: Set<string | ModuleNode>, acceptedModules: Set<string | ModuleNode>, isSelfAccepting: boolean): Promise<Set<ModuleNode> | undefined>;
|
|
50
|
+
ensureEntryFromUrl(rawUrl: string): Promise<ModuleNode>;
|
|
51
|
+
createFileOnlyEntry(file: string): ModuleNode;
|
|
52
|
+
resolveUrl(url: string): Promise<ResolvedUrl>;
|
|
53
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The following is modified based on source found in
|
|
3
|
+
* https://github.com/facebook/create-react-app
|
|
4
|
+
*
|
|
5
|
+
* MIT Licensed
|
|
6
|
+
* Copyright (c) 2015-present, Facebook, Inc.
|
|
7
|
+
* https://github.com/facebook/create-react-app/blob/master/LICENSE
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
import type { Logger } from '../logger';
|
|
11
|
+
/**
|
|
12
|
+
* Reads the BROWSER environment variable and decides what to do with it.
|
|
13
|
+
* Returns true if it opened a browser or ran a node.js script, otherwise false.
|
|
14
|
+
*/
|
|
15
|
+
export declare function openBrowser(url: string, opt: string | true, logger: Logger): boolean;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is refactored into TypeScript based on
|
|
3
|
+
* https://github.com/preactjs/wmr/blob/main/packages/wmr/src/lib/rollup-plugin-container.js
|
|
4
|
+
*/
|
|
5
|
+
import type { Plugin } from '../plugin';
|
|
6
|
+
import type { InputOptions, OutputOptions, ModuleInfo, PartialResolvedId, LoadResult, SourceDescription } from 'rollup';
|
|
7
|
+
import * as acorn from 'acorn';
|
|
8
|
+
import type { FSWatcher } from 'chokidar';
|
|
9
|
+
import type { ResolvedConfig } from '../config';
|
|
10
|
+
import type { ModuleGraph } from './moduleGraph';
|
|
11
|
+
export interface PluginContainerOptions {
|
|
12
|
+
cwd?: string;
|
|
13
|
+
output?: OutputOptions;
|
|
14
|
+
modules?: Map<string, {
|
|
15
|
+
info: ModuleInfo;
|
|
16
|
+
}>;
|
|
17
|
+
writeFile?: (name: string, source: string | Uint8Array) => void;
|
|
18
|
+
}
|
|
19
|
+
export interface PluginContainer {
|
|
20
|
+
options: InputOptions;
|
|
21
|
+
getModuleInfo(id: string): ModuleInfo | null;
|
|
22
|
+
buildStart(options: InputOptions): Promise<void>;
|
|
23
|
+
resolveId(id: string, importer?: string, options?: {
|
|
24
|
+
skip?: Set<Plugin>;
|
|
25
|
+
ssr?: boolean;
|
|
26
|
+
}): Promise<PartialResolvedId | null>;
|
|
27
|
+
transform(code: string, id: string, options?: {
|
|
28
|
+
inMap?: SourceDescription['map'];
|
|
29
|
+
ssr?: boolean;
|
|
30
|
+
}): Promise<SourceDescription | null>;
|
|
31
|
+
load(id: string, options?: {
|
|
32
|
+
ssr?: boolean;
|
|
33
|
+
}): Promise<LoadResult | null>;
|
|
34
|
+
close(): Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
export declare let parser: typeof acorn.Parser;
|
|
37
|
+
export declare function createPluginContainer({ plugins, logger, root, build: { rollupOptions } }: ResolvedConfig, moduleGraph?: ModuleGraph, watcher?: FSWatcher): Promise<PluginContainer>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Search up for the nearest `package.json`
|
|
3
|
+
*/
|
|
4
|
+
export declare function searchForPackageRoot(current: string, root?: string): string;
|
|
5
|
+
/**
|
|
6
|
+
* Search up for the nearest workspace root
|
|
7
|
+
*/
|
|
8
|
+
export declare function searchForWorkspaceRoot(current: string, root?: string): string;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { IncomingMessage, ServerResponse } from 'http';
|
|
3
|
+
import type { SourceMap } from 'rollup';
|
|
4
|
+
export declare function send(req: IncomingMessage, res: ServerResponse, content: string | Buffer, type: string, etag?: string, cacheControl?: string, map?: SourceMap | null): void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Logger } from '../logger';
|
|
2
|
+
interface SourceMapLike {
|
|
3
|
+
sources: string[];
|
|
4
|
+
sourcesContent?: (string | null)[];
|
|
5
|
+
sourceRoot?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function injectSourcesContent(map: SourceMapLike, file: string, logger: Logger): Promise<void>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { SourceMap } from 'rollup';
|
|
2
|
+
import type { ViteDevServer } from '..';
|
|
3
|
+
export interface TransformResult {
|
|
4
|
+
code: string;
|
|
5
|
+
map: SourceMap | null;
|
|
6
|
+
etag?: string;
|
|
7
|
+
deps?: string[];
|
|
8
|
+
dynamicDeps?: string[];
|
|
9
|
+
}
|
|
10
|
+
export interface TransformOptions {
|
|
11
|
+
ssr?: boolean;
|
|
12
|
+
html?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare function transformRequest(url: string, server: ViteDevServer, options?: TransformOptions): Promise<TransformResult | null>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { Server } from 'http';
|
|
3
|
+
import type { ServerOptions as HttpsServerOptions } from 'https';
|
|
4
|
+
import type { WebSocket as WebSocketTypes } from 'types/ws';
|
|
5
|
+
import type { HMRPayload } from 'types/hmrPayload';
|
|
6
|
+
import type { ResolvedConfig } from '..';
|
|
7
|
+
export declare const HMR_HEADER = "vite-hmr";
|
|
8
|
+
export interface WebSocketServer {
|
|
9
|
+
on: WebSocketTypes.Server['on'];
|
|
10
|
+
off: WebSocketTypes.Server['off'];
|
|
11
|
+
send(payload: HMRPayload): void;
|
|
12
|
+
close(): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
export declare function createWebSocketServer(server: Server | null, config: ResolvedConfig, httpsOptions?: HttpsServerOptions): WebSocketServer;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ResolvedConfig } from '..';
|
|
2
|
+
/**
|
|
3
|
+
* Heuristics for determining whether a dependency should be externalized for
|
|
4
|
+
* server-side rendering.
|
|
5
|
+
*/
|
|
6
|
+
export declare function resolveSSRExternal(config: ResolvedConfig, knownImports: string[]): string[];
|
|
7
|
+
export declare function shouldExternalizeForSSR(id: string, externals: string[]): boolean;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ViteDevServer } from '../server';
|
|
2
|
+
interface SSRContext {
|
|
3
|
+
global: typeof globalThis;
|
|
4
|
+
}
|
|
5
|
+
declare type SSRModule = Record<string, any>;
|
|
6
|
+
export declare function ssrLoadModule(url: string, server: ViteDevServer, context?: SSRContext, urlStack?: string[]): Promise<SSRModule>;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { SourceMap } from 'rollup';
|
|
2
|
+
import type { TransformResult } from '../server/transformRequest';
|
|
3
|
+
export declare const ssrModuleExportsKey = "__vite_ssr_exports__";
|
|
4
|
+
export declare const ssrImportKey = "__vite_ssr_import__";
|
|
5
|
+
export declare const ssrDynamicImportKey = "__vite_ssr_dynamic_import__";
|
|
6
|
+
export declare const ssrExportAllKey = "__vite_ssr_exportAll__";
|
|
7
|
+
export declare const ssrImportMetaKey = "__vite_ssr_import_meta__";
|
|
8
|
+
export declare function ssrTransform(code: string, inMap: SourceMap | null, url: string): Promise<TransformResult | null>;
|