vike-lite 1.0.16 → 1.0.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/vite.mjs +15 -19
- package/package.json +1 -1
package/dist/vite.mjs
CHANGED
|
@@ -54,21 +54,23 @@ function generateRoutes(pagesAbsPath) {
|
|
|
54
54
|
errorRoute
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
|
+
const cssCache = /* @__PURE__ */ new Map();
|
|
57
58
|
/**
|
|
58
59
|
* Anti-FOUC: Inspect all known SSR modules, ask the client environment
|
|
59
60
|
* to translate them into plain text (thanks to ?direct) and return them.
|
|
60
61
|
*/
|
|
61
62
|
async function injectFOUCStyles(server, html) {
|
|
62
|
-
const styles = /* @__PURE__ */ new Set();
|
|
63
63
|
const ssrEnv = server.environments.ssr;
|
|
64
64
|
const clientEnv = server.environments.client;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
try {
|
|
69
|
-
const
|
|
70
|
-
|
|
65
|
+
const styles = /* @__PURE__ */ new Set();
|
|
66
|
+
for (const mod of ssrEnv.moduleGraph.idToModuleMap.values()) if (mod.file && /\.(css|scss|sass|less|styl|stylus)($|\?)/.test(mod.file)) {
|
|
67
|
+
let css = cssCache.get(mod.file);
|
|
68
|
+
if (!css) try {
|
|
69
|
+
const url = mod.url.split("?", 1)[0] + "?direct";
|
|
70
|
+
css = (await clientEnv.transformRequest(url))?.code ?? "";
|
|
71
|
+
cssCache.set(mod.file, css);
|
|
71
72
|
} catch {}
|
|
73
|
+
if (css) styles.add(css);
|
|
72
74
|
}
|
|
73
75
|
if (styles.size === 0) return html;
|
|
74
76
|
const headEndIndex = html.lastIndexOf("</head>");
|
|
@@ -192,24 +194,15 @@ function routerPlugin({ pagesDir = "pages", serverEntry = "server/index.ts", api
|
|
|
192
194
|
if (id === resolvedVirtualEntryServerId) {
|
|
193
195
|
const normalizedServerEntry = path.join(viteConfigRoot, serverEntry).replaceAll("\\", "/");
|
|
194
196
|
return `import '${virtualSetupId}';
|
|
195
|
-
|
|
196
|
-
|
|
197
|
+
export * from '${normalizedServerEntry}';
|
|
198
|
+
export { default } from '${normalizedServerEntry}';`;
|
|
197
199
|
}
|
|
198
200
|
},
|
|
199
201
|
configureServer(server) {
|
|
200
202
|
return () => {
|
|
201
203
|
server.middlewares.use(async (req, res, next) => {
|
|
202
204
|
try {
|
|
203
|
-
const
|
|
204
|
-
const { routes, errorRoute, config } = await ssrEnv.runner.import(virtualModuleId);
|
|
205
|
-
const { setVikeState } = await ssrEnv.runner.import("vike-lite/__internal/server");
|
|
206
|
-
setVikeState({
|
|
207
|
-
routes,
|
|
208
|
-
errorRoute,
|
|
209
|
-
config
|
|
210
|
-
});
|
|
211
|
-
const absoluteServerEntry = path.join(viteConfigRoot, serverEntry);
|
|
212
|
-
const { default: app } = await ssrEnv.runner.import(absoluteServerEntry);
|
|
205
|
+
const { default: app } = await server.environments.ssr.runner.import(resolvedVirtualEntryServerId);
|
|
213
206
|
const headers = new Headers();
|
|
214
207
|
for (const [key, value] of Object.entries(req.headers)) {
|
|
215
208
|
if (key.startsWith(":")) continue;
|
|
@@ -250,6 +243,9 @@ function routerPlugin({ pagesDir = "pages", serverEntry = "server/index.ts", api
|
|
|
250
243
|
}
|
|
251
244
|
});
|
|
252
245
|
};
|
|
246
|
+
},
|
|
247
|
+
handleHotUpdate(ctx) {
|
|
248
|
+
if (/\.(css|scss|sass|less|styl|stylus)$/.test(ctx.file)) cssCache.delete(ctx.file);
|
|
253
249
|
}
|
|
254
250
|
};
|
|
255
251
|
}
|