-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
60 lines (58 loc) · 1.51 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
import path from 'node:path'
import type { ConfigEnv } from 'vite'
import { defineConfig, loadEnv } from 'vite'
import react from '@vitejs/plugin-react'
import AutoImport from 'unplugin-auto-import/vite'
import { wrapperEnv } from './build/utils'
import pkg from './package.json'
import { createProxy } from './build/vite/proxy'
export default ({ command, mode }: ConfigEnv) => {
const root: string = process.cwd()
const env = loadEnv(mode, root)
env.VITE_GLOB_APP_VERSION = `${pkg.version}`
const viteEnv = wrapperEnv(env)
const isBuild = command === 'build'
const { VITE_PORT, VITE_PUBLIC_PATH, VITE_DROP_CONSOLE, VITE_PROXY } = viteEnv
return defineConfig({
base: VITE_PUBLIC_PATH,
resolve: {
alias: [
{
find: /^~\//,
replacement: `${path.resolve(__dirname, 'src')}/`
}
]
},
server: {
host: true,
port: VITE_PORT,
proxy: createProxy(VITE_PROXY)
},
css: {
preprocessorOptions: {
scss: {
api: 'modern-compiler' // or 'modern'
}
}
},
plugins: [
react(),
AutoImport({
dirs: ['src/global', 'src/store'],
imports: [
{
'lodash-es': ['debounce', 'omit']
}
],
dts: './src/auto-imports.d.ts'
})
],
esbuild: {
drop: mode === 'production' ? (VITE_DROP_CONSOLE ? ['console', 'debugger'] : []) : []
},
build: {
minify: 'esbuild',
sourcemap: !isBuild // 是否生成sourcemap
}
})
}