-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathvite.config.ts
75 lines (67 loc) · 2 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
import { resolve } from 'node:path'
import { fileURLToPath, URL } from 'node:url'
import { defineConfig, loadEnv, type Plugin, type UserConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import legacy from '@vitejs/plugin-legacy'
export default ({ mode }: { mode: string }): UserConfig => {
process.env = { ...process.env, ...loadEnv(mode, process.cwd()) }
const root: string = resolve(__dirname, 'src/' + process.env.VITE_APP)
const minify: boolean = process.env.NODE_ENV !== 'development'
const base: string = process.env.VITE_APP === 'mobile' ? '' : '/'
return defineConfig({
plugins: [
vue(),
getLegacyPlugin(process.env),
],
root,
base,
publicDir: 'assets/public',
envDir: resolve(__dirname),
build: {
outDir: resolve(__dirname, process.env.VITE_BUILD_PATH!),
emptyOutDir: true,
manifest: false,
rollupOptions: {
input: '/index.html',
output: {
manualChunks: (id) => {
if (id.includes('hls.js')) {return 'hls'}
if (id.includes('node_modules')) {return 'vendor'}
}
},
},
// target: 'es2015',
assetsInlineLimit: 4096,
minify,
},
define: {
__APP_VERSION__: JSON.stringify(getBuildDate()),
},
resolve: {
alias: {
'@app': fileURLToPath(new URL('./src/app', import.meta.url)),
'@mobile': fileURLToPath(new URL('./src/mobile', import.meta.url)),
'@locales': fileURLToPath(new URL('./src/locales', import.meta.url)),
},
},
})
}
function getLegacyPlugin (env: NodeJS.ProcessEnv): Plugin[] | null {
if (env.NODE_ENV === 'development') {
return null
}
else {
if (env.VITE_APP === 'mobile') {
return legacy({
targets: 'defaults, android >= 5.0, ios >= 12',
})
} else {
return legacy({
targets: 'defaults, android >= 5.0, ios >= 10',
})
}
}
}
function getBuildDate (): string {
return new Date().toISOString().slice(0, 10).replace(/-/g, '')
}