vike-lite 1.15.16 → 1.15.17
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 +28 -1
- package/dist/__internal/server.mjs +29 -1
- package/dist/vite.mjs +14 -13
- package/package.json +1 -1
|
@@ -1,2 +1,29 @@
|
|
|
1
1
|
import { n as setVikeState, r as store, t as VikeState } from "../store-9UNcAe5D.mjs";
|
|
2
|
-
|
|
2
|
+
//#region src/__internal/server.d.ts
|
|
3
|
+
interface HtmlShellParams {
|
|
4
|
+
pageTitleTag: string;
|
|
5
|
+
cssLinks: string;
|
|
6
|
+
jsPreloads: string;
|
|
7
|
+
/** Statically rendered <head> content (not part of the hydrated tree). */
|
|
8
|
+
headHtml: string;
|
|
9
|
+
/** Server-rendered app markup, or '' in Client Takeover mode. */
|
|
10
|
+
appHtml: string;
|
|
11
|
+
serializedContext: string;
|
|
12
|
+
entryClient: string;
|
|
13
|
+
nonce?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Extra markup injected right after `headHtml`, before the context script.
|
|
16
|
+
* Used by Solid for `generateHydrationScript()`.
|
|
17
|
+
*/
|
|
18
|
+
extraHeadHtml?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Renders the HTML document shell shared by every adapter: doctype, meta tags,
|
|
22
|
+
* asset links, the injected `__PAGE_CONTEXT__` script, the root container and
|
|
23
|
+
* the client entry script. Centralized so that CSP nonce handling (and any other
|
|
24
|
+
* cross-cutting concern) is applied consistently instead of drifting between
|
|
25
|
+
* React/Vue/Solid, as it did before this was factored out.
|
|
26
|
+
*/
|
|
27
|
+
declare function renderHtmlShell({ pageTitleTag, cssLinks, jsPreloads, headHtml, appHtml, serializedContext, entryClient, nonce, extraHeadHtml }: HtmlShellParams): string;
|
|
28
|
+
//#endregion
|
|
29
|
+
export { VikeState, renderHtmlShell, setVikeState, store };
|
|
@@ -1,2 +1,30 @@
|
|
|
1
1
|
import { n as store, t as setVikeState } from "../store-BCs8gL_o.mjs";
|
|
2
|
-
|
|
2
|
+
//#region src/__internal/server.ts
|
|
3
|
+
/**
|
|
4
|
+
* Renders the HTML document shell shared by every adapter: doctype, meta tags,
|
|
5
|
+
* asset links, the injected `__PAGE_CONTEXT__` script, the root container and
|
|
6
|
+
* the client entry script. Centralized so that CSP nonce handling (and any other
|
|
7
|
+
* cross-cutting concern) is applied consistently instead of drifting between
|
|
8
|
+
* React/Vue/Solid, as it did before this was factored out.
|
|
9
|
+
*/
|
|
10
|
+
function renderHtmlShell({ pageTitleTag, cssLinks, jsPreloads, headHtml, appHtml, serializedContext, entryClient, nonce, extraHeadHtml = "" }) {
|
|
11
|
+
const nonceAttr = nonce ? ` nonce="${nonce}"` : "";
|
|
12
|
+
return `<!DOCTYPE html>
|
|
13
|
+
<html lang="en">
|
|
14
|
+
<head>
|
|
15
|
+
<meta charset="utf-8">
|
|
16
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
17
|
+
${pageTitleTag}
|
|
18
|
+
${cssLinks}
|
|
19
|
+
${jsPreloads}
|
|
20
|
+
${headHtml}
|
|
21
|
+
${extraHeadHtml ? `${extraHeadHtml}\n` : ""}<script${nonceAttr}>window.__PAGE_CONTEXT__=${serializedContext}<\/script>
|
|
22
|
+
</head>
|
|
23
|
+
<body>
|
|
24
|
+
<div id="root" tabindex="-1">${appHtml}</div>
|
|
25
|
+
<script type="module" src="${entryClient}"${nonceAttr}><\/script>
|
|
26
|
+
</body>
|
|
27
|
+
</html>`;
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
export { renderHtmlShell, setVikeState, store };
|
package/dist/vite.mjs
CHANGED
|
@@ -8,6 +8,7 @@ const nonPageExtensions = [".ts", ".js"];
|
|
|
8
8
|
const pageExtensions = [
|
|
9
9
|
".tsx",
|
|
10
10
|
".jsx",
|
|
11
|
+
".svelte",
|
|
11
12
|
".vue"
|
|
12
13
|
];
|
|
13
14
|
function findFile(files, basename, extensions) {
|
|
@@ -104,6 +105,7 @@ async function injectFOUCStyles(server, html) {
|
|
|
104
105
|
const SUPPORTED_RENDERERS = [
|
|
105
106
|
"react",
|
|
106
107
|
"solid",
|
|
108
|
+
"svelte",
|
|
107
109
|
"vue"
|
|
108
110
|
];
|
|
109
111
|
//#endregion
|
|
@@ -321,32 +323,29 @@ function vikeLite({ pagesDir = "pages", apiPrefix = "/api", prerender = false, s
|
|
|
321
323
|
for (const url of dynamicUrls) urlsToPrerender.add(url);
|
|
322
324
|
}
|
|
323
325
|
}
|
|
324
|
-
if (urlsToPrerender.size === 0)
|
|
326
|
+
if (urlsToPrerender.size === 0) {
|
|
327
|
+
console.warn("⚠️ No static routes to generate: if you don't want to use SSG, in the 'vite.config' set the \"prerender\" option as \"false\" or remove it.");
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
325
330
|
console.log("📦 Starting Static Site Generation (SSG)…");
|
|
326
|
-
let generatedCount = 0;
|
|
327
331
|
const clientDir = path.join(viteConfigRoot, outDir, "client");
|
|
328
332
|
for (const urlPath of urlsToPrerender) {
|
|
329
333
|
const htmlRes = await renderPage(new Request(`http://localhost${baseUrl}${urlPath}`));
|
|
330
|
-
if (htmlRes
|
|
334
|
+
if (htmlRes.ok && htmlRes.headers.get("content-type")?.includes("text/html")) {
|
|
331
335
|
const outDirRoute = path.join(clientDir, urlPath === "/" ? "" : urlPath);
|
|
332
336
|
fs.mkdirSync(outDirRoute, { recursive: true });
|
|
333
337
|
fs.writeFileSync(path.join(outDirRoute, "index.html"), await htmlRes.text());
|
|
334
338
|
} else throw new Error(`❌ SSG HTML Error for "${urlPath}"`);
|
|
335
339
|
const jsonTarget = urlPath === "/" ? "/index" : urlPath;
|
|
336
340
|
const jsonRes = await renderPage(new Request(`http://localhost${baseUrl}${jsonTarget}.pageContext.json`));
|
|
337
|
-
if (jsonRes
|
|
341
|
+
if (jsonRes.ok) {
|
|
338
342
|
const jsonOutPath = path.join(clientDir, `${jsonTarget}.pageContext.json`);
|
|
339
343
|
fs.mkdirSync(path.dirname(jsonOutPath), { recursive: true });
|
|
340
344
|
fs.writeFileSync(jsonOutPath, await jsonRes.text());
|
|
341
345
|
} else throw new Error(`❌ SSG JSON Error for "${jsonTarget}"`);
|
|
342
|
-
console.log(`
|
|
343
|
-
generatedCount++;
|
|
346
|
+
console.log(` → route ${urlPath}`);
|
|
344
347
|
}
|
|
345
|
-
|
|
346
|
-
console.warn("ℹ️ No static routes to generate. If you don't want to use SSG, in the 'vite.config', set \"prerender\" option as \"false\" or remove.");
|
|
347
|
-
return;
|
|
348
|
-
}
|
|
349
|
-
console.log(`✨ SSG Completed! Generated ${generatedCount} static routes`);
|
|
348
|
+
console.log(`✨ SSG Completed! Generated ${urlsToPrerender.size} static routes`);
|
|
350
349
|
},
|
|
351
350
|
configureServer(server) {
|
|
352
351
|
return () => {
|
|
@@ -374,8 +373,10 @@ function vikeLite({ pagesDir = "pages", apiPrefix = "/api", prerender = false, s
|
|
|
374
373
|
};
|
|
375
374
|
if (req.url.startsWith(apiPrefix)) {
|
|
376
375
|
server.config.logger.info(`⚡ API: ${req.method} ${req.url}`, { timestamp: true });
|
|
377
|
-
|
|
378
|
-
|
|
376
|
+
if (req.method !== "GET" && req.method !== "HEAD") {
|
|
377
|
+
requestInit.body = Readable.toWeb(req);
|
|
378
|
+
requestInit.duplex = "half";
|
|
379
|
+
}
|
|
379
380
|
} else if (req.url.endsWith(".pageContext.json")) server.config.logger.info(`🔄 SPA Navigation: ${req.url}`, { timestamp: true });
|
|
380
381
|
const response = await app.fetch(new Request(`http://${req.headers.host}${req.url}`, requestInit));
|
|
381
382
|
res.statusCode = response.status;
|