vike-lite 1.0.1 → 1.0.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.
package/dist/index.d.mts CHANGED
@@ -9,6 +9,16 @@ type PageContext<Data = unknown> = {
9
9
  is500?: boolean;
10
10
  errorMessage?: string;
11
11
  };
12
+ type DataAsync<Data = unknown> = (pageContext: PageContext) => Promise<Data>;
13
+ type DataSync<Data = unknown> = (pageContext: PageContext) => Data;
14
+ type Route = {
15
+ path: string;
16
+ page: string;
17
+ layout?: string;
18
+ head?: string;
19
+ hasData?: boolean;
20
+ hasTitle?: boolean;
21
+ };
12
22
  type Manifest = Record<string, {
13
23
  file: string;
14
24
  css?: string[];
@@ -50,4 +60,6 @@ declare module 'virtual:routes' {
50
60
  declare module 'virtual:client-manifest' {
51
61
  const manifest: Manifest;
52
62
  export default manifest;
53
- }
63
+ }
64
+ //#endregion
65
+ export { DataAsync, DataSync, PageContext, Route };
package/dist/server.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { n as virtualEntryClientId } from "./virtuals-CR__ZAgP.mjs";
1
+ import { t as virtualEntryClientId } from "./virtuals-CfLEPwEc.mjs";
2
2
  import { t as matchRoute } from "./matchRoute-BONrLRYy.mjs";
3
3
  //#region src/server/store.ts
4
4
  const store = {
@@ -1,8 +1,7 @@
1
1
  //#region src/virtuals.ts
2
2
  const virtualModuleId = "virtual:routes";
3
3
  const virtualManifestId = "virtual:client-manifest";
4
- const virtualAdapterId = "virtual:vike-lite-adapter";
5
4
  const virtualEntryClientId = "virtual:entry-client";
6
5
  const virtualSetupId = "virtual:vike-lite/setup";
7
6
  //#endregion
8
- export { virtualSetupId as a, virtualModuleId as i, virtualEntryClientId as n, virtualManifestId as r, virtualAdapterId as t };
7
+ export { virtualSetupId as i, virtualManifestId as n, virtualModuleId as r, virtualEntryClientId as t };
package/dist/vite.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as virtualSetupId, i as virtualModuleId, n as virtualEntryClientId, r as virtualManifestId, t as virtualAdapterId } from "./virtuals-CR__ZAgP.mjs";
1
+ import { i as virtualSetupId, n as virtualManifestId, r as virtualModuleId, t as virtualEntryClientId } from "./virtuals-CfLEPwEc.mjs";
2
2
  import fs from "node:fs";
3
3
  import path from "node:path";
4
4
  import { Readable } from "node:stream";
@@ -82,6 +82,8 @@ async function injectFOUCStyles(server, html) {
82
82
  function routerPlugin({ pagesDir = "pages", serverEntry = "server/index.ts", apiPrefix = "/api" } = {}) {
83
83
  const isProd = process.env.NODE_ENV === "production";
84
84
  let viteConfigRoot;
85
+ const virtualAdapterServerId = "virtual:vike-lite/adapter-server";
86
+ const virtualAdapterClientId = "virtual:vike-lite/adapter-client";
85
87
  const resolvedVirtualModuleId = "\0" + virtualModuleId;
86
88
  const resolvedVirtualManifestId = "\0" + virtualManifestId;
87
89
  const resolvedVirtualEntryClientId = "\0" + virtualEntryClientId;
@@ -142,7 +144,7 @@ function routerPlugin({ pagesDir = "pages", serverEntry = "server/index.ts", api
142
144
  if (id === resolvedVirtualModuleId) {
143
145
  const { routes, errorRoute } = generateRoutes(path.resolve(viteConfigRoot, pagesDir));
144
146
  const isSSR = options.ssr;
145
- let code = `import {onRenderClient,onRenderHtml} from '${virtualAdapterId}';export const config={onRenderClient,onRenderHtml};export const routes=[`;
147
+ let code = `import onRenderHtml from '${virtualAdapterServerId}';\nexport const config = { onRenderHtml };\nexport const routes = [\n`;
146
148
  for (const r of routes) {
147
149
  code += `{path:'${r.path}',page:'${r.page}',hasData:${r.hasData},hasTitle:${r.hasTitle},Page:()=>import('${r.page}'),`;
148
150
  if (r.head) code += `Head:()=>import('${r.head}'),`;
@@ -153,43 +155,38 @@ function routerPlugin({ pagesDir = "pages", serverEntry = "server/index.ts", api
153
155
  }
154
156
  code += "},";
155
157
  }
156
- code += "];";
158
+ code += "];\n";
157
159
  if (errorRoute) {
158
160
  const e = errorRoute;
159
161
  code += `export const errorRoute={path:'${e.path}',page:'${e.page}',Page:()=>import('${e.page}'),`;
160
162
  if (e.layout) code += `Layout:()=>import('${e.layout}'),`;
161
163
  if (e.head) code += `Head:()=>import('${e.head}'),`;
162
- code += "};";
163
- } else code += "export const errorRoute=null;";
164
+ code += "};\n";
165
+ } else code += "export const errorRoute=null;\n";
164
166
  return code;
165
167
  }
166
- if (id === resolvedVirtualManifestId) {
167
- if (!isProd || !options?.ssr) return "";
168
- const manifestPath = path.join(viteConfigRoot, "../dist/client/.vite/manifest.json");
169
- return `export default ${fs.readFileSync(manifestPath, "utf8")}`;
170
- }
171
- if (id === resolvedVirtualEntryClientId) return `import{onRenderClient}from'${virtualAdapterId}';onRenderClient();`;
172
168
  if (id === resolvedVirtualManifestId) {
173
169
  if (!isProd || !options?.ssr) return "export default {}";
174
170
  const manifestPath = path.join(viteConfigRoot, "../dist/client/.vite/manifest.json");
175
171
  return `export default ${fs.readFileSync(manifestPath, "utf8")}`;
176
172
  }
173
+ if (id === resolvedVirtualEntryClientId) return `
174
+ import { routes, errorRoute } from '${virtualModuleId}';
175
+ import onRenderClient from '${virtualAdapterClientId}';
176
+
177
+ onRenderClient({ routes, errorRoute });
178
+ `;
177
179
  if (id === resolvedVirtualSetupId) return `
178
- // 1. Importa i dati virtuali generati da Vite
179
- import { routes, errorRoute, config } from '${virtualModuleId}';
180
-
181
- // 2. Importa il setter dal TUO pacchetto compilato (assicurati di esportarlo nel package.json)
182
- import { setVikeState } from 'vike-lite/store';
183
-
184
- // 3. Risolve il manifest per la build di produzione
185
- let manifest;
186
- if (process.env.NODE_ENV === 'production') {
187
- manifest = (await import('${virtualManifestId}')).default;
188
- }
189
-
190
- // 4. INIETTA lo stato in memoria!
191
- setVikeState({ routes, errorRoute, config, manifest });
192
- `;
180
+ import { routes, errorRoute, config } from '${virtualModuleId}';
181
+ import { setVikeState } from 'vike-lite/store';
182
+
183
+ let manifest;
184
+ if (process.env.NODE_ENV === 'production') {
185
+ manifest = (await import('${virtualManifestId}')).default;
186
+ }
187
+
188
+ setVikeState({ routes, errorRoute, config, manifest });
189
+ `;
193
190
  },
194
191
  configureServer(server) {
195
192
  return () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike-lite",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "./dist/index.mjs",