-
Notifications
You must be signed in to change notification settings - Fork 9
/
vite.config.js
64 lines (63 loc) · 1.72 KB
/
vite.config.js
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
import { defineConfig, loadEnv } from 'vite'
import path from 'node:path'
import uni from '@dcloudio/vite-plugin-uni'
import AutoImport from 'unplugin-auto-import/vite'
import UnoCSS from 'unocss/vite'
import UniManifest from '@uni-helper/vite-plugin-uni-manifest'
import UniComponents from '@uni-helper/vite-plugin-uni-components'
import { NutResolver } from 'nutui-uniapp'
// https://vitejs.dev/config/
export default ({ command, mode }) => {
const env = loadEnv(mode, path.resolve(process.cwd()))
const { VITE_APP_API_BASEURL, VITE_APP_PROXY, VITE_APP_PROXY_PREFIX } = env
return defineConfig({
resolve: {
alias: {
'@': path.join(process.cwd(), './src'),
'@img': path.join(process.cwd(), './src/static/images')
}
},
plugins: [
UniComponents({
dts: false,
resolvers: [NutResolver()]
}),
UniManifest(),
uni(),
AutoImport({
dts: false,
imports: [
'vue',
'uni-app',
'pinia',
{
'@/api': ['useRequest']
}
],
eslintrc: { enabled: true }
}),
UnoCSS()
],
server: {
host: '0.0.0.0',
hmr: true,
// 仅 H5 端生效,其他端不生效(其他端走build,不走devServer)
proxy: JSON.parse(VITE_APP_PROXY)
? {
[VITE_APP_PROXY_PREFIX]: {
target: VITE_APP_API_BASEURL,
changeOrigin: true,
rewrite: (path) => path.replace(new RegExp(`^${VITE_APP_PROXY_PREFIX}`), '')
}
}
: undefined
},
css: {
preprocessorOptions: {
scss: {
additionalData: `@import "nutui-uniapp/styles/variables.scss";`
}
}
}
})
}