-
Notifications
You must be signed in to change notification settings - Fork 203
/
vite.config.ts
132 lines (131 loc) · 4.67 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
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
129
130
131
132
import { resolve } from 'path'
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
// import { viteMockServe } from 'vite-plugin-mock'
import Components from 'unplugin-vue-components/vite'
import UnoCSS from 'unocss/vite'
import { presetAttributify, presetIcons, presetUno } from 'unocss'
import mkcert from 'vite-plugin-mkcert'
import AutoImport from 'unplugin-auto-import/vite'
import setting from './src/settings'
// const prodMock = setting.openProdMock
import vitePluginSetupExtend from './src/plugins/vite-plugin-setup-extend'
// import { visualizer } from 'rollup-plugin-visualizer'
const pathSrc = resolve(__dirname, 'src')
// @ts-ignore
export default defineConfig(({ command, mode }) => {
const env = loadEnv(mode, process.cwd(), '') //获取环境变量
return {
base: setting.viteBasePath,
define: {
//define global var
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, //设为 false 可以避免 Vite 清屏而错过在终端中打印某些关键信息
server: {
//hmr: { overlay: false }, //设置 server.hmr.overlay 为 false 可以禁用开发服务器错误的屏蔽。方便错误查看
port: 5005, // 类型: number 指定服务器端口;
open: false, // 类型: boolean | string在服务器启动时自动在浏览器中打开应用程序;
host: true,
https: false,
// origin: ' http://192.168.198.226:5005',
// proxy: {
// [env.VITE_APP_BASE_URL]: {
// target: env.VITE_PROXY_URL,
// changeOrigin: true,
// rewrite: (path) => path.replace(new RegExp(`^${env.VITE_APP_BASE_URL}`), '')
// }
// }
},
preview: {
port: 5010,
host: true,
strictPort: true
},
plugins: [
vue(),
vueJsx(),
UnoCSS({
presets: [presetUno(), presetAttributify(), presetIcons()]
}),
mkcert(),
//compatible with old browsers
// legacy({
// targets: ['chrome 52'],
// additionalLegacyPolyfills: ['regenerator-runtime/runtime']
// }),
createSvgIconsPlugin({
iconDirs: [resolve(process.cwd(), 'src/icons/common'), resolve(process.cwd(), 'src/icons/nav-bar')],
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 '../mock-prod-server';
// setupProdMockServer();
// `,
// logger: true
// }),
// VueSetupExtend(),using DefineOptions instant of it
//https://github.com/antfu/unplugin-auto-import/blob/HEAD/src/types.ts
Components({
dirs: ['src/components', 'src/icons'],
extensions: ['vue'],
deep: true,
dts: './typings/components.d.ts'
}),
AutoImport({
imports: [
'vue',
'vue-router',
{
'pinia/dist/pinia': ['storeToRefs']
}
],
//配置后会自动扫描目录下的文件
dirs: ['src/hooks/**'],
eslintrc: {
enabled: true, // Default `false`
filepath: './eslintrc/.eslintrc-auto-import.json', // Default `./.eslintrc-auto-import.json`
globalsPropValue: true // Default `true`, (true | false | 'readonly' | 'readable' | 'writable' | 'writeable')
},
dts: './typings/auto-imports.d.ts'
}),
vitePluginSetupExtend({ inject: { title: setting.title } })
//依赖分析插件
// visualizer({
// open: true,
// gzipSize: true,
// brotliSize: true
// })
],
build: {
chunkSizeWarningLimit: 10000, //消除触发警告的 chunk, 默认500k
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: {
'@/': `${pathSrc}/`,
'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js' //remove i18n waring
}
},
optimizeDeps: {
//include: [...optimizeDependencies,...optimizeElementPlus] //on-demand element-plus use this
include: ['moment-mini',"@wangeditor/editor-for-vue","xlsx","d3","vuedraggable"]
}
}
})