-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvite.config.ts
68 lines (66 loc) · 1.97 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
import { resolve } from 'node:path'
import dayjs from 'dayjs'
import type { ConfigEnv, UserConfig } from 'vite'
import { loadEnv } from 'vite'
import { createVitePlugins } from './plugin'
export default ({ command, mode }: ConfigEnv): UserConfig => {
const root = process.cwd()
const viteEnv = loadEnv(mode, root) as unknown as ViteEnv
return {
base: '/',
root,
resolve: {
alias: {
'~/': `${resolve(__dirname, 'src')}/`,
'@/': `${process.cwd()}/`,
},
},
server: {
host: '0.0.0.0',
port: viteEnv.VITE_PORT,
// 预热文件以提前转换和缓存结果,降低启动期间的初始页面加载时长并防止转换瀑布
warmup: {
clientFiles: [
'/src/styles/index.css',
'/src/router/index.ts',
'/src/router/router-helper.ts',
'/src/store/index.ts',
'/src/directives/index.ts',
'/src/{views,components}/*',
],
},
},
plugins: createVitePlugins(viteEnv, command),
json: {
// https://cn.vitejs.dev/config/shared-options.html#json-stringify
stringify: true,
},
// 依赖优化配置
optimizeDeps: {
include: [
'@vue/runtime-core',
'@vue/shared',
],
},
build: {
// 消除打包大小超过500kb警告
chunkSizeWarningLimit: 4096,
rollupOptions: {
input: {
// fix bug: 高版本vite打包之后,index.html文件没有引入css、js问题。见:https://github.com/vitejs/vite/issues/15992
index: resolve('index.html'),
},
// 静态资源分类打包
output: {
chunkFileNames: 'static/js/[name]-[hash].js',
entryFileNames: 'static/js/[name]-[hash].js',
assetFileNames: 'static/[ext]/[name]-[hash].[ext]',
},
},
},
define: {
__INTLIFY_PROD_DEVTOOLS__: false,
PROJECT_BUILD_TIME: JSON.stringify(dayjs(new Date()).format('YYYY-MM-DD HH:mm:ss')),
},
}
}