forked from LibreService/my_rime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
88 lines (82 loc) · 2.01 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
import { execSync } from 'child_process'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import replace from '@rollup/plugin-replace'
import { run } from 'vite-plugin-run'
import { VitePWA, VitePWAOptions } from 'vite-plugin-pwa'
import { appName } from './package.json'
const resources = ['rime.data', 'rime.js', 'rime.wasm']
const workbox: VitePWAOptions["workbox"] = {
maximumFileSizeToCacheInBytes: 3145728,
globPatterns: [
'**/*.{js,css,html}',
'apple-touch-icon.png',
...resources
]
}
if (process.env.LIBRESERVICE_CDN) {
workbox.manifestTransforms = [
manifest => ({
manifest: manifest.map(entry => resources.includes(entry.url) ? {
url: process.env.LIBRESERVICE_CDN + entry.url,
revision: entry.revision,
size: entry.size
} : entry),
warnings: []
})
]
}
const plugins = [
replace({
__LIBRESERVICE_CDN__: process.env.LIBRESERVICE_CDN || '',
__COMMIT__: execSync('git rev-parse HEAD').toString().trim(),
__BUILD_DATE__: new Date().toLocaleString()
}),
VitePWA({
registerType: 'autoUpdate',
workbox,
manifest: {
name: appName,
short_name: appName,
icons: [
{
src: 'LibreService.svg',
sizes: 'any',
type: 'image/svg+xml',
purpose: 'any maskable',
}
]
}
}),
vue()
]
if (process.env.NODE_ENV !== 'production') {
const watchFiles = [
'worker.ts',
'schema-files.json',
'schema-name.json',
'schema-target.json',
'dependency-map.json',
'target-files.json',
'target-version.json'
]
plugins.push(run({
input: [
{
name: 'Transpile worker',
run: ['pnpm run worker'],
condition: file => watchFiles.some(name => file.includes(name))
}
],
silent: false
}))
}
export default defineConfig({
base: '',
plugins,
server: {
watch: {
ignored: ['**/boost/**', '**/build/**', '**/dist/**', '**/librime/**', '**/scripts/**', '**/wasm/**'],
},
}
})