-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.js
38 lines (35 loc) · 1.14 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
import { defineConfig ,loadEnv} from 'vite'
import { wrapperEnv, createProxy } from './build/utils'
import { createVitePlugins } from './build/plugin'
import path from 'path'
// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
const isBuild = command === 'build'
const env = loadEnv(mode, process.cwd())
const viteEnv = wrapperEnv(env)
// 在配置中使用环境变量
const { VITE_PORT, VITE_PUBLIC_PATH, VITE_PROXY } = viteEnv
return {
plugins: createVitePlugins(viteEnv, isBuild),
base: VITE_PUBLIC_PATH || '/',
resolve: {
// 设置别名,用以在项目中使用@作为根路径
alias: {
'@': path.resolve(__dirname, 'src'),
},
},
css: {
preprocessorOptions: {
//定义scss全局变量
scss: {
additionalData: `@import '@/styles/variables.scss';`,
},
},
},
server: {
host: '0.0.0.0', // 默认为'127.0.0.1',如果将此设置为 `0.0.0.0` 或者 `true` 将监听所有地址,包括局域网和公网地址
port: VITE_PORT, // 端口
proxy: createProxy(VITE_PROXY), // 代理
}
}
})