-
Notifications
You must be signed in to change notification settings - Fork 176
/
Copy pathvite.config.ts
64 lines (62 loc) · 1.79 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
import { defineConfig, loadEnv } from 'vite';
import { resolve } from 'path';
import presets from './presets/presets';
// https://vitejs.dev/config/
export default defineConfig((env) => {
// env 环境变量
const viteEnv = loadEnv(env.mode, process.cwd());
return {
base: viteEnv.VITE_BASE,
// 插件
plugins: [presets(env)],
// 别名设置
resolve: {
alias: {
'@': resolve(__dirname, './src'), // 把 @ 指向到 src 目录去
},
},
// 服务设置
server: {
host: true, // host设置为true才可以使用network的形式,以ip访问项目
port: 8080, // 端口号
open: true, // 自动打开浏览器
cors: true, // 跨域设置允许
strictPort: true, // 如果端口已占用直接退出
// 接口代理
proxy: {
'/api': {
// 本地 8000 前端代码的接口 代理到 8888 的服务端口
target: 'http://localhost:8888/',
changeOrigin: true, // 允许跨域
rewrite: (path) => path.replace('/api/', '/'),
},
},
},
build: {
reportCompressedSize: false,
// 消除打包大小超过500kb警告
chunkSizeWarningLimit: 2000,
minify: 'esbuild',
assetsDir: 'static/assets',
// 静态资源打包到dist下的不同目录
rollupOptions: {
output: {
chunkFileNames: 'static/js/[name]-[hash].js',
entryFileNames: 'static/js/[name]-[hash].js',
assetFileNames: 'static/[ext]/[name]-[hash].[ext]',
},
},
},
css: {
preprocessorOptions: {
// 全局引入了 scss 的文件
scss: {
additionalData: `
@import "@/assets/styles/variables.scss";
`,
javascriptEnabled: true,
},
},
},
};
});