11import { sentryVitePlugin } from "@sentry/vite-plugin" ;
22import react from "@vitejs/plugin-react" ;
33import path from "path" ;
4+ import { visualizer } from "rollup-plugin-visualizer" ;
45import { defineConfig , normalizePath } from "vite" ;
5- import { analyzer } from "vite-bundle-analyzer" ;
66import { viteStaticCopy } from "vite-plugin-static-copy" ;
77
88const 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
1129export 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