-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.js
100 lines (99 loc) · 2.94 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import { resolve } from 'path'
import { createHtmlPlugin } from 'vite-plugin-html'
import { viteMockServe } from 'vite-plugin-mock'
import svgLoader from 'vite-svg-loader'
import legacy from '@vitejs/plugin-legacy'
// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
return defineConfig({
base: loadEnv(mode, process.cwd()).VITE_PUBLIC_PATH,
server: {
host: '0.0.0.0',
hmr: true,
port: parseInt(loadEnv(mode, process.cwd()).VITE_PORT),
open: true,
proxy: {
'/dev_api/': {
target: 'http://10.68.130.83:8080',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/dev_api/, '')
}
}
},
plugins: [
vue(),
createHtmlPlugin({
inject: {
data: {
title: loadEnv(mode, process.cwd()).VITE_PROJECT_NAME
}
}
}),
AutoImport({
// resolvers: [ElementPlusResolver()],
imports: ['vue', 'pinia', 'vue-router'],
dts: true
}),
Components({
// resolvers: [ElementPlusResolver()] // 会引起重载
}),
svgLoader(),
createSvgIconsPlugin({
iconDirs: [resolve(process.cwd(), 'src/icons/svg')],
symbolId: 'icon-[dir]-[name]'
}),
//https://github.com/anncwb/vite-plugin-mock/blob/HEAD/README.zh_CN.md
viteMockServe({
supportTs: true,
mockPath: 'mock',
localEnabled: command === 'serve',
prodEnabled: loadEnv(mode, process.cwd()).OPEN_MOCK,
injectCode: `
import { setupProdMockServer } from './mockProdServer';
setupProdMockServer();
`,
logger: true
}),
legacy({
targets: ['chrome >= 49', 'safari >= 10', 'ios >= 10']
}),
],
build: {
target: 'es2015',
outDir: './dist',
minify: 'terser',
brotliSize: false,
// 消除打包大小超过500kb警告
chunkSizeWarningLimit: 5000,
terserOptions: {
//detail to look https://terser.org/docs/api-reference#compress-options
compress: {
drop_console: false,
pure_funcs: ['console.log', 'console.info'],
drop_debugger: true
}
},
assetsDir: 'static/assets',
rollupOptions: {
output: {
chunkFileNames: 'static/js/[name]-[hash].js',
entryFileNames: 'static/js/[name]-[hash].js',
assetFileNames: 'static/[ext]/[name]-[hash].[ext]'
}
}
},
resolve: {
alias: {
'~/': `${resolve(__dirname, 'src')}/`,
'@': resolve(__dirname, './src')
}
},
optimizeDeps: {}
})
})