vike-lite 1.15.15 → 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.
@@ -138,7 +138,7 @@ async function resolveHydrationView(initialContext, isHydration, routes, errorRo
138
138
  Head: null
139
139
  };
140
140
  if (!isHydration) return emptyView;
141
- if ((initialContext.is404 || initialContext.is500 || initialContext.errorMessage) && errorRoute) return loadViewModules(errorRoute);
141
+ if (errorRoute && (initialContext.is404 || initialContext.is500 || initialContext.errorMessage)) return loadViewModules(errorRoute);
142
142
  const matched = matchRoute(initialContext.urlPathname ?? globalThis.location.pathname, routes);
143
143
  return matched ? loadViewModules(matched.route) : emptyView;
144
144
  }
@@ -1,2 +1,29 @@
1
1
  import { n as setVikeState, r as store, t as VikeState } from "../store-9UNcAe5D.mjs";
2
- export { VikeState, setVikeState, store };
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
- export { setVikeState, store };
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
@@ -209,7 +211,7 @@ function vikeLite({ pagesDir = "pages", apiPrefix = "/api", prerender = false, s
209
211
  } : VIRTUAL.entryServer,
210
212
  output: {
211
213
  format: "esm",
212
- entryFileNames: "index.mjs",
214
+ entryFileNames: "[name].mjs",
213
215
  chunkFileNames: (chunkInfo) => {
214
216
  if (chunkInfo.facadeModuleId?.includes(`/${pagesDir}/`)) return "assets/pages/[name].[hash].mjs";
215
217
  return "assets/chunks/[name].[hash].mjs";
@@ -221,7 +223,7 @@ function vikeLite({ pagesDir = "pages", apiPrefix = "/api", prerender = false, s
221
223
  };
222
224
  },
223
225
  configResolved(config) {
224
- if (!config.plugins.some((plugin) => plugin.name?.startsWith("vike-lite-") && SUPPORTED_RENDERERS.includes(plugin.name.replace("vike-lite-", "")))) throw new Error(`[vike-lite] No UI renderer plugin found in 'vite.config': please install and configure one of ${SUPPORTED_RENDERERS.map((r) => `vike-lite-${r}`).join(", ")}`);
226
+ if (!config.plugins.some((plugin) => plugin.name?.startsWith("vike-lite-") && SUPPORTED_RENDERERS.includes(plugin.name.replace("vike-lite-", "")))) throw new Error(`❌ No UI adapter plugin found in 'vite.config': please install and configure one of ${SUPPORTED_RENDERERS.map((r) => `vike-lite-${r}`).join(", ")}`);
225
227
  },
226
228
  resolveId(id) {
227
229
  if (VIRTUAL_VALUES.has(id)) return "\0" + id;
@@ -283,7 +285,7 @@ function vikeLite({ pagesDir = "pages", apiPrefix = "/api", prerender = false, s
283
285
  break;
284
286
  }
285
287
  }
286
- if (!serverEntryPath) throw new Error(`[vike-lite] serverEntry '${serverEntry}' file not found`);
288
+ if (!serverEntryPath) throw new Error(`❌ serverEntry ${serverEntry} file not found`);
287
289
  serverEntryPath = serverEntryPath.replaceAll("\\", "/");
288
290
  return importSetup + `export*from'${serverEntryPath}';export{default}from'${serverEntryPath}';`;
289
291
  }
@@ -314,35 +316,36 @@ function vikeLite({ pagesDir = "pages", apiPrefix = "/api", prerender = false, s
314
316
  }
315
317
  if (shouldPrerender) {
316
318
  if (route.path.includes(":") && dynamicUrls.length === 0) {
317
- console.warn(`[vike-lite] ⚠️ Skipping dynamic route "${route.path}": no URLs provided by +prerender. Return an array of URLs to prerender it.`);
319
+ console.warn(`⚠️ Skipping dynamic route ${route.path}: no URLs provided by +prerender. Return an array of URLs to prerender it.`);
318
320
  continue;
319
321
  }
320
322
  if (!route.path.includes(":")) urlsToPrerender.add(route.path);
321
323
  for (const url of dynamicUrls) urlsToPrerender.add(url);
322
324
  }
323
325
  }
324
- if (urlsToPrerender.size === 0) return;
325
- console.log("[vike-lite] 📦 Starting Static Site Generation (SSG)…");
326
- let generatedCount = 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
+ }
330
+ console.log("📦 Starting Static Site Generation (SSG)…");
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?.ok && htmlRes.headers.get("content-type")?.includes("text/html")) {
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
- } else throw new Error(`[vike-lite] SSG HTML Error for "${urlPath}"`);
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?.ok) {
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
- } else throw new Error(`[vike-lite] SSG JSON Error for "${jsonTarget}"`);
342
- console.log(` → ${urlPath}`);
343
- generatedCount++;
345
+ } else throw new Error(`❌ SSG JSON Error for "${jsonTarget}"`);
346
+ console.log(` route ${urlPath}`);
344
347
  }
345
- console.log(`[vike-lite] SSG Completed! Generated ${generatedCount} static routes`);
348
+ console.log(`✨ SSG Completed! Generated ${urlsToPrerender.size} static routes`);
346
349
  },
347
350
  configureServer(server) {
348
351
  return () => {
@@ -370,8 +373,10 @@ function vikeLite({ pagesDir = "pages", apiPrefix = "/api", prerender = false, s
370
373
  };
371
374
  if (req.url.startsWith(apiPrefix)) {
372
375
  server.config.logger.info(`⚡ API: ${req.method} ${req.url}`, { timestamp: true });
373
- requestInit.body = Readable.toWeb(req);
374
- requestInit.duplex = "half";
376
+ if (req.method !== "GET" && req.method !== "HEAD") {
377
+ requestInit.body = Readable.toWeb(req);
378
+ requestInit.duplex = "half";
379
+ }
375
380
  } else if (req.url.endsWith(".pageContext.json")) server.config.logger.info(`🔄 SPA Navigation: ${req.url}`, { timestamp: true });
376
381
  const response = await app.fetch(new Request(`http://${req.headers.host}${req.url}`, requestInit));
377
382
  res.statusCode = response.status;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike-lite",
3
- "version": "1.15.15",
3
+ "version": "1.15.17",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -82,7 +82,7 @@
82
82
  },
83
83
  "devDependencies": {
84
84
  "@types/node": "^26.1.1",
85
- "tsdown": "^0.22.9",
85
+ "tsdown": "^0.22.11",
86
86
  "vite": "^8.1.5",
87
87
  "vitest": "^4.1.10"
88
88
  },