This repository has been archived by the owner on Apr 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathvite.config.ts
82 lines (77 loc) · 1.82 KB
/
vite.config.ts
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import svgr from '@honkhonk/vite-plugin-svgr'
import react from '@vitejs/plugin-react'
import path from 'path'
import summary from 'rollup-plugin-summary'
import bundleVisualizer from 'rollup-plugin-visualizer'
import AutoImport from 'unplugin-auto-import/vite'
import { defineConfig, Plugin } from 'vite'
import { dependencies } from './package.json'
const getBundleVisualizerPlugin = () =>
({
...bundleVisualizer({
template: 'treemap', // or sunburst
open: true,
gzipSize: true,
}),
apply: 'build',
enforce: 'post',
} as Plugin)
const renderChunks = (deps: Record<string, string>) => {
const chunks = {}
Object.keys(deps).forEach((key) => {
if (
['react', 'react-router-dom', 'react-dom', 'lodash', 'rollup-plugin-summary', '@metamask/onboarding'].includes(
key,
)
)
return
chunks[key] = [key]
})
return chunks
}
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
AutoImport({
imports: [
'react',
{
react: [
// named imports
'memo',
'createContext',
],
},
],
dts: './src/auto-imports.d.ts',
eslintrc: {
enabled: true, // Default `false`
filepath: './.eslintrc-auto-import.json', // Default `./.eslintrc-auto-import.json`
globalsPropValue: true, // Default `true`, (true | false | 'readonly' | 'readable' | 'writable' | 'writeable')
},
}),
react(),
svgr(),
// @ts-ignore
summary({
showBrotliSize: false,
}),
// uncomment this to analyze bundle
// getBundleVisualizerPlugin(),
],
resolve: {
alias: [{ find: '@', replacement: path.resolve(__dirname, '/src') }],
},
build: {
sourcemap: false,
rollupOptions: {
output: {
manualChunks: {
vendor: ['react', 'react-router-dom', 'react-dom'],
...renderChunks(dependencies),
},
chunkFileNames: '[name].[hash].js',
},
},
},
})