forked from xubaobao19940428/vue3-admin-vite-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
67 lines (66 loc) · 2.12 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
65
66
67
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
import ViteComponents, { ElementPlusResolver } from 'vite-plugin-components'
export default ({ mode }) => {
const env = loadEnv(mode, process.cwd()) // 获取.env文件里定义的环境变量
return defineConfig({
base: env.VITE_APP_BASE_URL,
server: {
proxy: {
// 选项写法
'/api/': {
target: 'http://localhost:3000/',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, 'api')
},
// 正则表达式写法
'^/fallback/.*': {
target: 'http://jsonplaceholder.typicode.com',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/fallback/, ''),
},
},
port: 8081,
host: '0.0.0.0',
https: false,
cors: true,
hmr: true,
},
plugins: [
vue(),
ViteComponents({
customComponentResolvers: [ElementPlusResolver({ importStyle: true })],
}),
],
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
dedupe: [
'vue'
]
},
css: {
preprocessorOptions: {
scss: {
additionalData: '@import "@/styles/main.scss";',
},
},
},
build: {
sourcemap: false,
cssCodeSplit: true,
rollupOptions: {
output: {
chunkFileNames: 'js/[name]-[hash].js',
entryFileNames: 'js/[name]-[hash].js',
assetFileNames: '[ext]/[name]-[hash].[ext]',
},
brotliSize: false, // 不统计
target: 'esnext',
minify: 'esbuild', // 混淆器,terser构建后文件体积更小
},
},
})
}