1
1
import path , { resolve } from 'path' ;
2
2
import react from '@vitejs/plugin-react' ;
3
3
import { VitePWA } from 'vite-plugin-pwa' ;
4
- import { defineConfig , createLogger } from 'vite' ;
4
+ import { defineConfig } from 'vite' ;
5
5
import { nodePolyfills } from 'vite-plugin-node-polyfills' ;
6
+ import compression from 'vite-plugin-compression' ;
6
7
import type { Plugin } from 'vite' ;
7
8
8
- const logger = createLogger ( ) ;
9
- const originalWarning = logger . warn ;
10
- logger . warn = ( msg , options ) => {
11
- /* Suppresses:
12
- [vite:css] Complex selectors in '.group:focus-within .dark\:group-focus-within\:text-gray-300:is(.dark *)' can not be transformed to an equivalent selector without ':is()'.
13
- */
14
- if ( msg . includes ( 'vite:css' ) && msg . includes ( '^^^^^^^' ) ) {
15
- return ;
16
- }
17
- /* Suppresses:
18
- (!) Some chunks are larger than 500 kB after minification. Consider:
19
- - Using dynamic import() to code-split the application
20
- - Use build.rollupOptions.output.manualChunks to improve chunking: https://rollupjs.org/configuration-options/#output-manualchunks
21
- - Adjust chunk size limit for this warning via build.chunkSizeWarningLimit.
22
- */
23
- if ( msg . includes ( 'Use build.rollupOptions.output.manualChunks' ) ) {
24
- return ;
25
- }
26
- originalWarning ( msg , options ) ;
27
- } ;
28
-
29
9
// https://vitejs.dev/config/
30
10
export default defineConfig ( {
31
- customLogger : logger ,
32
11
server : {
33
- fs : {
34
- cachedChecks : false ,
35
- } ,
36
12
host : 'localhost' ,
37
13
port : 3090 ,
38
14
strictPort : false ,
@@ -47,7 +23,7 @@ export default defineConfig({
47
23
} ,
48
24
} ,
49
25
} ,
50
- // All other env variables are filtered out
26
+ // Set the directory where environment variables are loaded from and restrict prefixes
51
27
envDir : '../' ,
52
28
envPrefix : [ 'VITE_' , 'SCRIPT_' , 'DOMAIN_' , 'ALLOW_' ] ,
53
29
plugins : [
@@ -57,11 +33,14 @@ export default defineConfig({
57
33
injectRegister : 'auto' , // 'auto' | 'manual' | 'disabled'
58
34
registerType : 'autoUpdate' , // 'prompt' | 'autoUpdate'
59
35
devOptions : {
60
- enabled : false , // enable/ disable registering SW in development mode
36
+ enabled : false , // disable service worker registration in development mode
61
37
} ,
62
38
useCredentials : true ,
63
39
workbox : {
64
- globPatterns : [ 'assets/**/*.{png,jpg,svg,ico}' , '**/*.{js,css,html,ico,woff2}' ] ,
40
+ globPatterns : [
41
+ 'assets/**/*.{png,jpg,svg,ico}' ,
42
+ '**/*.{js,css,html,ico,woff2}' ,
43
+ ] ,
65
44
maximumFileSizeToCacheInBytes : 5 * 1024 * 1024 ,
66
45
navigateFallbackDenylist : [ / ^ \/ o a u t h / ] ,
67
46
} ,
@@ -103,33 +82,70 @@ export default defineConfig({
103
82
} ,
104
83
} ) ,
105
84
sourcemapExclude ( { excludeNodeModules : true } ) ,
85
+ compression ( {
86
+ verbose : true ,
87
+ disable : false ,
88
+ threshold : 10240 , // compress files larger than 10KB
89
+ algorithm : 'gzip' ,
90
+ ext : '.gz' ,
91
+ } ) ,
106
92
] ,
107
93
publicDir : './public' ,
108
94
build : {
109
95
sourcemap : process . env . NODE_ENV === 'development' ,
110
96
outDir : './dist' ,
97
+ minify : 'terser' ,
111
98
rollupOptions : {
99
+ preserveEntrySignatures : 'strict' ,
112
100
// external: ['uuid'],
113
101
output : {
114
- manualChunks : ( id ) => {
115
- if ( id . includes ( 'node_modules/highlight.js' ) ) {
116
- return 'markdown_highlight' ;
117
- }
118
- // if (id.includes('node_modules/hast-util-raw')) {
119
- // return 'markdown_large';
120
- // }
121
- // if (id.includes('node_modules/katex')) {
122
- // return 'markdown_large';
123
- // }
102
+ manualChunks ( id : string ) {
124
103
if ( id . includes ( 'node_modules' ) ) {
104
+ // Group Radix UI libraries together.
105
+ if ( id . includes ( '@radix-ui' ) ) {
106
+ return 'radix-ui' ;
107
+ }
108
+ // Group framer-motion separately.
109
+ if ( id . includes ( 'framer-motion' ) ) {
110
+ return 'framer-motion' ;
111
+ }
112
+ // Group markdown-related libraries.
113
+ if ( id . includes ( 'node_modules/highlight.js' ) ) {
114
+ return 'markdown_highlight' ;
115
+ }
116
+ // if (
117
+ // id.includes('node_modules/hast-util-raw') ||
118
+ // id.includes('node_modules/katex')
119
+ // ) {
120
+ // return 'markdown_large';
121
+ // }
122
+ // Group TanStack libraries together.
123
+ if ( id . includes ( '@tanstack' ) ) {
124
+ return 'tanstack-vendor' ;
125
+ }
126
+ // Additional grouping for other node_modules:
127
+ if ( id . includes ( '@headlessui' ) ) {
128
+ return 'headlessui' ;
129
+ }
130
+
131
+ // Everything else falls into a generic vendor chunk.
125
132
return 'vendor' ;
126
133
}
134
+ // Create a separate chunk for all locale files under src/locales.
135
+ if ( id . includes ( path . join ( 'src' , 'locales' ) ) ) {
136
+ return 'locales' ;
137
+ }
138
+ // Let Rollup decide automatically for any other files.
139
+ return null ;
127
140
} ,
128
141
entryFileNames : 'assets/[name].[hash].js' ,
129
142
chunkFileNames : 'assets/[name].[hash].js' ,
130
143
assetFileNames : ( assetInfo ) => {
131
- if ( assetInfo . name && / \. ( w o f f | w o f f 2 | e o t | t t f | o t f ) $ / . test ( assetInfo . name ) ) {
132
- return 'assets/[name][extname]' ;
144
+ if (
145
+ assetInfo . names &&
146
+ / \. ( w o f f | w o f f 2 | e o t | t t f | o t f ) $ / . test ( assetInfo . names )
147
+ ) {
148
+ return 'assets/fonts/[name][extname]' ;
133
149
}
134
150
return 'assets/[name].[hash][extname]' ;
135
151
} ,
@@ -139,15 +155,13 @@ export default defineConfig({
139
155
* @see {@link https://github.com/TanStack/query/pull/5161#issuecomment-1477389761 Preserve 'use client' directives TanStack/query#5161 }
140
156
*/
141
157
onwarn ( warning , warn ) {
142
- if (
143
- // warning.code === 'MODULE_LEVEL_DIRECTIVE' &&
144
- warning . message . includes ( 'Error when using sourcemap' )
145
- ) {
158
+ if ( warning . message . includes ( 'Error when using sourcemap' ) ) {
146
159
return ;
147
160
}
148
161
warn ( warning ) ;
149
162
} ,
150
163
} ,
164
+ chunkSizeWarningLimit : 1200 ,
151
165
} ,
152
166
resolve : {
153
167
alias : {
@@ -173,4 +187,4 @@ export function sourcemapExclude(opts?: SourcemapExclude): Plugin {
173
187
}
174
188
} ,
175
189
} ;
176
- }
190
+ }
0 commit comments