Skip to content

Commit c30cf55

Browse files
manual chunks rework
1 parent bc237ca commit c30cf55

File tree

3 files changed

+84
-14
lines changed

3 files changed

+84
-14
lines changed

bun.lock

Lines changed: 35 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@
5959
"react-router-dom": "^7.12.0",
6060
"rehype-raw": "^7.0.0",
6161
"remark-gfm": "^4.0.1",
62+
"rollup-plugin-visualizer": "^6.0.5",
6263
"sonner": "^2.0.7",
6364
"tailwind-merge": "^3.4.0",
6465
"tailwindcss-animate": "^1.0.7",
65-
"uuid": "^13.0.0",
66-
"vite-bundle-analyzer": "^1.3.2"
66+
"uuid": "^13.0.0"
6767
},
6868
"devDependencies": {
6969
"@tailwindcss/postcss": "^4.1.18",

vite.config.ts

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,30 @@
11
import { sentryVitePlugin } from "@sentry/vite-plugin";
22
import react from "@vitejs/plugin-react";
33
import path from "path";
4+
import { visualizer } from "rollup-plugin-visualizer";
45
import { defineConfig, normalizePath } from "vite";
5-
import { analyzer } from "vite-bundle-analyzer";
66
import { viteStaticCopy } from "vite-plugin-static-copy";
77

88
const host = process.env.TAURI_DEV_HOST;
9-
const runBundleAnalyzer = process.env.BUNDLE_ANALYZER_DEBUG === "true";
9+
10+
const vendorManualChunks = {
11+
react: ["react", "react-dom", "react-dom/client"],
12+
reactRouter: ["react-router"],
13+
radixUi: [
14+
"@radix-ui/react-accordion",
15+
"@radix-ui/react-context-menu",
16+
"@radix-ui/react-dialog",
17+
"@radix-ui/react-dropdown-menu",
18+
"@radix-ui/react-label",
19+
"@radix-ui/react-popover",
20+
"@radix-ui/react-radio-group",
21+
"@radix-ui/react-scroll-area",
22+
"@radix-ui/react-separator",
23+
"@radix-ui/react-slot",
24+
"@radix-ui/react-tooltip",
25+
],
26+
miscUi: ["vaul", "tailwind-merge"],
27+
};
1028

1129
export default defineConfig(async () => ({
1230
plugins: [
@@ -31,11 +49,11 @@ export default defineConfig(async () => ({
3149
},
3250
],
3351
}),
34-
runBundleAnalyzer &&
35-
analyzer({
36-
openAnalyzer: false,
37-
fileName: "bundle-report.html",
38-
}),
52+
visualizer({
53+
open: false,
54+
emitFile: false,
55+
filename: "dist/stats.html",
56+
}),
3957
],
4058

4159
resolve: {
@@ -63,5 +81,27 @@ export default defineConfig(async () => ({
6381

6482
build: {
6583
sourcemap: true,
84+
rollupOptions: {
85+
output: {
86+
manualChunks(id: string) {
87+
// Normalize to POSIX-style paths so checks work on Windows too
88+
const normalizedId = id.replace(/\\/g, "/");
89+
90+
if (normalizedId.includes("/node_modules/")) {
91+
for (const [chunkName, packages] of Object.entries(
92+
vendorManualChunks,
93+
)) {
94+
if (
95+
packages.some((pkg) =>
96+
normalizedId.includes(`/node_modules/${pkg}/`),
97+
)
98+
) {
99+
return chunkName;
100+
}
101+
}
102+
}
103+
},
104+
},
105+
},
66106
},
67107
}));

0 commit comments

Comments
 (0)