-
Notifications
You must be signed in to change notification settings - Fork 1
/
vite.config.mts
67 lines (62 loc) · 1.69 KB
/
vite.config.mts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import path from 'node:path'
import react from '@vitejs/plugin-react'
import { defineConfig, Plugin } from 'vite'
export default defineConfig({
plugins: [
react(),
muteWarningsPlugin([
['SOURCEMAP_ERROR', "Can't resolve original location of error"],
// [
// 'INVALID_ANNOTATION',
// 'contains an annotation that Rollup cannot interpret',
// ],
]),
],
build: {
chunkSizeWarningLimit: 700,
},
resolve: {
alias: {
'@': path.resolve(process.cwd(), './src'),
},
},
})
function muteWarningsPlugin(warningsToIgnore: string[][]): Plugin {
const mutedMessages = new Set()
return {
name: 'mute-warnings',
enforce: 'pre',
config: (userConfig) => ({
build: {
rollupOptions: {
onwarn(warning, defaultHandler) {
if (warning.code) {
const muted = warningsToIgnore.find(
([code, message]) =>
code == warning.code && warning.message.includes(message)
)
if (muted) {
mutedMessages.add(muted.join())
return
}
}
if (userConfig.build?.rollupOptions?.onwarn) {
userConfig.build.rollupOptions.onwarn(warning, defaultHandler)
} else {
defaultHandler(warning)
}
},
},
},
}),
closeBundle() {
const diff = warningsToIgnore.filter((x) => !mutedMessages.has(x.join()))
if (diff.length > 0) {
this.warn(
'Some of your muted warnings never appeared during the build process:'
)
diff.forEach((m) => this.warn(`- ${m.join(': ')}`))
}
},
}
}