-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
92 lines (89 loc) · 2.37 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
83
84
85
86
87
88
89
90
91
92
import fs from 'node:fs'
import path from 'node:path'
import { __DEV__ } from '@pkgr/utils'
import replace from '@rollup/plugin-replace'
import strip from '@rollup/plugin-strip'
import react from '@vitejs/plugin-react'
import { html } from '@vitery/html'
import { svgr } from '@vitery/svgr'
import { visualizer } from 'rollup-plugin-visualizer'
import { defineConfig } from 'vite'
import { AntdResolve, createStyleImportPlugin } from 'vite-plugin-style-import'
import { isEnvEnabled, TEMPLATE_OPTIONS } from 'shared'
import { ANT_PREFIX, themeVars } from 'styles'
export default defineConfig(({ command }) => ({
resolve: {
alias: fs
.readdirSync(path.resolve(process.cwd(), 'src'), {
withFileTypes: true,
})
.reduce<Record<string, string>>(
(acc, dir) => {
if (dir.isDirectory()) {
Object.assign(acc, {
[dir.name]: `/src/${dir.name}/`,
})
}
return acc
},
{
dayjs: 'dayjs/esm',
moment: 'dayjs/esm',
assets: '/assets',
shared: '/shared',
mixins: 'src/styles/_mixins.less',
variables: 'src/styles/_variables.less',
// `moduleReplacement` is only available on build
...(command === 'build' && {
'./wdyr': 'src/wdyr.prod.ts', // bundled by `vite` rather than `rollup`
classnames: 'clsx',
lodash: 'lodash-es',
}),
},
),
},
plugins: [
createStyleImportPlugin({
resolves: [AntdResolve()],
}),
html({
templateOptions: TEMPLATE_OPTIONS,
minify: command === 'build',
}),
react(),
replace({
preventAssignment: true,
values: {
__DEV__: JSON.stringify(__DEV__),
__SERVER__: JSON.stringify(false),
ASYNC_VALIDATOR_NO_WARNING: JSON.stringify(true),
'process.env.MOCK': JSON.stringify(isEnvEnabled('MOCK')),
},
}),
svgr(),
],
build: {
rollupOptions: {
plugins: [strip(), isEnvEnabled('ANALYZE') && visualizer()].filter(
Boolean,
),
},
},
css: {
modules: {
localsConvention: 'camelCaseOnly',
},
preprocessorOptions: {
less: {
javascriptEnabled: true,
modifyVars: {
'ant-prefix': ANT_PREFIX,
...themeVars,
},
},
},
},
server: {
open: true,
},
}))