vike-lite 1.17.2 ā 1.17.3
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 +48 -3
- package/package.json +1 -1
package/dist/vite.mjs
CHANGED
|
@@ -143,6 +143,8 @@ 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();
|
|
146
148
|
const VIRTUAL = {
|
|
147
149
|
routes: "virtual:vike-lite/routes",
|
|
148
150
|
manifest: "virtual:vike-lite/client-manifest",
|
|
@@ -352,19 +354,62 @@ function vikeLite({ pagesDir = "pages", apiPrefix = "/api", prerender = false, s
|
|
|
352
354
|
if (chunk.type !== "chunk") continue;
|
|
353
355
|
for (const id of chunk.moduleIds) {
|
|
354
356
|
const pkg = extractPkgName(id);
|
|
355
|
-
if (pkg && !pkg.startsWith("vike-lite") && Object.hasOwn(projectDependencies, pkg))
|
|
357
|
+
if (pkg && !pkg.startsWith("vike-lite") && Object.hasOwn(projectDependencies, pkg)) {
|
|
358
|
+
const entry = usedDeps.get(pkg) ?? {
|
|
359
|
+
...projectDependencies[pkg],
|
|
360
|
+
isBundled: false,
|
|
361
|
+
isExternal: false
|
|
362
|
+
};
|
|
363
|
+
entry.isBundled = true;
|
|
364
|
+
usedDeps.set(pkg, entry);
|
|
365
|
+
}
|
|
356
366
|
}
|
|
357
367
|
for (const imp of [...chunk.imports, ...chunk.dynamicImports]) {
|
|
368
|
+
if (bundle[imp]) continue;
|
|
358
369
|
const pkg = extractPkgName(imp);
|
|
359
|
-
if (pkg && !pkg.startsWith("vike-lite") && Object.hasOwn(projectDependencies, pkg))
|
|
370
|
+
if (pkg && !pkg.startsWith("vike-lite") && Object.hasOwn(projectDependencies, pkg)) {
|
|
371
|
+
const entry = usedDeps.get(pkg) ?? {
|
|
372
|
+
...projectDependencies[pkg],
|
|
373
|
+
isBundled: false,
|
|
374
|
+
isExternal: false
|
|
375
|
+
};
|
|
376
|
+
entry.isExternal = true;
|
|
377
|
+
usedDeps.set(pkg, entry);
|
|
378
|
+
}
|
|
360
379
|
}
|
|
361
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);
|
|
362
395
|
const sorted = [...usedDeps.entries()].sort(([a], [b]) => a.localeCompare(b));
|
|
363
396
|
console.log(`\nš¦ [${envName === "client" ? "Client" : "Server"} bundle] ${sorted.length} dependencies used from package.json:`);
|
|
364
397
|
if (sorted.length === 0) console.log(" (None)");
|
|
365
398
|
else for (const [name, info] of sorted) {
|
|
366
399
|
const typeTag = info.type ? ` \u{1B}[33m[${info.type}]\u{1B}[0m` : "";
|
|
367
|
-
|
|
400
|
+
const usageTag = info.isExternal ? " \x1B[90m(external)\x1B[0m" : " \x1B[90m(bundled)\x1B[0m";
|
|
401
|
+
console.log(` - \u{1B}[36m${name}@${info.version}\u{1B}[0m${typeTag}${usageTag}`);
|
|
402
|
+
}
|
|
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
|
+
}
|
|
368
413
|
}
|
|
369
414
|
},
|
|
370
415
|
closeBundle: {
|