arcway 0.4.10 → 0.4.11
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/package.json
CHANGED
|
@@ -11,14 +11,65 @@ const DEFAULTS = {
|
|
|
11
11
|
},
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
+
const HMR_KEYS = new Set(['protocol', 'host', 'clientPort']);
|
|
15
|
+
|
|
16
|
+
function resolveHmr(rawHmr) {
|
|
17
|
+
if (rawHmr == null) return undefined;
|
|
18
|
+
if (typeof rawHmr !== 'object' || Array.isArray(rawHmr)) {
|
|
19
|
+
throw new TypeError('Invalid config: pages.vite.hmr must be an object');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
for (const key of Object.keys(rawHmr)) {
|
|
23
|
+
if (!HMR_KEYS.has(key)) {
|
|
24
|
+
throw new TypeError(`Invalid config: pages.vite.hmr.${key} is not supported`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const hmr = {};
|
|
29
|
+
if (rawHmr.protocol != null) {
|
|
30
|
+
if (!['ws', 'wss'].includes(rawHmr.protocol)) {
|
|
31
|
+
throw new TypeError('Invalid config: pages.vite.hmr.protocol must be "ws" or "wss"');
|
|
32
|
+
}
|
|
33
|
+
hmr.protocol = rawHmr.protocol;
|
|
34
|
+
}
|
|
35
|
+
if (rawHmr.host != null) {
|
|
36
|
+
if (
|
|
37
|
+
typeof rawHmr.host !== 'string' ||
|
|
38
|
+
rawHmr.host.length === 0 ||
|
|
39
|
+
rawHmr.host.trim() !== rawHmr.host ||
|
|
40
|
+
/[/?#\s]/.test(rawHmr.host)
|
|
41
|
+
) {
|
|
42
|
+
throw new TypeError('Invalid config: pages.vite.hmr.host must be a hostname');
|
|
43
|
+
}
|
|
44
|
+
hmr.host = rawHmr.host;
|
|
45
|
+
}
|
|
46
|
+
if (rawHmr.clientPort != null) {
|
|
47
|
+
if (
|
|
48
|
+
!Number.isInteger(rawHmr.clientPort) ||
|
|
49
|
+
rawHmr.clientPort < 1 ||
|
|
50
|
+
rawHmr.clientPort > 65535
|
|
51
|
+
) {
|
|
52
|
+
throw new TypeError(
|
|
53
|
+
'Invalid config: pages.vite.hmr.clientPort must be an integer from 1 to 65535',
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
hmr.clientPort = rawHmr.clientPort;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return Object.keys(hmr).length > 0 ? hmr : undefined;
|
|
60
|
+
}
|
|
61
|
+
|
|
14
62
|
function resolve(config, { rootDir } = {}) {
|
|
15
63
|
const rawPages = config.pages ?? {};
|
|
64
|
+
const { hmr: rawHmr, ...rawVite } = rawPages.vite ?? {};
|
|
65
|
+
const hmr = resolveHmr(rawHmr);
|
|
16
66
|
const pages = {
|
|
17
67
|
...DEFAULTS,
|
|
18
68
|
...rawPages,
|
|
19
69
|
vite: {
|
|
20
70
|
...DEFAULTS.vite,
|
|
21
|
-
...
|
|
71
|
+
...rawVite,
|
|
72
|
+
...(hmr ? { hmr } : {}),
|
|
22
73
|
},
|
|
23
74
|
};
|
|
24
75
|
if (pages.dir && !path.isAbsolute(pages.dir)) {
|
|
@@ -33,4 +84,5 @@ function resolve(config, { rootDir } = {}) {
|
|
|
33
84
|
return { ...config, pages };
|
|
34
85
|
}
|
|
35
86
|
|
|
87
|
+
export { resolveHmr };
|
|
36
88
|
export default resolve;
|
package/server/pages/vite-dev.js
CHANGED
|
@@ -203,14 +203,20 @@ function resolveAppAliases(rootDir) {
|
|
|
203
203
|
return aliases;
|
|
204
204
|
}
|
|
205
205
|
|
|
206
|
-
|
|
206
|
+
function getViteServerOptions(config) {
|
|
207
|
+
const hmr = config?.pages?.vite?.hmr;
|
|
208
|
+
return {
|
|
209
|
+
middlewareMode: true,
|
|
210
|
+
...(hmr ? { hmr } : {}),
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
async function createViteDevRouter({ rootDir, log, config }) {
|
|
207
215
|
const appAliases = resolveAppAliases(rootDir);
|
|
208
216
|
const vite = await createViteServer({
|
|
209
217
|
root: rootDir,
|
|
210
218
|
appType: 'custom',
|
|
211
|
-
server:
|
|
212
|
-
middlewareMode: true,
|
|
213
|
-
},
|
|
219
|
+
server: getViteServerOptions(config),
|
|
214
220
|
resolve: {
|
|
215
221
|
alias: appAliases,
|
|
216
222
|
dedupe: ['react', 'react-dom', 'swr'],
|
|
@@ -274,6 +280,7 @@ export {
|
|
|
274
280
|
buildViteClientManifestJson,
|
|
275
281
|
buildViteRoute,
|
|
276
282
|
createViteDevRouter,
|
|
283
|
+
getViteServerOptions,
|
|
277
284
|
getViteEntryPath,
|
|
278
285
|
getViteFontsPath,
|
|
279
286
|
syncViteHydrationEntries,
|