vike-lite 1.0.15 → 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.
Files changed (2) hide show
  1. package/dist/vite.mjs +15 -20
  2. 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
- for (const mod of ssrEnv.moduleGraph.idToModuleMap.values()) {
66
- if (!(mod.file && /\.(css|scss|sass|less|styl|stylus)($|\?)/.test(mod.file))) continue;
67
- const url = mod.url.split("?", 1)[0];
68
- try {
69
- const result = await clientEnv.transformRequest(url + "?direct");
70
- if (result?.code) styles.add(result.code);
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,25 +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
- export * from '${normalizedServerEntry}'
196
- export { default } from '${normalizedServerEntry}'`;
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 ssrEnv = server.environments.ssr;
204
- const { routes, errorRoute, config } = await ssrEnv.runner.import(virtualModuleId);
205
- const storePath = path.resolve("vike-lite/__internal/server");
206
- const { setVikeState } = await ssrEnv.runner.import(storePath);
207
- setVikeState({
208
- routes,
209
- errorRoute,
210
- config
211
- });
212
- const absoluteServerEntry = path.join(viteConfigRoot, serverEntry);
213
- const { default: app } = await ssrEnv.runner.import(absoluteServerEntry);
205
+ const { default: app } = await server.environments.ssr.runner.import(resolvedVirtualEntryServerId);
214
206
  const headers = new Headers();
215
207
  for (const [key, value] of Object.entries(req.headers)) {
216
208
  if (key.startsWith(":")) continue;
@@ -251,6 +243,9 @@ function routerPlugin({ pagesDir = "pages", serverEntry = "server/index.ts", api
251
243
  }
252
244
  });
253
245
  };
246
+ },
247
+ handleHotUpdate(ctx) {
248
+ if (/\.(css|scss|sass|less|styl|stylus)$/.test(ctx.file)) cssCache.delete(ctx.file);
254
249
  }
255
250
  };
256
251
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike-lite",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "./dist/index.mjs",