vike-lite 1.8.1 → 1.8.2

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 CHANGED
@@ -27,30 +27,34 @@ function getAssets(route) {
27
27
  entryClient: withBase("@id/virtual:entry-client")
28
28
  };
29
29
  const cssFiles = /* @__PURE__ */ new Set();
30
- const jsFiles = /* @__PURE__ */ new Set();
31
- const visitedKeys = /* @__PURE__ */ new Set();
30
+ const jsFiles = /* @__PURE__ */ new Map();
32
31
  const { manifest } = store;
33
32
  function getVirtualEntryClientKey() {
34
33
  for (const key in manifest) if (manifest[key].isEntry) return key;
35
34
  throw new Error("entry-client not found in manifest");
36
35
  }
37
- function collectAssets(key) {
38
- if (visitedKeys.has(key)) return;
39
- visitedKeys.add(key);
36
+ function collectAssets(key, isCritical) {
40
37
  const chunk = manifest[key];
41
- jsFiles.add(chunk.file);
38
+ if (!chunk) return;
39
+ const current = jsFiles.get(chunk.file);
40
+ if (current === true) return;
41
+ if (current === false && !isCritical) return;
42
+ jsFiles.set(chunk.file, isCritical);
42
43
  if (chunk.css) for (const css of chunk.css) cssFiles.add(css);
43
- if (chunk.imports) for (const imp of chunk.imports) collectAssets(imp);
44
+ if (chunk.imports) for (const imp of chunk.imports) collectAssets(imp, false);
44
45
  }
45
46
  const virtualEntryClientKey = getVirtualEntryClientKey();
46
- collectAssets(virtualEntryClientKey);
47
+ collectAssets(virtualEntryClientKey, true);
47
48
  const { page, layout, head } = route;
48
- collectAssets(page);
49
- if (head) collectAssets(head);
50
- if (layout) collectAssets(layout);
49
+ collectAssets(page, true);
50
+ if (head) collectAssets(head, true);
51
+ if (layout) collectAssets(layout, true);
52
+ const criticalJs = [];
53
+ const sharedJs = [];
54
+ for (const [file, isCritical] of jsFiles) (isCritical ? criticalJs : sharedJs).push(file);
51
55
  return {
52
56
  cssLinks: [...cssFiles].map((href) => `<link rel="stylesheet" href="${withBase(href)}">`).join(""),
53
- jsPreloads: [...jsFiles].map((href) => `<link rel="modulepreload" href="${withBase(href)}">`).join(""),
57
+ jsPreloads: [...criticalJs.map((href) => `<link rel="modulepreload" href="${withBase(href)}" crossorigin fetchpriority="high">`), ...sharedJs.map((href) => `<link rel="modulepreload" href="${withBase(href)}" crossorigin>`)].join(""),
54
58
  entryClient: withBase(manifest[virtualEntryClientKey].file)
55
59
  };
56
60
  }
package/dist/vite.mjs CHANGED
@@ -135,12 +135,45 @@ function routerPlugin({ pagesDir = "pages", serverEntry = "server/index", apiPre
135
135
  input: virtualEntryClientId,
136
136
  output: {
137
137
  format: "esm",
138
+ hoistTransitiveImports: false,
138
139
  entryFileNames: "assets/[name].[hash].js",
139
140
  chunkFileNames: (chunkInfo) => {
140
141
  if (chunkInfo.facadeModuleId?.includes(`/${pagesDir}/`)) return "assets/pages/[name].[hash].js";
141
142
  return "assets/chunks/[name].[hash].js";
142
143
  },
143
- assetFileNames: "assets/static/[name].[hash][extname]"
144
+ assetFileNames: "assets/static/[name].[hash][extname]",
145
+ codeSplitting: { groups: [
146
+ {
147
+ name: "framework",
148
+ test: /[\\/]vike-lite(?:-\w+)?[\\/]|[\\/](?:solid-js|@solidjs)[\\/]|^\0virtual:vike-lite/,
149
+ priority: 30
150
+ },
151
+ {
152
+ name: "vendor",
153
+ test(moduleId) {
154
+ if (/[\\/](node_modules|\.yarn)[\\/]/.test(moduleId)) return true;
155
+ return !moduleId.startsWith("\0") && !moduleId.startsWith(viteConfigRoot);
156
+ },
157
+ priority: 20,
158
+ minSize: 2e4
159
+ },
160
+ {
161
+ name(moduleId) {
162
+ const match = moduleId.match(new RegExp(String.raw`[\\/]${pagesDir}[\\/]([^\\/]+)[\\/]`));
163
+ return match ? `page-${match[1]}` : "shared";
164
+ },
165
+ test: new RegExp(String.raw`[\\/]${pagesDir}[\\/]`),
166
+ priority: 10
167
+ },
168
+ {
169
+ name(moduleId) {
170
+ const match = moduleId.match(new RegExp(String.raw`[\\/]${pagesDir}[\\/]([^\\/]+)[\\/]`));
171
+ return match ? `css-${match[1]}` : "css-shared";
172
+ },
173
+ test: /\.css$/,
174
+ priority: 5
175
+ }
176
+ ] }
144
177
  }
145
178
  }
146
179
  } },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike-lite",
3
- "version": "1.8.1",
3
+ "version": "1.8.2",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "./dist/index.mjs",