Skip to content

Commit 0814088

Browse files
committed
chore: refactor Vite configuration for chunking dependencies and improve manual chunking logic
1 parent aeea32c commit 0814088

1 file changed

Lines changed: 22 additions & 6 deletions

File tree

vite.config.mjs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import react from "@vitejs/plugin-react";
33
import { defineConfig } from "vite";
44
import tsconfigPaths from "vite-tsconfig-paths";
55

6-
const dependenciesToChunk = {
6+
const chunkGroups = {
77
editor: [
88
"react-markdown",
99
"unified",
@@ -15,7 +15,6 @@ const dependenciesToChunk = {
1515
"remark-stringify",
1616
"strip-markdown"
1717
],
18-
indexer: ["./src/indexer/generated.ts"],
1918
media: ["plyr-react", "@livepeer/react", "browser-image-compression"],
2019
misc: [
2120
"@lens-chain/storage-client",
@@ -26,14 +25,15 @@ const dependenciesToChunk = {
2625
"virtua",
2726
"zod"
2827
],
29-
prosekit: ["prosekit", "prosekit/core", "prosekit/react"],
28+
prosekit: ["prosekit"],
3029
react: [
3130
"react",
3231
"react-dom",
3332
"react-easy-crop",
3433
"react-hook-form",
3534
"react-router",
36-
"react-tracked"
35+
"react-tracked",
36+
"@tanstack/react-query"
3737
],
3838
ui: [
3939
"@headlessui/react",
@@ -45,9 +45,25 @@ const dependenciesToChunk = {
4545
"motion",
4646
"motion-plus-react"
4747
],
48-
wevm: ["wagmi", "family", "viem", "viem/zksync"]
48+
wevm: ["wagmi", "family", "viem"]
4949
};
5050

51+
function manualChunks(id) {
52+
if (id.includes("src/indexer/generated")) {
53+
return "indexer";
54+
}
55+
56+
if (!id.includes("node_modules")) {
57+
return;
58+
}
59+
60+
for (const [chunk, deps] of Object.entries(chunkGroups)) {
61+
if (deps.some((dep) => id.includes(`/node_modules/${dep}/`))) {
62+
return chunk;
63+
}
64+
}
65+
}
66+
5167
export default defineConfig({
5268
build: {
5369
cssMinify: "lightningcss",
@@ -60,7 +76,7 @@ export default defineConfig({
6076

6177
return "assets/[name]-[hash][extname]";
6278
},
63-
manualChunks: dependenciesToChunk
79+
manualChunks
6480
}
6581
},
6682
sourcemap: true,

0 commit comments

Comments
 (0)