vike-lite 1.11.0 → 1.12.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/dist/__internal/server.d.mts +2 -4
- package/dist/__internal/server.mjs +1 -1
- package/dist/__internal/shared.d.mts +23 -2
- package/dist/client/router.d.mts +0 -1
- package/dist/index.d.mts +16 -6
- package/dist/server.d.mts +1 -3
- package/dist/server.mjs +1 -1
- package/dist/{store-CfUB1COP.mjs → store-DPJQje-K.mjs} +1 -1
- package/dist/vite.d.mts +3 -8
- package/dist/vite.mjs +78 -84
- package/package.json +4 -4
- package/dist/index-ZDN-jKX_.d.mts +0 -34
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { t as Config } from "../index-ZDN-jKX_.mjs";
|
|
2
|
-
|
|
3
1
|
//#region src/server/store.d.ts
|
|
4
2
|
interface VikeState {
|
|
5
3
|
routes: typeof import('virtual:routes')['routes'];
|
|
6
4
|
errorRoute: typeof import('virtual:routes')['errorRoute'] | null;
|
|
7
|
-
config:
|
|
8
|
-
manifest:
|
|
5
|
+
config: typeof import('virtual:routes')['config'] | null;
|
|
6
|
+
manifest: typeof import('virtual:client-manifest')['default'] | null;
|
|
9
7
|
}
|
|
10
8
|
declare const store: VikeState;
|
|
11
9
|
declare function setVikeState(newState: Partial<VikeState>): void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as store, t as setVikeState } from "../store-
|
|
1
|
+
import { n as store, t as setVikeState } from "../store-DPJQje-K.mjs";
|
|
2
2
|
export { setVikeState, store };
|
|
@@ -1,2 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/__internal/shared/matchRoute.d.ts
|
|
2
|
+
declare function matchRoute(urlPathname: string, routes: typeof import('virtual:routes').routes): {
|
|
3
|
+
route: any;
|
|
4
|
+
routeParams: Record<string, string>;
|
|
5
|
+
} | null;
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/__internal/shared/index.d.ts
|
|
8
|
+
interface RenderContext {
|
|
9
|
+
pageContext: any;
|
|
10
|
+
Page: unknown;
|
|
11
|
+
Head?: unknown;
|
|
12
|
+
Layout?: unknown;
|
|
13
|
+
pageTitleTag: string;
|
|
14
|
+
serializedContext: string;
|
|
15
|
+
assets: {
|
|
16
|
+
cssLinks: string;
|
|
17
|
+
jsPreloads: string;
|
|
18
|
+
entryClient: string;
|
|
19
|
+
};
|
|
20
|
+
nonce?: string;
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
export { RenderContext, matchRoute };
|
package/dist/client/router.d.mts
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -1,16 +1,26 @@
|
|
|
1
1
|
//#region src/index.d.ts
|
|
2
|
-
type
|
|
2
|
+
type PageContextBase = {
|
|
3
3
|
routeParams: Record<string, string>;
|
|
4
4
|
urlOriginal: string;
|
|
5
5
|
urlPathname: string;
|
|
6
|
-
|
|
6
|
+
search: string;
|
|
7
7
|
title?: string;
|
|
8
|
-
nonce?: string;
|
|
9
8
|
is404?: boolean;
|
|
10
9
|
is500?: boolean;
|
|
11
10
|
errorMessage?: string;
|
|
12
11
|
};
|
|
13
|
-
type
|
|
14
|
-
|
|
12
|
+
type PageContext<Data = unknown> = PageContextBase & (unknown extends Data ? {
|
|
13
|
+
data?: Data;
|
|
14
|
+
} : {
|
|
15
|
+
data: Data;
|
|
16
|
+
});
|
|
17
|
+
type PageContextServer<Data = unknown> = PageContext<Data> & {
|
|
18
|
+
isClientSide: false;
|
|
19
|
+
nonce?: string;
|
|
20
|
+
};
|
|
21
|
+
type PageContextClient = PageContextBase & {
|
|
22
|
+
isClientSide: true;
|
|
23
|
+
isHydration?: boolean;
|
|
24
|
+
};
|
|
15
25
|
//#endregion
|
|
16
|
-
export {
|
|
26
|
+
export { PageContext, PageContextClient, PageContextServer };
|
package/dist/server.d.mts
CHANGED
package/dist/server.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as BASE_URL } from "./shared-DEpJkq09.mjs";
|
|
2
2
|
import { t as matchRoute } from "./matchRoute-nTNPxoMq.mjs";
|
|
3
3
|
import { AbortRedirect, AbortRender } from "./server/abort.mjs";
|
|
4
|
-
import { n as store } from "./store-
|
|
4
|
+
import { n as store } from "./store-DPJQje-K.mjs";
|
|
5
5
|
//#region src/utils/serializeContext.ts
|
|
6
6
|
const ESCAPE_LOOKUP = {
|
|
7
7
|
"&": String.raw`\u0026`,
|
package/dist/vite.d.mts
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import { Plugin } from "vite";
|
|
2
|
-
|
|
3
2
|
//#region src/vite-plugin.d.ts
|
|
4
|
-
declare function routerPlugin({
|
|
5
|
-
pagesDir,
|
|
6
|
-
serverEntry,
|
|
7
|
-
apiPrefix,
|
|
8
|
-
prerender
|
|
9
|
-
}?: {
|
|
3
|
+
declare function routerPlugin({ pagesDir, serverEntry, apiPrefix, prerender }?: {
|
|
10
4
|
/**
|
|
11
5
|
* The directory where your page components are located.
|
|
12
6
|
* This is where the plugin will look for your page files to generate routes.
|
|
@@ -26,7 +20,8 @@ declare function routerPlugin({
|
|
|
26
20
|
*/
|
|
27
21
|
apiPrefix?: string;
|
|
28
22
|
/**
|
|
29
|
-
* Whether to prerender the pages.
|
|
23
|
+
* Whether to prerender the pages by default.
|
|
24
|
+
* Individual pages can override this via +prerender.ts.
|
|
30
25
|
* @default false
|
|
31
26
|
*/
|
|
32
27
|
prerender?: boolean;
|
package/dist/vite.mjs
CHANGED
|
@@ -102,17 +102,18 @@ function routerPlugin({ pagesDir = "pages", serverEntry = "server/index", apiPre
|
|
|
102
102
|
const isProd = process.env.NODE_ENV === "production";
|
|
103
103
|
let viteConfigRoot;
|
|
104
104
|
let outDir;
|
|
105
|
-
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const
|
|
105
|
+
let hasAnyPrerender;
|
|
106
|
+
const VIRTUAL = {
|
|
107
|
+
routes: "virtual:routes",
|
|
108
|
+
manifest: "virtual:client-manifest",
|
|
109
|
+
renderer: "virtual:vike-lite/renderer",
|
|
110
|
+
entryClient: "virtual:entry-client",
|
|
111
|
+
setup: "virtual:vike-lite/setup",
|
|
112
|
+
entryServer: "virtual:entry-server",
|
|
113
|
+
entryPrerender: "virtual:entry-prerender"
|
|
114
|
+
};
|
|
115
|
+
const VIRTUAL_VALUES = new Set(Object.values(VIRTUAL));
|
|
116
|
+
const RESOLVED = Object.fromEntries(Object.entries(VIRTUAL).map(([k, v]) => [k, `\0${v}`]));
|
|
116
117
|
return {
|
|
117
118
|
name: "vike-lite",
|
|
118
119
|
config(config, { mode }) {
|
|
@@ -120,6 +121,9 @@ function routerPlugin({ pagesDir = "pages", serverEntry = "server/index", apiPre
|
|
|
120
121
|
for (const key in envVariables) if (process.env[key] === void 0) process.env[key] = envVariables[key];
|
|
121
122
|
outDir = config.build?.outDir ?? "dist";
|
|
122
123
|
const { emptyOutDir, minify = true, cssMinify = true, sourcemap } = config.build || {};
|
|
124
|
+
viteConfigRoot = config.root ? path.resolve(config.root) : process.cwd();
|
|
125
|
+
const { routes } = generateRoutes(viteConfigRoot, pagesDir);
|
|
126
|
+
hasAnyPrerender = prerender || routes.some((r) => r.prerender);
|
|
123
127
|
return {
|
|
124
128
|
appType: "custom",
|
|
125
129
|
ssr: { noExternal: [/^vike-lite(?:$|-)/] },
|
|
@@ -132,7 +136,7 @@ function routerPlugin({ pagesDir = "pages", serverEntry = "server/index", apiPre
|
|
|
132
136
|
sourcemap,
|
|
133
137
|
manifest: true,
|
|
134
138
|
rolldownOptions: {
|
|
135
|
-
input:
|
|
139
|
+
input: VIRTUAL.entryClient,
|
|
136
140
|
output: {
|
|
137
141
|
format: "esm",
|
|
138
142
|
hoistTransitiveImports: false,
|
|
@@ -184,7 +188,10 @@ function routerPlugin({ pagesDir = "pages", serverEntry = "server/index", apiPre
|
|
|
184
188
|
minify,
|
|
185
189
|
sourcemap,
|
|
186
190
|
rolldownOptions: {
|
|
187
|
-
input:
|
|
191
|
+
input: hasAnyPrerender ? {
|
|
192
|
+
index: VIRTUAL.entryServer,
|
|
193
|
+
prerender: VIRTUAL.entryPrerender
|
|
194
|
+
} : VIRTUAL.entryServer,
|
|
188
195
|
output: {
|
|
189
196
|
format: "esm",
|
|
190
197
|
entryFileNames: "index.mjs",
|
|
@@ -199,21 +206,16 @@ function routerPlugin({ pagesDir = "pages", serverEntry = "server/index", apiPre
|
|
|
199
206
|
};
|
|
200
207
|
},
|
|
201
208
|
configResolved(config) {
|
|
202
|
-
viteConfigRoot = config.root;
|
|
203
209
|
if (!config.plugins.some((plugin) => plugin.name?.startsWith("vike-lite-") && SUPPORTED_RENDERERS.includes(plugin.name.replace("vike-lite-", "")))) throw new Error(`No UI renderer plugin found in 'vite.config': please install and configure one of ${SUPPORTED_RENDERERS.map((r) => `vike-lite-${r}`).join(", ")}`);
|
|
204
210
|
},
|
|
205
211
|
resolveId(id) {
|
|
206
|
-
if (id
|
|
207
|
-
if (id === virtualManifestId) return resolvedVirtualManifestId;
|
|
208
|
-
if (id === virtualEntryClientId) return resolvedVirtualEntryClientId;
|
|
209
|
-
if (id === virtualSetupId) return resolvedVirtualSetupId;
|
|
210
|
-
if (id === virtualEntryServerId) return resolvedVirtualEntryServerId;
|
|
212
|
+
if (VIRTUAL_VALUES.has(id)) return "\0" + id;
|
|
211
213
|
},
|
|
212
214
|
async load(id, options) {
|
|
213
|
-
if (id ===
|
|
215
|
+
if (id === RESOLVED.routes) {
|
|
214
216
|
const { routes, errorRoute } = generateRoutes(viteConfigRoot, pagesDir);
|
|
215
217
|
const isSSR = options.ssr;
|
|
216
|
-
let code = `import { onRenderHtml } from '${
|
|
218
|
+
let code = `import { onRenderHtml } from '${VIRTUAL.renderer}';\nexport const config = { onRenderHtml };\nexport const routes = [\n`;
|
|
217
219
|
for (const r of routes) {
|
|
218
220
|
code += `{path:'${r.path}',page:'${r.page}',Page:()=>import('/${r.page}'),`;
|
|
219
221
|
if (r.head) code += `head:'${r.head}',Head:()=>import('/${r.head}'),`;
|
|
@@ -238,44 +240,30 @@ function routerPlugin({ pagesDir = "pages", serverEntry = "server/index", apiPre
|
|
|
238
240
|
} else code += "export const errorRoute=null;\n";
|
|
239
241
|
return code;
|
|
240
242
|
}
|
|
241
|
-
if (id ===
|
|
243
|
+
if (id === RESOLVED.manifest) {
|
|
242
244
|
if (!isProd || !options?.ssr) return "export default {}";
|
|
243
245
|
const manifestPath = path.join(viteConfigRoot, outDir, "client/.vite/manifest.json");
|
|
244
246
|
return `export default ${fs.readFileSync(manifestPath, "utf8")}`;
|
|
245
247
|
}
|
|
246
|
-
if (id ===
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
await render({ routes, errorRoute });`;
|
|
250
|
-
if (id === resolvedVirtualSetupId) return `import { routes, errorRoute, config } from '${virtualModuleId}';
|
|
251
|
-
import { setVikeState } from 'vike-lite/__internal/server';
|
|
252
|
-
let manifest;
|
|
253
|
-
if (process.env.NODE_ENV === 'production') {
|
|
254
|
-
manifest = (await import('${virtualManifestId}')).default;
|
|
255
|
-
}
|
|
256
|
-
setVikeState({ routes, errorRoute, config, manifest });`;
|
|
257
|
-
if (id === resolvedVirtualEntryServerId) {
|
|
258
|
-
let hasCustomServer = false;
|
|
259
|
-
let customServerPath = "";
|
|
248
|
+
if (id === RESOLVED.entryClient) return `import{routes,errorRoute}from'${VIRTUAL.routes}';import{onRenderClient}from'${VIRTUAL.renderer}';const{default:render}=await onRenderClient();await render({routes,errorRoute});`;
|
|
249
|
+
if (id === RESOLVED.setup) return `import{routes,errorRoute,config}from'${VIRTUAL.routes}';import{setVikeState}from'vike-lite/__internal/server';const manifest=process.env.NODE_ENV==='production'?(await import('${VIRTUAL.manifest}')).default:null;setVikeState({routes,errorRoute,config,manifest});`;
|
|
250
|
+
if (id === RESOLVED.entryServer) {
|
|
260
251
|
if (serverEntry) {
|
|
261
252
|
const basePath = path.resolve(viteConfigRoot, serverEntry);
|
|
253
|
+
let serverEntryPath = "";
|
|
262
254
|
for (const ext of [
|
|
263
255
|
".ts",
|
|
264
256
|
".js",
|
|
265
257
|
".mjs"
|
|
266
258
|
]) if (fs.existsSync(basePath + ext)) {
|
|
267
|
-
|
|
268
|
-
customServerPath = (basePath + ext).replaceAll("\\", "/");
|
|
259
|
+
serverEntryPath = (basePath + ext).replaceAll("\\", "/");
|
|
269
260
|
break;
|
|
270
261
|
}
|
|
262
|
+
if (!serverEntryPath) throw new Error(`[vike-lite] serverEntry ${serverEntry} file not found!`);
|
|
263
|
+
return `import '${VIRTUAL.setup}';export * from'${serverEntryPath}';export{default}from'${serverEntryPath}';`;
|
|
271
264
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
export default {
|
|
275
|
-
async fetch(request) {
|
|
276
|
-
return renderPage(request);
|
|
277
|
-
}
|
|
278
|
-
};
|
|
265
|
+
return `import '${VIRTUAL.setup}';import{renderPage}from'vike-lite/server';
|
|
266
|
+
export default{async fetch(request){return renderPage(request);}};
|
|
279
267
|
if (process.env.NODE_ENV === 'production') {
|
|
280
268
|
const { createServer } = await import('node:http');
|
|
281
269
|
const { Readable } = await import('node:stream');
|
|
@@ -291,18 +279,27 @@ if (process.env.NODE_ENV === 'production') {
|
|
|
291
279
|
'.mjs': 'text/javascript; charset=utf-8',
|
|
292
280
|
'.css': 'text/css; charset=utf-8',
|
|
293
281
|
'.json': 'application/json; charset=utf-8',
|
|
282
|
+
'.xml': 'application/xml',
|
|
283
|
+
'.txt': 'text/plain; charset=utf-8',
|
|
284
|
+
'.map': 'application/json; charset=utf-8',
|
|
294
285
|
'.png': 'image/png',
|
|
295
286
|
'.jpg': 'image/jpeg',
|
|
296
287
|
'.jpeg': 'image/jpeg',
|
|
297
288
|
'.gif': 'image/gif',
|
|
298
289
|
'.svg': 'image/svg+xml',
|
|
299
290
|
'.ico': 'image/x-icon',
|
|
300
|
-
'.
|
|
301
|
-
'.
|
|
302
|
-
'.txt': 'text/plain; charset=utf-8',
|
|
291
|
+
'.webp': 'image/webp',
|
|
292
|
+
'.avif': 'image/avif',
|
|
303
293
|
'.woff': 'font/woff',
|
|
304
294
|
'.woff2': 'font/woff2',
|
|
305
|
-
'.
|
|
295
|
+
'.ttf': 'font/ttf',
|
|
296
|
+
'.otf': 'font/otf',
|
|
297
|
+
'.mp4': 'video/mp4',
|
|
298
|
+
'.webm': 'video/webm',
|
|
299
|
+
'.mp3': 'audio/mpeg',
|
|
300
|
+
'.pdf': 'application/pdf',
|
|
301
|
+
'.wasm': 'application/wasm',
|
|
302
|
+
'.webmanifest': 'application/manifest+json'
|
|
306
303
|
};
|
|
307
304
|
const { BASE_URL } = import.meta.env;
|
|
308
305
|
const server = createServer(async (req, res) => {
|
|
@@ -334,22 +331,13 @@ if (process.env.NODE_ENV === 'production') {
|
|
|
334
331
|
}
|
|
335
332
|
const { method } = req;
|
|
336
333
|
const init = { method, headers };
|
|
337
|
-
if (
|
|
338
|
-
res.end()
|
|
339
|
-
return
|
|
340
|
-
}
|
|
341
|
-
if (method !== 'GET' && method !== 'HEAD') {
|
|
342
|
-
init.body = Readable.toWeb(req);
|
|
343
|
-
init.duplex = 'half';
|
|
344
|
-
}
|
|
334
|
+
if (method !== 'GET' && method !== 'HEAD') { init.body = Readable.toWeb(req); init.duplex = 'half'; }
|
|
345
335
|
const request = new Request(urlObj.href, init);
|
|
346
336
|
const response = await renderPage(request);
|
|
347
337
|
res.statusCode = response.status;
|
|
348
|
-
for (const [key, val] of response.headers)
|
|
349
|
-
|
|
350
|
-
}
|
|
351
|
-
if (response.body) await pipeline(Readable.fromWeb(response.body), res);
|
|
352
|
-
else res.end();
|
|
338
|
+
for (const [key, val] of response.headers) res.setHeader(key, val);
|
|
339
|
+
if (method === 'HEAD' || !response.body) { await response.body?.cancel(); res.end(); return; }
|
|
340
|
+
try { await pipeline(Readable.fromWeb(response.body), res); } catch {}
|
|
353
341
|
} catch (e) {
|
|
354
342
|
console.error(e);
|
|
355
343
|
res.statusCode = 500;
|
|
@@ -363,19 +351,19 @@ if (process.env.NODE_ENV === 'production') {
|
|
|
363
351
|
});
|
|
364
352
|
}`;
|
|
365
353
|
}
|
|
354
|
+
if (id === RESOLVED.entryPrerender) return `import'${VIRTUAL.setup}';export{routes}from'${VIRTUAL.routes}';`;
|
|
366
355
|
},
|
|
367
356
|
async closeBundle() {
|
|
368
|
-
if (!
|
|
369
|
-
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
357
|
+
if (!isProd || this.environment.name !== "ssr") return;
|
|
370
358
|
const { pathToFileURL } = await import("node:url");
|
|
371
|
-
const
|
|
372
|
-
if (!fs.existsSync(
|
|
373
|
-
const
|
|
374
|
-
|
|
375
|
-
const
|
|
359
|
+
const prerenderPath = path.resolve(viteConfigRoot, outDir, "server/prerender.mjs");
|
|
360
|
+
if (!fs.existsSync(prerenderPath)) return;
|
|
361
|
+
const { routes } = await import(pathToFileURL(prerenderPath).href);
|
|
362
|
+
if (!routes) return;
|
|
363
|
+
const { renderPage } = await import("vike-lite/server");
|
|
376
364
|
const urlsToPrerender = /* @__PURE__ */ new Set();
|
|
377
365
|
for (const route of routes) {
|
|
378
|
-
let shouldPrerender =
|
|
366
|
+
let shouldPrerender = prerender;
|
|
379
367
|
let dynamicUrls = [];
|
|
380
368
|
if (route.Prerender) {
|
|
381
369
|
const mod = await route.Prerender();
|
|
@@ -389,7 +377,11 @@ if (process.env.NODE_ENV === 'production') {
|
|
|
389
377
|
}
|
|
390
378
|
}
|
|
391
379
|
if (shouldPrerender) {
|
|
392
|
-
if (
|
|
380
|
+
if (route.path.includes(":") && dynamicUrls.length === 0) {
|
|
381
|
+
console.warn(`[vike-lite] ⚠️ Skipping dynamic route "${route.path}": no URLs provided by +prerender. Return an array of URLs to prerender it.`);
|
|
382
|
+
continue;
|
|
383
|
+
}
|
|
384
|
+
if (!route.path.includes(":")) urlsToPrerender.add(route.path);
|
|
393
385
|
for (const url of dynamicUrls) urlsToPrerender.add(url);
|
|
394
386
|
}
|
|
395
387
|
}
|
|
@@ -400,21 +392,19 @@ if (process.env.NODE_ENV === 'production') {
|
|
|
400
392
|
let generatedCount = 0;
|
|
401
393
|
const clientDir = path.resolve(viteConfigRoot, outDir, "client");
|
|
402
394
|
for (const urlPath of urlsToPrerender) {
|
|
403
|
-
const
|
|
404
|
-
|
|
405
|
-
if (htmlRes.ok && htmlRes.headers.get("content-type")?.includes("text/html")) {
|
|
395
|
+
const htmlRes = await renderPage(new Request(`http://localhost${baseNoSlash}${urlPath}`));
|
|
396
|
+
if (htmlRes && htmlRes.ok && htmlRes.headers.get("content-type")?.includes("text/html")) {
|
|
406
397
|
const outDirRoute = path.join(clientDir, urlPath === "/" ? "" : urlPath);
|
|
407
398
|
fs.mkdirSync(outDirRoute, { recursive: true });
|
|
408
399
|
fs.writeFileSync(path.join(outDirRoute, "index.html"), await htmlRes.text());
|
|
409
|
-
} else
|
|
400
|
+
} else throw new Error(`\u{1B}[31m✖ SSG HTML Error for ${urlPath}\u{1B}[0m`);
|
|
410
401
|
const jsonTarget = urlPath === "/" ? "/index" : urlPath;
|
|
411
|
-
const
|
|
412
|
-
|
|
413
|
-
if (jsonRes.ok) {
|
|
402
|
+
const jsonRes = await renderPage(new Request(`http://localhost${baseNoSlash}${jsonTarget}.pageContext.json`));
|
|
403
|
+
if (jsonRes && jsonRes.ok) {
|
|
414
404
|
const jsonOutPath = path.join(clientDir, `${jsonTarget}.pageContext.json`);
|
|
415
405
|
fs.mkdirSync(path.dirname(jsonOutPath), { recursive: true });
|
|
416
406
|
fs.writeFileSync(jsonOutPath, await jsonRes.text());
|
|
417
|
-
} else
|
|
407
|
+
} else throw new Error(`\u{1B}[31m✖ SSG JSON Error for ${jsonTarget}\u{1B}[0m`);
|
|
418
408
|
console.log(`\u{1B}[32m✓\u{1B}[0m Pre-rendered: ${urlPath}`);
|
|
419
409
|
generatedCount++;
|
|
420
410
|
}
|
|
@@ -426,14 +416,14 @@ if (process.env.NODE_ENV === 'production') {
|
|
|
426
416
|
server.watcher.on("all", (event, file) => {
|
|
427
417
|
if (!((event === "add" || event === "unlink") && file.startsWith(pagesPath))) return;
|
|
428
418
|
for (const env of Object.values(server.environments)) {
|
|
429
|
-
const mod = env.moduleGraph.getModuleById(
|
|
419
|
+
const mod = env.moduleGraph.getModuleById(RESOLVED.routes);
|
|
430
420
|
if (mod) env.moduleGraph.invalidateModule(mod);
|
|
431
421
|
}
|
|
432
422
|
server.ws.send({ type: "full-reload" });
|
|
433
423
|
});
|
|
434
424
|
server.middlewares.use(async (req, res, next) => {
|
|
435
425
|
try {
|
|
436
|
-
const { default: app } = await server.environments.ssr.runner.import(
|
|
426
|
+
const { default: app } = await server.environments.ssr.runner.import(RESOLVED.entryServer);
|
|
437
427
|
const headers = new Headers();
|
|
438
428
|
for (const [key, value] of Object.entries(req.headers)) {
|
|
439
429
|
if (key.startsWith(":")) continue;
|
|
@@ -461,11 +451,15 @@ if (process.env.NODE_ENV === 'production') {
|
|
|
461
451
|
return;
|
|
462
452
|
}
|
|
463
453
|
for (const [key, value] of response.headers) res.setHeader(key, value);
|
|
464
|
-
if (!response.body) {
|
|
465
|
-
|
|
454
|
+
if (req.method === "HEAD" || !response.body) {
|
|
455
|
+
await response.body?.cancel();
|
|
456
|
+
if (!res.destroyed && !res.closed) res.end();
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
if (res.destroyed || res.closed) {
|
|
460
|
+
await response.body.cancel();
|
|
466
461
|
return;
|
|
467
462
|
}
|
|
468
|
-
if (res.destroyed || res.closed) return;
|
|
469
463
|
try {
|
|
470
464
|
await pipeline(Readable.fromWeb(response.body), res);
|
|
471
465
|
} catch {}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vike-lite",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -49,9 +49,9 @@
|
|
|
49
49
|
"build": "tsdown"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@types/node": "^26.1.
|
|
53
|
-
"tsdown": "^0.22.
|
|
54
|
-
"vite": "^8.1.
|
|
52
|
+
"@types/node": "^26.1.1",
|
|
53
|
+
"tsdown": "^0.22.4",
|
|
54
|
+
"vite": "^8.1.4"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
57
|
"vite": ">=8"
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
//#region src/__internal/shared/matchRoute.d.ts
|
|
2
|
-
declare function matchRoute(urlPathname: string, routes: typeof import('virtual:routes').routes): {
|
|
3
|
-
route: any;
|
|
4
|
-
routeParams: Record<string, string>;
|
|
5
|
-
} | null;
|
|
6
|
-
//#endregion
|
|
7
|
-
//#region src/__internal/shared/index.d.ts
|
|
8
|
-
interface RenderContext {
|
|
9
|
-
pageContext: any;
|
|
10
|
-
Page: unknown;
|
|
11
|
-
Head?: unknown;
|
|
12
|
-
Layout?: unknown;
|
|
13
|
-
pageTitleTag: string;
|
|
14
|
-
serializedContext: string;
|
|
15
|
-
assets: {
|
|
16
|
-
cssLinks: string;
|
|
17
|
-
jsPreloads: string;
|
|
18
|
-
entryClient: string;
|
|
19
|
-
};
|
|
20
|
-
nonce?: string;
|
|
21
|
-
}
|
|
22
|
-
type Config = {
|
|
23
|
-
onRenderHtml: () => Promise<{
|
|
24
|
-
default: (ctx: RenderContext) => Promise<string>;
|
|
25
|
-
}>;
|
|
26
|
-
onRenderClient: () => Promise<{
|
|
27
|
-
default: (opts: {
|
|
28
|
-
routes: any[];
|
|
29
|
-
errorRoute: any;
|
|
30
|
-
}) => void;
|
|
31
|
-
}>;
|
|
32
|
-
};
|
|
33
|
-
//#endregion
|
|
34
|
-
export { RenderContext as n, matchRoute as r, Config as t };
|