-
-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(frontend): manual chunk js modules
- Loading branch information
1 parent
3c778f9
commit beef3f4
Showing
6 changed files
with
276 additions
and
242 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const allowList = ['mantine', 'prismjs', 'zrender', 'katex', 'pdfjs-dist', '/echarts@', '/react-dom@'] | ||
|
||
const packDict: Record<string, string> = { | ||
'src/components/admin': 'admin', | ||
'src/components': 'user', | ||
'src/pages/admin': 'admin', | ||
'src/pages': 'pages', | ||
use: 'hooks', | ||
// for __vite-browser-external | ||
browser: 'user', | ||
} | ||
|
||
export default function manualChunks(id: string): string | undefined { | ||
// pack all packDict to its own chunk | ||
for (const [key, value] of Object.entries(packDict)) { | ||
if (id.includes(key)) { | ||
return value | ||
} | ||
} | ||
// pack all node_modules/* into its own chunk | ||
if (id.includes('node_modules')) { | ||
for (const name of allowList) { | ||
if (id.includes(name)) { | ||
const match = id.match(/\.pnpm\/([^@]+)/) | ||
if (match) { | ||
return `vendor-${match[1]}` | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.