-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathvite.config.ts
More file actions
111 lines (106 loc) · 3.54 KB
/
vite.config.ts
File metadata and controls
111 lines (106 loc) · 3.54 KB
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
import vue from '@vitejs/plugin-vue'
import chalk, { ChalkInstance } from 'chalk'
import { Features } from 'lightningcss'
import { URL, fileURLToPath } from 'node:url'
import { visualizer } from 'rollup-plugin-visualizer'
import { simpleGit } from 'simple-git'
import { defineConfig } from 'vite'
import packageJSON from './package.json'
import { coiPlugin } from './pipelines/coi/plugin'
import { faviconPlugin } from './pipelines/favicon/plugin'
import { viteStaticCopyPyodide } from './pipelines/pyodide/plugin'
import { manifestPlugin } from './pipelines/webManifest/plugin'
const aliasRelMap: Record<string, string> = {
'@core': './src/core',
'@assets': './src/assets',
'@ui': './src/ui',
'@utils': './src/utils',
'@states': './src/states',
'@vendors': './src/vendors',
'@i18n': './src/i18n',
}
const isBeta = process.env.VITE_BUILD_CHANNEL === 'BETA'
const defineObjMap: Record<string, string | number | boolean | undefined> = {
__APP_VERSION__: packageJSON.version,
__APP_COMMIT_HASH__: await simpleGit().revparse(['HEAD']),
__REPO_URL__: packageJSON.repository,
__APP_DISPLAY_NAME__: packageJSON.displayName + (isBeta ? ` BETA` : ''),
__APP_BUILD_CHANNEL__: process.env.VITE_BUILD_CHANNEL || undefined,
__APP_IS_BETA__: isBeta,
__APP_BUILD_TIMESTAMP__: Date.now(),
__AMLL_CORE_VERSION__: packageJSON.dependencies['@applemusic-like-lyrics/core'],
__AMLL_VUE_VERSION__: packageJSON.dependencies['@applemusic-like-lyrics/vue'],
}
const channelColors: Record<string, ChalkInstance> = {
STABLE: chalk.hex('#10B981'),
BETA: chalk.hex('#F97316'),
UNSPECIFIED: chalk.gray,
}
const channel = process.env.VITE_BUILD_CHANNEL || 'UNSPECIFIED'
console.log(`Current channel: ${channelColors[channel]?.(channel) || channel}\n`)
// https://vite.dev/config/
export default defineConfig(({ mode }) => ({
plugins: [
manifestPlugin(),
faviconPlugin(),
coiPlugin(),
viteStaticCopyPyodide(mode === 'development'),
vue(),
visualizer({
gzipSize: true,
brotliSize: true,
emitFile: false,
filename: 'chunk-analysis.html',
}),
],
worker: { format: 'es' },
resolve: {
alias: Object.fromEntries(
[...Object.entries(aliasRelMap)].map(([key, rel]) => [
key,
fileURLToPath(new URL(rel, import.meta.url)),
]),
),
},
define: Object.fromEntries(
[...Object.entries(defineObjMap)].map(([key, value]) => [key, JSON.stringify(value)]),
),
optimizeDeps: { exclude: ['pyodide'] },
build: {
chunkSizeWarningLimit: 1024,
rollupOptions: {
output: {
manualChunks(id) {
if (!id.includes('node_modules')) return
const m = id.split('node_modules/')[1]
if (m.startsWith('prime') || m.startsWith('@prime') || m.startsWith('@mdi')) return 'ui'
if (m.startsWith('@vue') || m.startsWith('pinia') || m.startsWith('@vueuse')) return 'vue'
if (m.startsWith('codemirror') || m.startsWith('@codemirror')) return 'codemirror'
if (m.startsWith('compromise') || m.startsWith('syllabify')) return 'nlp'
if (
m.startsWith('@applemusic-like-lyrics') ||
m.startsWith('@pixi') ||
m.startsWith('jss')
)
return 'amll'
return 'vendor'
},
},
external: [
'node:url',
'node:fs',
'node:fs/promises',
'node:vm',
'node:path',
'node:crypto',
'node:child_process',
],
},
},
css: {
transformer: 'lightningcss',
lightningcss: {
exclude: Features.LightDark,
},
},
}))