-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvite.config.ts
69 lines (63 loc) · 1.5 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
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 = ['opencc.js', 'opencc.wasm']
const workbox: VitePWAOptions["workbox"] = {
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({
__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') {
plugins.push(run([
{
name: 'Transpile worker',
run: ['pnpm run worker'],
condition: file => file.includes('worker.ts')
}
]))
}
export default defineConfig({
base: '',
plugins
})