vike-lite 1.13.1 → 1.13.3

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.
@@ -1,9 +1,9 @@
1
1
  //#region src/server/store.d.ts
2
2
  interface VikeState {
3
- routes: typeof import('virtual:routes')['routes'];
4
- errorRoute: typeof import('virtual:routes')['errorRoute'] | null;
5
- config: typeof import('virtual:routes')['config'] | null;
6
- manifest: typeof import('virtual:client-manifest')['default'] | null;
3
+ routes: typeof import('virtual:vike-lite/routes')['routes'];
4
+ errorRoute: typeof import('virtual:vike-lite/routes')['errorRoute'] | null;
5
+ config: typeof import('virtual:vike-lite/routes')['config'] | null;
6
+ manifest: typeof import('virtual:vike-lite/client-manifest')['default'] | null;
7
7
  }
8
8
  declare const store: VikeState;
9
9
  declare function setVikeState(newState: Partial<VikeState>): void;
@@ -1,5 +1,5 @@
1
1
  //#region src/__internal/shared/matchRoute.d.ts
2
- declare function matchRoute(urlPathname: string, routes: typeof import('virtual:routes').routes): {
2
+ declare function matchRoute(urlPathname: string, routes: typeof import('virtual:vike-lite/routes').routes): {
3
3
  route: any;
4
4
  routeParams: Record<string, string>;
5
5
  } | null;
@@ -40,7 +40,7 @@ function computeAssets(route, nonce) {
40
40
  if (!isProd) return {
41
41
  cssLinks: "",
42
42
  jsPreloads: "",
43
- entryClient: withBase("@id/virtual:entry-client")
43
+ entryClient: withBase("@id/virtual:vike-lite/entry-client")
44
44
  };
45
45
  const cssFiles = /* @__PURE__ */ new Set();
46
46
  const jsFiles = /* @__PURE__ */ new Map();
@@ -122,7 +122,6 @@ async function renderErrorPage(req, status, urlPathname, error, nonce) {
122
122
  } else is500 = false;
123
123
  if (!store.errorRoute) return new Response(status === 404 ? "Not Found" : "Internal Server Error", { status });
124
124
  try {
125
- const { default: onRenderHtml } = await store.config.onRenderHtml();
126
125
  const [PageModule, HeadModule, LayoutModule] = await Promise.all([
127
126
  store.errorRoute.Page(),
128
127
  store.errorRoute.Head?.() ?? null,
@@ -136,7 +135,7 @@ async function renderErrorPage(req, status, urlPathname, error, nonce) {
136
135
  is500,
137
136
  errorMessage
138
137
  };
139
- const html = await onRenderHtml({
138
+ const html = await store.config.onRenderHtml({
140
139
  pageContext,
141
140
  Page: PageModule.Page ?? PageModule.default,
142
141
  Layout: LayoutModule ? LayoutModule.Layout ?? LayoutModule.default : void 0,
@@ -177,8 +176,7 @@ async function renderPage(req, { nonce } = {}) {
177
176
  }
178
177
  const { pageContext, route, PageModule, HeadModule, LayoutModule } = resolved;
179
178
  if (isJsonRequest) return Response.json(pageContext);
180
- const { default: onRenderHtml } = await store.config.onRenderHtml();
181
- const html = await onRenderHtml({
179
+ const html = await store.config.onRenderHtml({
182
180
  pageContext,
183
181
  Page: PageModule.Page ?? PageModule.default,
184
182
  Head: HeadModule ? HeadModule.Head ?? HeadModule.default : void 0,
package/dist/server.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { t as renderPage } from "./server-Cm1ZA_Dp.mjs";
1
+ import { t as renderPage } from "./server-BFTxx6MH.mjs";
2
2
  export { renderPage };
package/dist/vite.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Plugin } from "vite";
2
- //#region src/vite-plugin.d.ts
2
+ //#region src/vite/index.d.ts
3
3
  declare function routerPlugin({ pagesDir, serverEntry, apiPrefix, prerender }?: {
4
4
  /**
5
5
  * The directory where your page components are located.
package/dist/vite.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as renderPage } from "./server-Cm1ZA_Dp.mjs";
1
+ import { t as renderPage } from "./server-BFTxx6MH.mjs";
2
2
  import fs from "node:fs";
3
3
  import path from "node:path";
4
4
  import { Readable } from "node:stream";
@@ -98,20 +98,21 @@ async function injectFOUCStyles(server, html) {
98
98
  //#region src/config.ts
99
99
  const SUPPORTED_RENDERERS = ["solid"];
100
100
  //#endregion
101
- //#region src/vite-plugin.ts
101
+ //#region src/vite/index.ts
102
102
  function routerPlugin({ pagesDir = "pages", serverEntry = "server/index", apiPrefix = "/api", prerender = false } = {}) {
103
103
  const isProd = process.env.NODE_ENV === "production";
104
104
  let viteConfigRoot;
105
105
  let outDir;
106
106
  let hasAnyPrerender;
107
107
  const VIRTUAL = {
108
- routes: "virtual:routes",
109
- manifest: "virtual:client-manifest",
110
- renderer: "virtual:vike-lite/renderer",
111
- entryClient: "virtual:entry-client",
108
+ routes: "virtual:vike-lite/routes",
109
+ manifest: "virtual:vike-lite/client-manifest",
110
+ client: "virtual:vike-lite/client",
111
+ server: "virtual:vike-lite/server",
112
112
  setup: "virtual:vike-lite/setup",
113
- entryServer: "virtual:entry-server",
114
- entryPrerender: "virtual:entry-prerender"
113
+ entryClient: "virtual:vike-lite/entry-client",
114
+ entryServer: "virtual:vike-lite/entry-server",
115
+ entryPrerender: "virtual:vike-lite/entry-prerender"
115
116
  };
116
117
  const VIRTUAL_VALUES = new Set(Object.values(VIRTUAL));
117
118
  const RESOLVED = Object.fromEntries(Object.entries(VIRTUAL).map(([k, v]) => [k, `\0${v}`]));
@@ -216,7 +217,7 @@ function routerPlugin({ pagesDir = "pages", serverEntry = "server/index", apiPre
216
217
  if (id === RESOLVED.routes) {
217
218
  const { routes, errorRoute } = generateRoutes(viteConfigRoot, pagesDir);
218
219
  const isSSR = options.ssr;
219
- let code = `import { onRenderHtml } from '${VIRTUAL.renderer}';\nexport const config = { onRenderHtml };\nexport const routes = [\n`;
220
+ let code = `import{onRenderHtml}from'${VIRTUAL.server}';export const config={onRenderHtml};export const routes=[`;
220
221
  for (const r of routes) {
221
222
  code += `{path:'${r.path}',page:'${r.page}',Page:()=>import('/${r.page}'),`;
222
223
  if (r.head) code += `head:'${r.head}',Head:()=>import('/${r.head}'),`;
@@ -231,23 +232,26 @@ function routerPlugin({ pagesDir = "pages", serverEntry = "server/index", apiPre
231
232
  }
232
233
  code += "},";
233
234
  }
234
- code += "];\n";
235
+ code += "];";
235
236
  if (errorRoute) {
236
237
  const e = errorRoute;
237
238
  code += `export const errorRoute={path:'${e.path}',page:'${e.page}',Page:()=>import('/${e.page}'),`;
238
239
  if (e.layout) code += `layout:'${e.layout}',Layout:()=>import('/${e.layout}'),`;
239
240
  if (e.head) code += `head:'${e.head}',Head:()=>import('/${e.head}'),`;
240
- code += "};\n";
241
- } else code += "export const errorRoute=null;\n";
241
+ code += "};";
242
+ } else code += "export const errorRoute=null;";
242
243
  return code;
243
244
  }
244
245
  if (id === RESOLVED.manifest) {
245
- if (!isProd || !options?.ssr) return "export default {}";
246
+ if (!isProd || !options?.ssr) return "export default{}";
246
247
  const manifestPath = path.join(viteConfigRoot, outDir, "client/.vite/manifest.json");
247
248
  return `export default ${fs.readFileSync(manifestPath, "utf8")}`;
248
249
  }
249
- 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});`;
250
- 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.entryClient) return `import{routes,errorRoute}from'${VIRTUAL.routes}';import{onRenderClient}from'${VIRTUAL.client}';await(await onRenderClient()).default({routes,errorRoute});`;
251
+ if (id === RESOLVED.setup) {
252
+ const manifestContent = isProd ? `(await import('${VIRTUAL.manifest}')).default` : "null";
253
+ return `import{routes,errorRoute,config}from'${VIRTUAL.routes}';import{setVikeState}from'vike-lite/__internal/server';const manifest=${manifestContent};setVikeState({routes,errorRoute,config,manifest});`;
254
+ }
251
255
  if (id === RESOLVED.entryServer) {
252
256
  if (serverEntry) {
253
257
  const basePath = path.resolve(viteConfigRoot, serverEntry);
@@ -263,94 +267,8 @@ function routerPlugin({ pagesDir = "pages", serverEntry = "server/index", apiPre
263
267
  if (!serverEntryPath) throw new Error(`[vike-lite] serverEntry ${serverEntry} file not found`);
264
268
  return `import '${VIRTUAL.setup}';export * from'${serverEntryPath}';export{default}from'${serverEntryPath}';`;
265
269
  }
266
- return `import '${VIRTUAL.setup}';import{renderPage}from'vike-lite/server';
267
- export default{async fetch(request){return renderPage(request);}};
268
- if (process.env.NODE_ENV === 'production') {
269
- const { createServer } = await import('node:http');
270
- const { Readable } = await import('node:stream');
271
- const { pipeline } = await import('node:stream/promises');
272
- const fs = await import('node:fs');
273
- const path = await import('node:path');
274
- const { fileURLToPath } = await import('node:url');
275
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
276
- const clientDir = path.resolve(__dirname, '../client');
277
- const MIME_TYPES = {
278
- '.html': 'text/html; charset=utf-8',
279
- '.js': 'text/javascript; charset=utf-8',
280
- '.mjs': 'text/javascript; charset=utf-8',
281
- '.css': 'text/css; charset=utf-8',
282
- '.json': 'application/json; charset=utf-8',
283
- '.xml': 'application/xml',
284
- '.txt': 'text/plain; charset=utf-8',
285
- '.map': 'application/json; charset=utf-8',
286
- '.png': 'image/png',
287
- '.jpg': 'image/jpeg',
288
- '.jpeg': 'image/jpeg',
289
- '.gif': 'image/gif',
290
- '.svg': 'image/svg+xml',
291
- '.ico': 'image/x-icon',
292
- '.webp': 'image/webp',
293
- '.avif': 'image/avif',
294
- '.woff': 'font/woff',
295
- '.woff2': 'font/woff2',
296
- '.ttf': 'font/ttf',
297
- '.otf': 'font/otf',
298
- '.mp4': 'video/mp4',
299
- '.webm': 'video/webm',
300
- '.mp3': 'audio/mpeg',
301
- '.pdf': 'application/pdf',
302
- '.wasm': 'application/wasm',
303
- '.webmanifest': 'application/manifest+json'
304
- };
305
- const { BASE_URL } = import.meta.env;
306
- const server = createServer(async (req, res) => {
307
- try {
308
- const urlObj = new URL(req.url || '/', 'http://' + (req.headers.host || 'localhost'));
309
- const pathname = urlObj.pathname;
310
- let fileUrl = pathname;
311
- if (BASE_URL !== '/' && pathname.startsWith(BASE_URL)) fileUrl = '/' + pathname.slice(BASE_URL.length);
312
- if (fileUrl !== '/') {
313
- const filePath = path.resolve(clientDir, '.' + fileUrl)
314
- if (!filePath.startsWith(clientDir + path.sep)) {
315
- res.statusCode = 403
316
- res.end('Forbidden')
317
- return
318
- }
319
- if (filePath.startsWith(clientDir) && fs.existsSync(filePath) && fs.statSync(filePath).isFile()) {
320
- const ext = path.extname(filePath).toLowerCase();
321
- const mimeType = MIME_TYPES[ext] || 'application/octet-stream';
322
- res.setHeader('Content-Type', mimeType);
323
- res.setHeader('Cache-Control', fileUrl.startsWith('/assets/') ? 'public, max-age=31536000, immutable' : 'public, max-age=0, must-revalidate')
324
- fs.createReadStream(filePath).pipe(res);
325
- return;
326
- }
327
- }
328
- const headers = new Headers();
329
- for (const [key, val] of Object.entries(req.headers)) {
330
- if (Array.isArray(val)) val.forEach(v => headers.append(key, v));
331
- else if (val) headers.set(key, val);
332
- }
333
- const { method } = req;
334
- const init = { method, headers };
335
- if (method !== 'GET' && method !== 'HEAD') { init.body = Readable.toWeb(req); init.duplex = 'half'; }
336
- const request = new Request(urlObj.href, init);
337
- const response = await renderPage(request);
338
- res.statusCode = response.status;
339
- for (const [key, val] of response.headers) res.setHeader(key, val);
340
- if (method === 'HEAD' || !response.body) { await response.body?.cancel(); res.end(); return; }
341
- try { await pipeline(Readable.fromWeb(response.body), res); } catch {}
342
- } catch (e) {
343
- console.error(e);
344
- res.statusCode = 500;
345
- res.end('Internal Server Error');
346
- }
347
- });
348
- const { PORT } = process.env;
349
- const port = PORT ? Number.parseInt(PORT) : 3000;
350
- server.listen(port, () => {
351
- console.log('\n\u{1B}[32m🚀 Server is running at http://localhost:' + port + '\u{1B}[0m\n');
352
- });
353
- }`;
270
+ const defaultServerEntryContent = isProd ? fs.readFileSync(path.resolve(viteConfigRoot, "defaultServerEntry.mjs"), "utf8") : `import{renderPage}from'vike-lite/server'\n`;
271
+ return `import'${VIRTUAL.setup}'\n` + defaultServerEntryContent + "export default{fetch:renderPage}\n";
354
272
  }
355
273
  if (id === RESOLVED.entryPrerender) return `import'${VIRTUAL.setup}';export{routes}from'${VIRTUAL.routes}';`;
356
274
  },
@@ -405,7 +323,7 @@ if (process.env.NODE_ENV === 'production') {
405
323
  fs.mkdirSync(path.dirname(jsonOutPath), { recursive: true });
406
324
  fs.writeFileSync(jsonOutPath, await jsonRes.text());
407
325
  } else throw new Error(`[vike-lite] ❌ SSG JSON Error for "${jsonTarget}"`);
408
- console.log(` └─ ${urlPath}`);
326
+ console.log(` ${urlPath}`);
409
327
  generatedCount++;
410
328
  }
411
329
  console.log(`[vike-lite] ✨ SSG Completed! Generated ${generatedCount} static routes`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike-lite",
3
- "version": "1.13.1",
3
+ "version": "1.13.3",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "./dist/index.mjs",
@@ -51,7 +51,7 @@
51
51
  },
52
52
  "devDependencies": {
53
53
  "@types/node": "^26.1.1",
54
- "tsdown": "^0.22.5",
54
+ "tsdown": "^0.22.7",
55
55
  "vite": "^8.1.4"
56
56
  },
57
57
  "peerDependencies": {