-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.js
128 lines (127 loc) · 4.27 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import path, { resolve } from 'path'
import vue from '@vitejs/plugin-vue'
import legacy from '@vitejs/plugin-legacy'
import vueJsx from '@vitejs/plugin-vue-jsx'
import viteSvgIcons from 'vite-plugin-svg-icons'
//mock
import { viteMockServe } from 'vite-plugin-mock'
import setting from './src/settings'
// import { loadEnv } from 'vite'
const prodMock = setting.openProdMock
export default ({ command }) => {
//fix electron some issue
let processEnv = { 'process.platform': null, 'process.version': null }
if (command === 'serve') {
processEnv = { process: { platform: {}, version: {} } }
}
return {
/*
* "/vue3-admin-plus" nginx deploy folder
* detail to look https://vitejs.cn/config/#base
* how to config, such as http://8.135.1.141/vue3-admin-plus/#/dashboard
* "/vue3-admin-plus/" --> config to base is you need
* http://8.135.1.141 --> if you config "/" , you can visit attached to http://8.135.1.141
* */
base: setting.viteBasePath,
//define global var
define: {
//fix process not define
...processEnv,
//fix "path" module issue
'process.platform': null,
'process.version': null,
GLOBAL_STRING: JSON.stringify('i am global var from vite.config.js define'),
GLOBAL_VAR: {
test: 'i am global var from vite.config.js define'
}
},
clearScreen: false,
server: {
hmr: { overlay: false }, // 禁用或配置 HMR 连接 设置 server.hmr.overlay 为 false 可以禁用服务器错误遮罩层
// 服务配置
port: 5006, // 类型: number 指定服务器端口;
open: false, // 类型: boolean | string在服务器启动时自动在浏览器中打开应用程序;
cors: true // 类型: boolean | CorsOptions 为开发服务器配置 CORS。默认启用并允许任何源
//proxy look for https://vitejs.cn/config/#server-proxy
// proxy: {
// '/api': {
// target: loadEnv(mode, process.cwd()).VITE_APP_PROXY_URL,
// changeOrigin: true,
// rewrite: (path) => path.replace(/^\/api/, '')
// }
// }
},
plugins: [
vue(),
vueJsx(),
legacy({
targets: ['ie >= 11'],
additionalLegacyPolyfills: ['regenerator-runtime/runtime']
}),
viteSvgIcons({
// config svg dir that can config multi
iconDirs: [path.resolve(process.cwd(), 'src/icons/common'), path.resolve(process.cwd(), 'src/icons/nav-bar')],
// appoint svg icon using mode
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: prodMock,
injectCode: `
import { setupProdMockServer } from './mockProdServer';
setupProdMockServer();
`,
logger: true
})
],
build: {
// minify: 'terser',
brotliSize: false,
// 消除打包大小超过500kb警告
chunkSizeWarningLimit: 2000,
//remote console.log in prod
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
}
},
//build assets Separate
assetsDir: 'static/assets',
rollupOptions: {
external:{
},
output: {
chunkFileNames: 'static/js/[name]-[hash].js',
entryFileNames: 'static/js/[name]-[hash].js',
assetFileNames: 'static/[ext]/[name]-[hash].[ext]'
}
}
},
resolve: {
alias: {
'~': resolve(__dirname, './'),
'@': resolve(__dirname, 'src'),
'#': resolve(__dirname, 'electron')
}
// why remove it , look for https://github.com/vitejs/vite/issues/6026
// extensions: ['.js', '.ts', '.jsx', '.tsx', '.json', '.vue', '.mjs']
},
css: {
preprocessorOptions: {
//define global scss variable
scss: {
additionalData: `@import "@/styles/variables.scss";`
}
}
},
// optimizeDeps: {
// include: ['element-plus/lib/locale/lang/zh-cn', 'element-plus/lib/locale/lang/en']
// }
}
}