-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
56 lines (56 loc) · 1.47 KB
/
vite.config.ts
File metadata and controls
56 lines (56 loc) · 1.47 KB
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
import path from 'path'
import tailwindcss from '@tailwindcss/vite'
import { defineConfig, loadEnv } from 'vite'
import react from '@vitejs/plugin-react'
import { fileURLToPath } from 'url'
import { dirname } from 'path'
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
export default defineConfig(({ mode }) => {
// 获取环境变量
const { VITE_PORT, VITE_PROXY_URL } = loadEnv(mode, __dirname)
return {
root: './', // 根目录
base: '/', // 项目打包路径
publicDir: 'public', // 静态资源目录
plugins: [react(), tailwindcss()], // 插件
// 别名配置
resolve: {
alias: {
'@': path.resolve(__dirname, './src')
}
},
// scss配置
css: {
preprocessorOptions: {
scss: {
// 自动导入定制化样式文件进行样式覆盖
additionalData: '@use "@/styles/index.scss" as *;',
// 关闭 sass 变量名称警告
silenceDeprecations: ['legacy-js-api']
}
}
},
// 开发服务器配置
server: {
host: '0.0.0.0', // 服务器地址
port: Number(VITE_PORT), // 服务端口号
open: false, // 自动打开浏览器
cors: true, // 允许跨域
hmr: true, // 热更新
strictPort: false, // 端口被占用时,直接退出
// 代理配置
proxy: {
'/api': {
target: VITE_PROXY_URL,
changeOrigin: true,
rewrite: path => path.replace(/^\/api/, '')
}
}
},
// 打包配置
build: {
outDir: 'dist' // 打包输出目录
}
}
})