vite 5.3.0-beta.1 → 5.3.0
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 +111 -144
- package/client.d.ts +4 -0
- package/dist/client/client.mjs +608 -606
- package/dist/client/env.mjs +18 -24
- package/dist/node/chunks/{dep-Cg_8Tny5.js → dep-C-hCBY92.js} +1 -1
- package/dist/node/chunks/{dep-ByQDP9Ky.js → dep-DfBmsS12.js} +1 -1
- package/dist/node/chunks/{dep-Dz0We6of.js → dep-h78lQ5BT.js} +23857 -20836
- package/dist/node/cli.js +235 -244
- package/dist/node/constants.js +80 -83
- package/dist/node/index.d.ts +1 -0
- package/dist/node/index.js +186 -198
- package/dist/node/runtime.js +139 -99
- package/dist/node-cjs/publicUtils.cjs +512 -573
- package/package.json +8 -9
- package/dist/client/client.mjs.map +0 -1
- package/dist/client/env.mjs.map +0 -1
package/dist/node/constants.js
CHANGED
@@ -2,114 +2,111 @@ import path, { resolve } from 'node:path';
|
|
2
2
|
import { fileURLToPath } from 'node:url';
|
3
3
|
import { readFileSync } from 'node:fs';
|
4
4
|
|
5
|
-
const { version } = JSON.parse(
|
5
|
+
const { version } = JSON.parse(
|
6
|
+
readFileSync(new URL("../../package.json", import.meta.url)).toString()
|
7
|
+
);
|
6
8
|
const VERSION = version;
|
7
9
|
const DEFAULT_MAIN_FIELDS = [
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
"browser",
|
11
|
+
"module",
|
12
|
+
"jsnext:main",
|
13
|
+
// moment still uses this...
|
14
|
+
"jsnext"
|
12
15
|
];
|
13
|
-
// Baseline support browserslist
|
14
|
-
// "defaults and supports es6-module and supports es6-module-dynamic-import"
|
15
|
-
// Higher browser versions may be needed for extra features.
|
16
16
|
const ESBUILD_MODULES_TARGET = [
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
"es2020",
|
18
|
+
// support import.meta.url
|
19
|
+
"edge88",
|
20
|
+
"firefox78",
|
21
|
+
"chrome87",
|
22
|
+
"safari14"
|
22
23
|
];
|
23
24
|
const DEFAULT_EXTENSIONS = [
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
25
|
+
".mjs",
|
26
|
+
".js",
|
27
|
+
".mts",
|
28
|
+
".ts",
|
29
|
+
".jsx",
|
30
|
+
".tsx",
|
31
|
+
".json"
|
31
32
|
];
|
32
33
|
const DEFAULT_CONFIG_FILES = [
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
34
|
+
"vite.config.js",
|
35
|
+
"vite.config.mjs",
|
36
|
+
"vite.config.ts",
|
37
|
+
"vite.config.cjs",
|
38
|
+
"vite.config.mts",
|
39
|
+
"vite.config.cts"
|
39
40
|
];
|
40
41
|
const JS_TYPES_RE = /\.(?:j|t)sx?$|\.mjs$/;
|
41
42
|
const CSS_LANGS_RE = /\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/;
|
42
43
|
const OPTIMIZABLE_ENTRY_RE = /\.[cm]?[jt]s$/;
|
43
44
|
const SPECIAL_QUERY_RE = /[?&](?:worker|sharedworker|raw|url)\b/;
|
44
|
-
/**
|
45
|
-
* Prefix for resolved fs paths, since windows paths may not be valid as URLs.
|
46
|
-
*/
|
47
45
|
const FS_PREFIX = `/@fs/`;
|
48
46
|
const CLIENT_PUBLIC_PATH = `/@vite/client`;
|
49
47
|
const ENV_PUBLIC_PATH = `/@vite/env`;
|
50
48
|
const VITE_PACKAGE_DIR = resolve(
|
51
|
-
// import.meta.url is `dist/node/constants.js` after bundle
|
52
|
-
fileURLToPath(import.meta.url),
|
53
|
-
|
54
|
-
|
49
|
+
// import.meta.url is `dist/node/constants.js` after bundle
|
50
|
+
fileURLToPath(import.meta.url),
|
51
|
+
"../../.."
|
52
|
+
);
|
53
|
+
const CLIENT_ENTRY = resolve(VITE_PACKAGE_DIR, "dist/client/client.mjs");
|
54
|
+
const ENV_ENTRY = resolve(VITE_PACKAGE_DIR, "dist/client/env.mjs");
|
55
55
|
const CLIENT_DIR = path.dirname(CLIENT_ENTRY);
|
56
|
-
// ** READ THIS ** before editing `KNOWN_ASSET_TYPES`.
|
57
|
-
// If you add an asset to `KNOWN_ASSET_TYPES`, make sure to also add it
|
58
|
-
// to the TypeScript declaration file `packages/vite/client.d.ts` and
|
59
|
-
// add a mime type to the `registerCustomMime` in
|
60
|
-
// `packages/vite/src/node/plugin/assets.ts` if mime type cannot be
|
61
|
-
// looked up by mrmime.
|
62
56
|
const KNOWN_ASSET_TYPES = [
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
57
|
+
// images
|
58
|
+
"apng",
|
59
|
+
"bmp",
|
60
|
+
"png",
|
61
|
+
"jpe?g",
|
62
|
+
"jfif",
|
63
|
+
"pjpeg",
|
64
|
+
"pjp",
|
65
|
+
"gif",
|
66
|
+
"svg",
|
67
|
+
"ico",
|
68
|
+
"webp",
|
69
|
+
"avif",
|
70
|
+
// media
|
71
|
+
"mp4",
|
72
|
+
"webm",
|
73
|
+
"ogg",
|
74
|
+
"mp3",
|
75
|
+
"wav",
|
76
|
+
"flac",
|
77
|
+
"aac",
|
78
|
+
"opus",
|
79
|
+
"mov",
|
80
|
+
"m4a",
|
81
|
+
"vtt",
|
82
|
+
// fonts
|
83
|
+
"woff2?",
|
84
|
+
"eot",
|
85
|
+
"ttf",
|
86
|
+
"otf",
|
87
|
+
// other
|
88
|
+
"webmanifest",
|
89
|
+
"pdf",
|
90
|
+
"txt"
|
96
91
|
];
|
97
|
-
const DEFAULT_ASSETS_RE = new RegExp(
|
92
|
+
const DEFAULT_ASSETS_RE = new RegExp(
|
93
|
+
`\\.(` + KNOWN_ASSET_TYPES.join("|") + `)(\\?.*)?$`
|
94
|
+
);
|
98
95
|
const DEP_VERSION_RE = /[?&](v=[\w.-]+)\b/;
|
99
|
-
const loopbackHosts = new Set([
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
96
|
+
const loopbackHosts = /* @__PURE__ */ new Set([
|
97
|
+
"localhost",
|
98
|
+
"127.0.0.1",
|
99
|
+
"::1",
|
100
|
+
"0000:0000:0000:0000:0000:0000:0000:0001"
|
104
101
|
]);
|
105
|
-
const wildcardHosts = new Set([
|
106
|
-
|
107
|
-
|
108
|
-
|
102
|
+
const wildcardHosts = /* @__PURE__ */ new Set([
|
103
|
+
"0.0.0.0",
|
104
|
+
"::",
|
105
|
+
"0000:0000:0000:0000:0000:0000:0000:0000"
|
109
106
|
]);
|
110
107
|
const DEFAULT_DEV_PORT = 5173;
|
111
108
|
const DEFAULT_PREVIEW_PORT = 4173;
|
112
109
|
const DEFAULT_ASSETS_INLINE_LIMIT = 4096;
|
113
|
-
const METADATA_FILENAME =
|
110
|
+
const METADATA_FILENAME = "_metadata.json";
|
114
111
|
|
115
112
|
export { CLIENT_DIR, CLIENT_ENTRY, CLIENT_PUBLIC_PATH, CSS_LANGS_RE, DEFAULT_ASSETS_INLINE_LIMIT, DEFAULT_ASSETS_RE, DEFAULT_CONFIG_FILES, DEFAULT_DEV_PORT, DEFAULT_EXTENSIONS, DEFAULT_MAIN_FIELDS, DEFAULT_PREVIEW_PORT, DEP_VERSION_RE, ENV_ENTRY, ENV_PUBLIC_PATH, ESBUILD_MODULES_TARGET, FS_PREFIX, JS_TYPES_RE, KNOWN_ASSET_TYPES, METADATA_FILENAME, OPTIMIZABLE_ENTRY_RE, SPECIAL_QUERY_RE, VERSION, VITE_PACKAGE_DIR, loopbackHosts, wildcardHosts };
|
package/dist/node/index.d.ts
CHANGED
package/dist/node/index.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
export { parseAst, parseAstAsync } from 'rollup/parseAst';
|
2
|
-
import { i as isInNodeModules, a as arraify } from './chunks/dep-
|
3
|
-
export { b as build, g as buildErrorMessage, k as createFilter, v as createLogger, c as createServer, d as defineConfig, h as fetchModule, f as formatPostcssSourceMap, x as isFileServingAllowed, l as loadConfigFromFile, y as loadEnv, j as mergeAlias, m as mergeConfig, n as normalizePath, o as optimizeDeps, e as preprocessCSS, p as preview, r as resolveConfig, z as resolveEnvPrefix, q as rollupVersion, w as searchForWorkspaceRoot, u as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-
|
2
|
+
import { i as isInNodeModules, a as arraify } from './chunks/dep-h78lQ5BT.js';
|
3
|
+
export { b as build, g as buildErrorMessage, k as createFilter, v as createLogger, c as createServer, d as defineConfig, h as fetchModule, f as formatPostcssSourceMap, x as isFileServingAllowed, l as loadConfigFromFile, y as loadEnv, j as mergeAlias, m as mergeConfig, n as normalizePath, o as optimizeDeps, e as preprocessCSS, p as preview, r as resolveConfig, z as resolveEnvPrefix, q as rollupVersion, w as searchForWorkspaceRoot, u as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-h78lQ5BT.js';
|
4
4
|
export { VERSION as version } from './constants.js';
|
5
5
|
export { version as esbuildVersion } from 'esbuild';
|
6
6
|
import { existsSync, readFileSync } from 'node:fs';
|
@@ -14,13 +14,15 @@ import 'node:module';
|
|
14
14
|
import 'tty';
|
15
15
|
import 'path';
|
16
16
|
import 'fs';
|
17
|
-
import 'events';
|
18
|
-
import '
|
17
|
+
import 'node:events';
|
18
|
+
import 'node:stream';
|
19
|
+
import 'node:string_decoder';
|
19
20
|
import 'node:child_process';
|
20
21
|
import 'node:http';
|
21
22
|
import 'node:https';
|
22
23
|
import 'util';
|
23
24
|
import 'net';
|
25
|
+
import 'events';
|
24
26
|
import 'url';
|
25
27
|
import 'http';
|
26
28
|
import 'stream';
|
@@ -35,238 +37,224 @@ import 'node:assert';
|
|
35
37
|
import 'node:v8';
|
36
38
|
import 'node:worker_threads';
|
37
39
|
import 'node:buffer';
|
38
|
-
import 'node:events';
|
39
40
|
import 'querystring';
|
40
41
|
import 'node:readline';
|
41
42
|
import 'zlib';
|
42
43
|
import 'buffer';
|
43
44
|
import 'https';
|
44
45
|
import 'tls';
|
46
|
+
import 'assert';
|
45
47
|
import 'node:zlib';
|
46
48
|
|
47
|
-
|
48
|
-
//
|
49
|
-
|
50
|
-
|
51
|
-
/\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/;
|
49
|
+
const CSS_LANGS_RE = (
|
50
|
+
// eslint-disable-next-line regexp/no-unused-capturing-group
|
51
|
+
/\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/
|
52
|
+
);
|
52
53
|
const isCSSRequest = (request) => CSS_LANGS_RE.test(request);
|
53
|
-
// Use splitVendorChunkPlugin() to get the same manualChunks strategy as Vite 2.7
|
54
|
-
// We don't recommend using this strategy as a general solution moving forward
|
55
|
-
// splitVendorChunk is a simple index/vendor strategy that was used in Vite
|
56
|
-
// until v2.8. It is exposed to let people continue to use it in case it was
|
57
|
-
// working well for their setups.
|
58
|
-
// The cache needs to be reset on buildStart for watch mode to work correctly
|
59
|
-
// Don't use this manualChunks strategy for ssr, lib mode, and 'umd' or 'iife'
|
60
|
-
/**
|
61
|
-
* @deprecated use build.rollupOptions.output.manualChunks or framework specific configuration
|
62
|
-
*/
|
63
54
|
class SplitVendorChunkCache {
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
55
|
+
cache;
|
56
|
+
constructor() {
|
57
|
+
this.cache = /* @__PURE__ */ new Map();
|
58
|
+
}
|
59
|
+
reset() {
|
60
|
+
this.cache = /* @__PURE__ */ new Map();
|
61
|
+
}
|
71
62
|
}
|
72
|
-
/**
|
73
|
-
* @deprecated use build.rollupOptions.output.manualChunks or framework specific configuration
|
74
|
-
*/
|
75
63
|
function splitVendorChunk(options = {}) {
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
}
|
83
|
-
};
|
64
|
+
const cache = options.cache ?? new SplitVendorChunkCache();
|
65
|
+
return (id, { getModuleInfo }) => {
|
66
|
+
if (isInNodeModules(id) && !isCSSRequest(id) && staticImportedByEntry(id, getModuleInfo, cache.cache)) {
|
67
|
+
return "vendor";
|
68
|
+
}
|
69
|
+
};
|
84
70
|
}
|
85
71
|
function staticImportedByEntry(id, getModuleInfo, cache, importStack = []) {
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
72
|
+
if (cache.has(id)) {
|
73
|
+
return cache.get(id);
|
74
|
+
}
|
75
|
+
if (importStack.includes(id)) {
|
76
|
+
cache.set(id, false);
|
77
|
+
return false;
|
78
|
+
}
|
79
|
+
const mod = getModuleInfo(id);
|
80
|
+
if (!mod) {
|
81
|
+
cache.set(id, false);
|
82
|
+
return false;
|
83
|
+
}
|
84
|
+
if (mod.isEntry) {
|
85
|
+
cache.set(id, true);
|
86
|
+
return true;
|
87
|
+
}
|
88
|
+
const someImporterIs = mod.importers.some(
|
89
|
+
(importer) => staticImportedByEntry(
|
90
|
+
importer,
|
91
|
+
getModuleInfo,
|
92
|
+
cache,
|
93
|
+
importStack.concat(id)
|
94
|
+
)
|
95
|
+
);
|
96
|
+
cache.set(id, someImporterIs);
|
97
|
+
return someImporterIs;
|
106
98
|
}
|
107
|
-
/**
|
108
|
-
* @deprecated use build.rollupOptions.output.manualChunks or framework specific configuration
|
109
|
-
*/
|
110
99
|
function splitVendorChunkPlugin() {
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
}
|
100
|
+
const caches = [];
|
101
|
+
function createSplitVendorChunk(output, config) {
|
102
|
+
const cache = new SplitVendorChunkCache();
|
103
|
+
caches.push(cache);
|
104
|
+
const build = config.build ?? {};
|
105
|
+
const format = output?.format;
|
106
|
+
if (!build.ssr && !build.lib && format !== "umd" && format !== "iife") {
|
107
|
+
return splitVendorChunk({ cache });
|
120
108
|
}
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
}
|
137
|
-
else {
|
138
|
-
// else, leave the object form of manualChunks untouched, as
|
139
|
-
// we can't safely replicate rollup handling.
|
140
|
-
// eslint-disable-next-line no-console
|
141
|
-
console.warn("(!) the `splitVendorChunk` plugin doesn't have any effect when using the object form of `build.rollupOptions.output.manualChunks`. Consider using the function form instead.");
|
142
|
-
}
|
143
|
-
}
|
144
|
-
else {
|
145
|
-
output.manualChunks = viteManualChunks;
|
146
|
-
}
|
147
|
-
}
|
148
|
-
}
|
149
|
-
}
|
150
|
-
else {
|
151
|
-
return {
|
152
|
-
build: {
|
153
|
-
rollupOptions: {
|
154
|
-
output: {
|
155
|
-
manualChunks: createSplitVendorChunk({}, config),
|
156
|
-
},
|
157
|
-
},
|
158
|
-
},
|
109
|
+
}
|
110
|
+
return {
|
111
|
+
name: "vite:split-vendor-chunk",
|
112
|
+
config(config) {
|
113
|
+
let outputs = config?.build?.rollupOptions?.output;
|
114
|
+
if (outputs) {
|
115
|
+
outputs = arraify(outputs);
|
116
|
+
for (const output of outputs) {
|
117
|
+
const viteManualChunks = createSplitVendorChunk(output, config);
|
118
|
+
if (viteManualChunks) {
|
119
|
+
if (output.manualChunks) {
|
120
|
+
if (typeof output.manualChunks === "function") {
|
121
|
+
const userManualChunks = output.manualChunks;
|
122
|
+
output.manualChunks = (id, api) => {
|
123
|
+
return userManualChunks(id, api) ?? viteManualChunks(id, api);
|
159
124
|
};
|
125
|
+
} else {
|
126
|
+
console.warn(
|
127
|
+
"(!) the `splitVendorChunk` plugin doesn't have any effect when using the object form of `build.rollupOptions.output.manualChunks`. Consider using the function form instead."
|
128
|
+
);
|
129
|
+
}
|
130
|
+
} else {
|
131
|
+
output.manualChunks = viteManualChunks;
|
132
|
+
}
|
133
|
+
}
|
134
|
+
}
|
135
|
+
} else {
|
136
|
+
return {
|
137
|
+
build: {
|
138
|
+
rollupOptions: {
|
139
|
+
output: {
|
140
|
+
manualChunks: createSplitVendorChunk({}, config)
|
141
|
+
}
|
160
142
|
}
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
143
|
+
}
|
144
|
+
};
|
145
|
+
}
|
146
|
+
},
|
147
|
+
buildStart() {
|
148
|
+
caches.forEach((cache) => cache.reset());
|
149
|
+
}
|
150
|
+
};
|
166
151
|
}
|
167
152
|
|
168
153
|
class ServerHMRBroadcasterClient {
|
169
|
-
|
170
|
-
|
171
|
-
|
154
|
+
constructor(hmrChannel) {
|
155
|
+
this.hmrChannel = hmrChannel;
|
156
|
+
}
|
157
|
+
send(...args) {
|
158
|
+
let payload;
|
159
|
+
if (typeof args[0] === "string") {
|
160
|
+
payload = {
|
161
|
+
type: "custom",
|
162
|
+
event: args[0],
|
163
|
+
data: args[1]
|
164
|
+
};
|
165
|
+
} else {
|
166
|
+
payload = args[0];
|
172
167
|
}
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
type: 'custom',
|
178
|
-
event: args[0],
|
179
|
-
data: args[1],
|
180
|
-
};
|
181
|
-
}
|
182
|
-
else {
|
183
|
-
payload = args[0];
|
184
|
-
}
|
185
|
-
if (payload.type !== 'custom') {
|
186
|
-
throw new Error('Cannot send non-custom events from the client to the server.');
|
187
|
-
}
|
188
|
-
this.hmrChannel.send(payload);
|
168
|
+
if (payload.type !== "custom") {
|
169
|
+
throw new Error(
|
170
|
+
"Cannot send non-custom events from the client to the server."
|
171
|
+
);
|
189
172
|
}
|
173
|
+
this.hmrChannel.send(payload);
|
174
|
+
}
|
190
175
|
}
|
191
|
-
/**
|
192
|
-
* The connector class to establish HMR communication between the server and the Vite runtime.
|
193
|
-
* @experimental
|
194
|
-
*/
|
195
176
|
class ServerHMRConnector {
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
});
|
209
|
-
this.hmrChannel = hmrChannel;
|
210
|
-
}
|
211
|
-
isReady() {
|
212
|
-
return this.connected;
|
213
|
-
}
|
214
|
-
send(message) {
|
215
|
-
const payload = JSON.parse(message);
|
216
|
-
this.hmrChannel.api.innerEmitter.emit(payload.event, payload.data, this.hmrClient);
|
217
|
-
}
|
218
|
-
onUpdate(handler) {
|
219
|
-
this.handlers.push(handler);
|
220
|
-
handler({ type: 'connected' });
|
221
|
-
this.connected = true;
|
177
|
+
handlers = [];
|
178
|
+
hmrChannel;
|
179
|
+
hmrClient;
|
180
|
+
connected = false;
|
181
|
+
constructor(server) {
|
182
|
+
const hmrChannel = server.hot?.channels.find(
|
183
|
+
(c) => c.name === "ssr"
|
184
|
+
);
|
185
|
+
if (!hmrChannel) {
|
186
|
+
throw new Error(
|
187
|
+
"Your version of Vite doesn't support HMR during SSR. Please, use Vite 5.1 or higher."
|
188
|
+
);
|
222
189
|
}
|
190
|
+
this.hmrClient = new ServerHMRBroadcasterClient(hmrChannel);
|
191
|
+
hmrChannel.api.outsideEmitter.on("send", (payload) => {
|
192
|
+
this.handlers.forEach((listener) => listener(payload));
|
193
|
+
});
|
194
|
+
this.hmrChannel = hmrChannel;
|
195
|
+
}
|
196
|
+
isReady() {
|
197
|
+
return this.connected;
|
198
|
+
}
|
199
|
+
send(message) {
|
200
|
+
const payload = JSON.parse(message);
|
201
|
+
this.hmrChannel.api.innerEmitter.emit(
|
202
|
+
payload.event,
|
203
|
+
payload.data,
|
204
|
+
this.hmrClient
|
205
|
+
);
|
206
|
+
}
|
207
|
+
onUpdate(handler) {
|
208
|
+
this.handlers.push(handler);
|
209
|
+
handler({ type: "connected" });
|
210
|
+
this.connected = true;
|
211
|
+
}
|
223
212
|
}
|
224
213
|
|
225
214
|
function createHMROptions(server, options) {
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
215
|
+
if (server.config.server.hmr === false || options.hmr === false) {
|
216
|
+
return false;
|
217
|
+
}
|
218
|
+
const connection = new ServerHMRConnector(server);
|
219
|
+
return {
|
220
|
+
connection,
|
221
|
+
logger: options.hmr?.logger
|
222
|
+
};
|
234
223
|
}
|
235
224
|
const prepareStackTrace = {
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
225
|
+
retrieveFile(id) {
|
226
|
+
if (existsSync(id)) {
|
227
|
+
return readFileSync(id, "utf-8");
|
228
|
+
}
|
229
|
+
}
|
241
230
|
};
|
242
231
|
function resolveSourceMapOptions(options) {
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
}
|
247
|
-
if (typeof options.sourcemapInterceptor === 'object') {
|
248
|
-
return { ...prepareStackTrace, ...options.sourcemapInterceptor };
|
249
|
-
}
|
250
|
-
return options.sourcemapInterceptor;
|
232
|
+
if (options.sourcemapInterceptor != null) {
|
233
|
+
if (options.sourcemapInterceptor === "prepareStackTrace") {
|
234
|
+
return prepareStackTrace;
|
251
235
|
}
|
252
|
-
if (typeof
|
253
|
-
|
236
|
+
if (typeof options.sourcemapInterceptor === "object") {
|
237
|
+
return { ...prepareStackTrace, ...options.sourcemapInterceptor };
|
254
238
|
}
|
255
|
-
return
|
239
|
+
return options.sourcemapInterceptor;
|
240
|
+
}
|
241
|
+
if (typeof process !== "undefined" && "setSourceMapsEnabled" in process) {
|
242
|
+
return "node";
|
243
|
+
}
|
244
|
+
return prepareStackTrace;
|
256
245
|
}
|
257
|
-
/**
|
258
|
-
* Create an instance of the Vite SSR runtime that support HMR.
|
259
|
-
* @experimental
|
260
|
-
*/
|
261
246
|
async function createViteRuntime(server, options = {}) {
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
247
|
+
const hmr = createHMROptions(server, options);
|
248
|
+
return new ViteRuntime(
|
249
|
+
{
|
250
|
+
...options,
|
251
|
+
root: server.config.root,
|
252
|
+
fetchModule: server.ssrFetchModule,
|
253
|
+
hmr,
|
254
|
+
sourcemapInterceptor: resolveSourceMapOptions(options)
|
255
|
+
},
|
256
|
+
options.runner || new ESModulesRunner()
|
257
|
+
);
|
270
258
|
}
|
271
259
|
|
272
260
|
export { ServerHMRConnector, createViteRuntime, isCSSRequest, splitVendorChunk, splitVendorChunkPlugin };
|