1
1
import dotenv from "dotenv" ;
2
- import { defineConfig , ServerOptions , UserConfig } from "vite" ;
2
+ import { defineConfig , PluginOption , ServerOptions , UserConfig } from "vite" ;
3
3
import react from "@vitejs/plugin-react" ;
4
4
import viteTsconfigPaths from "vite-tsconfig-paths" ;
5
5
import svgrPlugin from "vite-plugin-svgr" ;
@@ -12,6 +12,7 @@ import dynamicImport from 'vite-plugin-dynamic-import';
12
12
import { ensureLastSlash } from "./src/dev-utils/util" ;
13
13
import { buildVars } from "./src/dev-utils/buildVars" ;
14
14
import { globalDepPlugin } from "./src/dev-utils/globalDepPlguin" ;
15
+ import { terser } from 'rollup-plugin-terser' ;
15
16
// import { nodePolyfills } from 'vite-plugin-node-polyfills'
16
17
17
18
dotenv . config ( ) ;
@@ -66,16 +67,124 @@ export const viteConfig: UserConfig = {
66
67
} ,
67
68
base,
68
69
build : {
70
+ minify : "terser" ,
69
71
manifest : true ,
70
72
target : "es2020" ,
71
73
cssTarget : "chrome87" ,
72
74
outDir : "build" ,
73
75
assetsDir : "static" ,
74
76
emptyOutDir : false ,
75
77
rollupOptions : {
78
+ treeshake : {
79
+ moduleSideEffects : true ,
80
+ propertyReadSideEffects : false ,
81
+ tryCatchDeoptimization : false ,
82
+ unknownGlobalSideEffects : false ,
83
+ } ,
76
84
output : {
77
85
chunkFileNames : "[hash].js" ,
86
+ manualChunks : ( id ) => {
87
+ if ( id . includes ( "node_modules" ) ) {
88
+ // UI LIBRARIES
89
+ if ( id . includes ( "@ant-design/icons" ) ) return "ant-design-icons" ;
90
+ if ( id . includes ( "node_modules/antd" ) ) return "antd" ;
91
+ if ( id . includes ( "styled-components" ) ) return "styled-components" ;
92
+
93
+ // 🔹 BARCODE & QR CODE PROCESSING
94
+ if ( id . includes ( "react-qr-barcode-scanner" ) ) return "barcode" ;
95
+
96
+ // TEXT EDITORS & PARSERS
97
+ if ( id . includes ( "codemirror" ) ) return "codemirror" ;
98
+ if ( id . includes ( "quill" ) ) return "quill" ;
99
+ if ( id . includes ( "react-json-view" ) ) return "react-json-view" ;
100
+ if ( id . includes ( "react-quill" ) ) return "react-quill" ;
101
+ if ( id . includes ( "remark-gfm" ) ) return "remark-gfm" ;
102
+ if ( id . includes ( "rehype-raw" ) ) return "rehype-raw" ;
103
+ if ( id . includes ( "rehype-sanitize" ) ) return "rehype-sanitize" ;
104
+
105
+ // DRAG & DROP
106
+ if ( id . includes ( "@dnd-kit" ) ) return "dnd-kit" ;
107
+ if ( id . includes ( "react-draggable" ) ) return "react-draggable" ;
108
+ if ( id . includes ( "react-grid-layout" ) ) return "react-grid-layout" ;
109
+ if ( id . includes ( "react-sortable-hoc" ) ) return "react-sortable-hoc" ;
110
+
111
+ // ICONS & FONTS
112
+ if ( id . includes ( "@fortawesome" ) ) return "fontawesome" ;
113
+ if ( id . includes ( "@remixicon" ) ) return "remixicon" ;
114
+
115
+ // DATE/TIME HANDLING
116
+ if ( id . includes ( "moment" ) ) return "moment" ;
117
+ if ( id . includes ( "date-fns" ) ) return "date-fns" ;
118
+ if ( id . includes ( "dayjs" ) ) return "dayjs" ;
119
+
120
+ // UTILITIES & HELPERS
121
+ if ( id . includes ( "clsx" ) ) return "clsx" ;
122
+ if ( id . includes ( "immer" ) ) return "immer" ;
123
+ if ( id . includes ( "lodash" ) ) return "lodash" ;
124
+ if ( id . includes ( "lodash-es" ) ) return "lodash-es" ;
125
+ if ( id . includes ( "uuid" ) ) return "uuid" ;
126
+ if ( id . includes ( "ua-parser-js" ) ) return "ua-parser-js" ;
127
+ if ( id . includes ( "html2canvas" ) ) return "ua-parser-js" ;
128
+ if ( id . includes ( "numbro" ) ) return "numbro" ;
129
+
130
+ // FILE & DATA PROCESSING
131
+ if ( id . includes ( "buffer" ) ) return "buffer" ;
132
+ if ( id . includes ( "file-saver" ) ) return "file-saver" ;
133
+ if ( id . includes ( "papaparse" ) ) return "papaparse" ;
134
+ if ( id . includes ( "parse5" ) ) return "parse5" ;
135
+ if ( id . includes ( "xlsx" ) ) return "xlsx" ;
136
+ if ( id . includes ( "alasql" ) ) return "alasql" ;
137
+ if ( id . includes ( "sql-formatter" ) ) return "sql-formatter" ;
138
+
139
+ // NETWORK & HTTP
140
+ if ( id . includes ( "axios" ) ) return "axios" ;
141
+ if ( id . includes ( "fetch" ) ) return "fetch" ;
142
+ if ( id . includes ( "http" ) ) return "http-modules" ;
143
+ if ( id . includes ( "https" ) ) return "https-modules" ;
144
+
145
+ // WEB SOCKETS & STREAMING
146
+ if ( id . includes ( "sockjs" ) ) return "websockets" ;
147
+ if ( id . includes ( "websocket" ) ) return "websockets" ;
148
+
149
+ // STATE MANAGEMENT
150
+ if ( id . includes ( "react-error-boundary" ) ) return "react-error-boundary" ;
151
+ if ( id . includes ( "redux-devtools-extension" ) ) return "redux-devtools" ;
152
+
153
+ // POLYFILLS & BROWSER COMPATIBILITY
154
+ // if (id.includes("core-js")) return "core-js";
155
+ if ( id . includes ( "regenerator-runtime" ) ) return "regenerator-runtime" ;
156
+ if ( id . includes ( "eslint4b-prebuilt-2" ) ) return "eslint4b-prebuilt-2" ;
157
+
158
+ // MISCELLANEOUS
159
+ if ( id . includes ( "cnchar" ) ) return "cnchar" ;
160
+ if ( id . includes ( "hotkeys-js" ) ) return "hotkeys-js" ;
161
+ if ( id . includes ( "loglevel" ) ) return "loglevel" ;
162
+ if ( id . includes ( "qrcode.react" ) ) return "qrcode-react" ;
163
+ if ( id . includes ( "react-joyride" ) ) return "react-joyride" ;
164
+ if ( id . includes ( "rc-trigger" ) ) return "rc-trigger" ;
165
+ if ( id . includes ( "really-relaxed-json" ) ) return "really-relaxed-json" ;
166
+ if ( id . includes ( "simplebar-react" ) ) return "simplebar-react" ;
167
+ if ( id . includes ( "react-documents" ) ) return "react-documents" ;
168
+ if ( id . includes ( "react-colorful" ) ) return "react-colorful" ;
169
+ if ( id . includes ( "react-best-gradient-color-picker" ) ) return "react-best-gradient-color-picker" ;
170
+ if ( id . includes ( "@supabase/supabase-js" ) ) return "supabase" ;
171
+ return null ;
172
+ }
173
+ return null ;
174
+ } ,
78
175
} ,
176
+ plugins : [
177
+ terser ( {
178
+ compress : {
179
+ drop_console : true ,
180
+ drop_debugger : true ,
181
+ pure_funcs : [ "console.info" , "console.debug" , "console.log" ] ,
182
+ } ,
183
+ format : {
184
+ comments : / ( @ v i t e - i g n o r e | w e b p a c k I g n o r e ) /
185
+ } ,
186
+ } ) as PluginOption ,
187
+ ] ,
79
188
onwarn : ( warning , warn ) => {
80
189
if ( warning . code === 'MODULE_LEVEL_DIRECTIVE' ) {
81
190
return
0 commit comments