vike-lite 1.17.3 → 1.18.0

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 (3) hide show
  1. package/README.md +20 -6
  2. package/dist/vite.mjs +16 -29
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -39,18 +39,32 @@ export default {
39
39
 
40
40
  #### printDependencies
41
41
 
42
- When set to `true`, at the end of each production build (client and server) the plugin prints the list of `package.json` dependencies (and devDependencies) that were actually bundled or externally imported in that specific build output. This is useful to debug bundle composition/size — e.g. spotting a heavy dependency that unexpectedly ended up in the client bundle.
42
+ When set to `true`, at the end of each production build (client and server), the plugin prints the list of `package.json` dependencies (and devDependencies) that were actually bundled or externally imported in that specific build output.
43
43
 
44
- ```sh
44
+ More importantly, it cross-references this usage with your `package.json` to provide **smart suggestions** to prevent production crashes and optimize your deployment size.
45
45
 
46
+ ```sh
46
47
  šŸ“¦ [Client bundle] 1 dependencies used from package.json:
47
- - solid-js@^1.9.3
48
+ - solid-js@^1.9.3 (bundled)
49
+
50
+ šŸ“¦ [Server bundle] 3 dependencies used from package.json:
51
+ - solid-js@^1.9.3 (bundled)
52
+ - hono@^4.12.31 (external)
53
+ - postgres@^3.4.4 [dev] (external)
48
54
 
49
- šŸ“¦ [Server bundle] 2 dependencies used from package.json:
50
- - solid-js@^1.9.3
51
- - hono@^4.12.31
55
+ Suggestions:
56
+ 🚨 postgres is externalized in the server bundle but listed as a devDependency. Move it to dependencies or it will break in production.
57
+ šŸ’” solid-js is always fully bundled (never externalized). Consider moving it to devDependencies to reduce production node_modules size.
58
+ šŸ—‘ļø lodash@4.17.21 is listed in "dependencies" but wasn't found in any bundle — if it's only needed at build/dev time, move it to devDependencies (or remove it if unused).
52
59
  ```
53
60
 
61
+ ##### What it catches:
62
+ - 🚨 **Production Crashes:** Flags devDependencies that are externalized by the server (if left as dev dependencies, your app will crash in production environments that use `npm ci --omit=dev`).
63
+ - šŸ’” **Server Bloat:** Flags regular dependencies that are 100% bundled into the build. Moving these to `devDependencies` shrinks your production node_modules size.
64
+ - šŸ—‘ļø **Unused Packages**: Highlights dependencies taking up space in your `package.json` that never appeared in the final build graph.
65
+
66
+ It's disabled by default since it adds diagnostic console output and isn't needed for normal usage, but it is highly recommended to run occasionally to audit your packages.
67
+
54
68
  It's disabled by default since it only adds diagnostic console output and isn't needed for normal usage.
55
69
 
56
70
  ### šŸ–„ļø Server Integration
package/dist/vite.mjs CHANGED
@@ -143,8 +143,6 @@ function vikeLite({ pagesDir = "pages", apiPrefix = "/api", prerender = false, s
143
143
  let hasAnyPrerender;
144
144
  let baseUrl;
145
145
  let projectDependencies = null;
146
- const depUsage = /* @__PURE__ */ new Map();
147
- const processedEnvs = /* @__PURE__ */ new Set();
148
146
  const VIRTUAL = {
149
147
  routes: "virtual:vike-lite/routes",
150
148
  manifest: "virtual:vike-lite/client-manifest",
@@ -196,6 +194,10 @@ function vikeLite({ pagesDir = "pages", apiPrefix = "/api", prerender = false, s
196
194
  const pagesDirTest = new RegExp(String.raw`[\\/]${escapedPagesDir}[\\/]`);
197
195
  return {
198
196
  appType: "custom",
197
+ builder: { async buildApp(builder) {
198
+ await builder.build(builder.environments.client);
199
+ await builder.build(builder.environments.ssr);
200
+ } },
199
201
  ssr: { noExternal: [/^vike-lite(?:$|-)/] },
200
202
  environments: {
201
203
  client: { build: {
@@ -347,8 +349,6 @@ function vikeLite({ pagesDir = "pages", apiPrefix = "/api", prerender = false, s
347
349
  },
348
350
  generateBundle(_options, bundle) {
349
351
  if (!printDependencies || !projectDependencies) return;
350
- const envName = this.environment.name;
351
- if (envName !== "client" && envName !== "ssr") return;
352
352
  const usedDeps = /* @__PURE__ */ new Map();
353
353
  for (const chunk of Object.values(bundle)) {
354
354
  if (chunk.type !== "chunk") continue;
@@ -378,38 +378,25 @@ function vikeLite({ pagesDir = "pages", apiPrefix = "/api", prerender = false, s
378
378
  }
379
379
  }
380
380
  }
381
- for (const [name, info] of usedDeps) {
382
- const global = depUsage.get(name) ?? {
383
- version: info.version,
384
- type: info.type,
385
- isBundled: false,
386
- isExternal: false,
387
- externalEnvs: /* @__PURE__ */ new Set()
388
- };
389
- global.isBundled ||= info.isBundled;
390
- global.isExternal ||= info.isExternal;
391
- if (info.isExternal) global.externalEnvs.add(envName);
392
- depUsage.set(name, global);
393
- }
394
- processedEnvs.add(envName);
395
381
  const sorted = [...usedDeps.entries()].sort(([a], [b]) => a.localeCompare(b));
396
- console.log(`\nšŸ“¦ [${envName === "client" ? "Client" : "Server"} bundle] ${sorted.length} dependencies used from package.json:`);
382
+ const envName = this.environment.name;
383
+ const label = envName === "client" ? "Client" : "Server";
384
+ console.log(`\nšŸ“¦ [${label} bundle] ${sorted.length} dependencies used from package.json:`);
397
385
  if (sorted.length === 0) console.log(" (None)");
398
386
  else for (const [name, info] of sorted) {
399
387
  const typeTag = info.type ? ` \u{1B}[33m[${info.type}]\u{1B}[0m` : "";
400
388
  const usageTag = info.isExternal ? " \x1B[90m(external)\x1B[0m" : " \x1B[90m(bundled)\x1B[0m";
401
389
  console.log(` - \u{1B}[36m${name}@${info.version}\u{1B}[0m${typeTag}${usageTag}`);
402
390
  }
403
- if (processedEnvs.has("client") && processedEnvs.has("ssr")) {
404
- const suggestions = [];
405
- for (const [name, info] of [...depUsage.entries()].sort(([a], [b]) => a.localeCompare(b))) if (info.externalEnvs.has("ssr") && info.type === "dev") suggestions.push(`\u{1B}[31m🚨 ${name}\u{1B}[0m is externalized in the server bundle but listed as a \u{1B}[33mdevDependency\u{1B}[0m. Move it to \u{1B}[32mdependencies\u{1B}[0m or it will break in production.`);
406
- else if (info.type === "" && info.isBundled && !info.isExternal) suggestions.push(`\u{1B}[34mšŸ’” ${name}\u{1B}[0m is always fully bundled (never externalized). Consider moving it to \u{1B}[33mdevDependencies\u{1B}[0m to reduce production node_modules size.`);
407
- const unusedRegularDeps = Object.entries(projectDependencies).filter(([name, info]) => info.type === "" && !depUsage.has(name)).sort(([a], [b]) => a.localeCompare(b));
408
- for (const [name, info] of unusedRegularDeps) suggestions.push(`\u{1B}[90mšŸ—‘ļø ${name}@${info.version}\u{1B}[0m is listed in "dependencies" but wasn't found in any bundle — if it's only needed at build/dev time, move it to devDependencies (or remove it if unused).`);
409
- if (suggestions.length > 0) {
410
- console.log("\n \x1B[1mSuggestions:\x1B[0m");
411
- for (const s of suggestions) console.log(` ${s}`);
412
- }
391
+ const suggestions = [];
392
+ for (const [name, info] of sorted) if (envName === "ssr" && info.isExternal && info.type === "dev") suggestions.push(`\u{1B}[31m🚨 ${name}\u{1B}[0m is externalized by the server but listed as a \u{1B}[33mdevDependency\u{1B}[0m. Move it to \u{1B}[32mdependencies\u{1B}[0m to prevent production crashes.`);
393
+ else if (info.isBundled && !info.isExternal && info.type === "") {
394
+ const otherEnv = envName === "client" ? "server" : "client";
395
+ suggestions.push(`\u{1B}[34mšŸ’” ${name}\u{1B}[0m is fully bundled here. If it's also bundled (or unused) in the ${otherEnv}, consider moving it to \u{1B}[33mdevDependencies\u{1B}[0m.`);
396
+ }
397
+ if (suggestions.length > 0) {
398
+ console.log(`\n \u{1B}[1m${label} Suggestions:\u{1B}[0m`);
399
+ for (const s of suggestions) console.log(` ${s}`);
413
400
  }
414
401
  },
415
402
  closeBundle: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike-lite",
3
- "version": "1.17.3",
3
+ "version": "1.18.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",