vike-lite 1.0.2 → 1.0.4
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/server.mjs +1 -1
- package/dist/vite.mjs +32 -34
- package/package.json +1 -1
- package/dist/virtuals-CR__ZAgP.mjs +0 -8
package/dist/server.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { n as virtualEntryClientId } from "./virtuals-CR__ZAgP.mjs";
|
|
2
1
|
import { t as matchRoute } from "./matchRoute-BONrLRYy.mjs";
|
|
3
2
|
//#region src/server/store.ts
|
|
4
3
|
const store = {
|
|
@@ -24,6 +23,7 @@ var AbortRender = class extends Error {
|
|
|
24
23
|
//#endregion
|
|
25
24
|
//#region src/server/renderPage.tsx
|
|
26
25
|
const isProd = process.env.NODE_ENV === "production";
|
|
26
|
+
const virtualEntryClientId = "virtual:entry-client";
|
|
27
27
|
const ESCAPE_LOOKUP = {
|
|
28
28
|
"&": String.raw`\u0026`,
|
|
29
29
|
">": String.raw`\u003e`,
|
package/dist/vite.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { a as virtualSetupId, i as virtualModuleId, n as virtualEntryClientId, r as virtualManifestId, t as virtualAdapterId } from "./virtuals-CR__ZAgP.mjs";
|
|
2
1
|
import fs from "node:fs";
|
|
3
2
|
import path from "node:path";
|
|
4
3
|
import { Readable } from "node:stream";
|
|
@@ -82,10 +81,15 @@ async function injectFOUCStyles(server, html) {
|
|
|
82
81
|
function routerPlugin({ pagesDir = "pages", serverEntry = "server/index.ts", apiPrefix = "/api" } = {}) {
|
|
83
82
|
const isProd = process.env.NODE_ENV === "production";
|
|
84
83
|
let viteConfigRoot;
|
|
85
|
-
const
|
|
86
|
-
const
|
|
87
|
-
const
|
|
88
|
-
const
|
|
84
|
+
const virtualModuleId = "virtual:routes";
|
|
85
|
+
const virtualManifestId = "virtual:client-manifest";
|
|
86
|
+
const virtualAdapterId = "virtual:vike-lite-adapter";
|
|
87
|
+
const virtualEntryClientId = "virtual:entry-client";
|
|
88
|
+
const virtualSetupId = "virtual:vike-lite/setup";
|
|
89
|
+
const resolvedVirtualModuleId = "\0virtual:routes";
|
|
90
|
+
const resolvedVirtualManifestId = "\0virtual:client-manifest";
|
|
91
|
+
const resolvedVirtualEntryClientId = "\0virtual:entry-client";
|
|
92
|
+
const resolvedVirtualSetupId = "\0virtual:vike-lite/setup";
|
|
89
93
|
return {
|
|
90
94
|
name: "vike-lite",
|
|
91
95
|
config() {
|
|
@@ -133,16 +137,16 @@ function routerPlugin({ pagesDir = "pages", serverEntry = "server/index.ts", api
|
|
|
133
137
|
viteConfigRoot = config.root;
|
|
134
138
|
},
|
|
135
139
|
resolveId(id) {
|
|
136
|
-
if (id ===
|
|
137
|
-
if (id ===
|
|
138
|
-
if (id ===
|
|
139
|
-
if (id ===
|
|
140
|
+
if (id === virtualModuleId) return resolvedVirtualModuleId;
|
|
141
|
+
if (id === virtualManifestId) return resolvedVirtualManifestId;
|
|
142
|
+
if (id === virtualEntryClientId) return resolvedVirtualEntryClientId;
|
|
143
|
+
if (id === virtualSetupId) return resolvedVirtualSetupId;
|
|
140
144
|
},
|
|
141
145
|
async load(id, options) {
|
|
142
146
|
if (id === resolvedVirtualModuleId) {
|
|
143
147
|
const { routes, errorRoute } = generateRoutes(path.resolve(viteConfigRoot, pagesDir));
|
|
144
148
|
const isSSR = options.ssr;
|
|
145
|
-
let code = `import {
|
|
149
|
+
let code = `import { onRenderHtml } from '${virtualAdapterId}';\nexport const config = { onRenderHtml };\nexport const routes = [\n`;
|
|
146
150
|
for (const r of routes) {
|
|
147
151
|
code += `{path:'${r.path}',page:'${r.page}',hasData:${r.hasData},hasTitle:${r.hasTitle},Page:()=>import('${r.page}'),`;
|
|
148
152
|
if (r.head) code += `Head:()=>import('${r.head}'),`;
|
|
@@ -153,43 +157,37 @@ function routerPlugin({ pagesDir = "pages", serverEntry = "server/index.ts", api
|
|
|
153
157
|
}
|
|
154
158
|
code += "},";
|
|
155
159
|
}
|
|
156
|
-
code += "]
|
|
160
|
+
code += "];\n";
|
|
157
161
|
if (errorRoute) {
|
|
158
162
|
const e = errorRoute;
|
|
159
163
|
code += `export const errorRoute={path:'${e.path}',page:'${e.page}',Page:()=>import('${e.page}'),`;
|
|
160
164
|
if (e.layout) code += `Layout:()=>import('${e.layout}'),`;
|
|
161
165
|
if (e.head) code += `Head:()=>import('${e.head}'),`;
|
|
162
|
-
code += "}
|
|
163
|
-
} else code += "export const errorRoute=null
|
|
166
|
+
code += "};\n";
|
|
167
|
+
} else code += "export const errorRoute=null;\n";
|
|
164
168
|
return code;
|
|
165
169
|
}
|
|
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
170
|
if (id === resolvedVirtualManifestId) {
|
|
173
171
|
if (!isProd || !options?.ssr) return "export default {}";
|
|
174
172
|
const manifestPath = path.join(viteConfigRoot, "../dist/client/.vite/manifest.json");
|
|
175
173
|
return `export default ${fs.readFileSync(manifestPath, "utf8")}`;
|
|
176
174
|
}
|
|
175
|
+
if (id === resolvedVirtualEntryClientId) return `
|
|
176
|
+
import { routes, errorRoute } from '${virtualModuleId}';
|
|
177
|
+
import { onRenderClient } from '${virtualAdapterId}';
|
|
178
|
+
onRenderClient().then((module) => { module.default({ routes, errorRoute })});
|
|
179
|
+
`;
|
|
177
180
|
if (id === resolvedVirtualSetupId) return `
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
// 4. INIETTA lo stato in memoria!
|
|
191
|
-
setVikeState({ routes, errorRoute, config, manifest });
|
|
192
|
-
`;
|
|
181
|
+
import { routes, errorRoute, config } from '${virtualModuleId}';
|
|
182
|
+
import { setVikeState } from 'vike-lite/store';
|
|
183
|
+
|
|
184
|
+
let manifest;
|
|
185
|
+
if (process.env.NODE_ENV === 'production') {
|
|
186
|
+
manifest = (await import('${virtualManifestId}')).default;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
setVikeState({ routes, errorRoute, config, manifest });
|
|
190
|
+
`;
|
|
193
191
|
},
|
|
194
192
|
configureServer(server) {
|
|
195
193
|
return () => {
|
package/package.json
CHANGED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
//#region src/virtuals.ts
|
|
2
|
-
const virtualModuleId = "virtual:routes";
|
|
3
|
-
const virtualManifestId = "virtual:client-manifest";
|
|
4
|
-
const virtualAdapterId = "virtual:vike-lite-adapter";
|
|
5
|
-
const virtualEntryClientId = "virtual:entry-client";
|
|
6
|
-
const virtualSetupId = "virtual:vike-lite/setup";
|
|
7
|
-
//#endregion
|
|
8
|
-
export { virtualSetupId as a, virtualModuleId as i, virtualEntryClientId as n, virtualManifestId as r, virtualAdapterId as t };
|