-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvite.config.ts
executable file
·113 lines (104 loc) · 2.8 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import type { Plugin } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import VueDevTools from 'vite-plugin-vue-devtools'
import type { ManifestOptions, VitePWAOptions } from 'vite-plugin-pwa'
import { VitePWA } from 'vite-plugin-pwa'
const pwaAssets = true
const pwaOptions: Partial<VitePWAOptions> = {
mode: 'development',
base: '/',
includeAssets: ['favicon.svg'],
manifest: {
theme_color: '#6841ea',
background_color: '#6841ea',
display: 'standalone',
scope: '/',
start_url: '/',
name: 'Portfolio | Jerome Pangilinan',
short_name: 'Jerome',
description: "Jerome Pangilinan's portfolio website",
icons: [
{
src: '/icon-192x192.png',
sizes: '192x192',
type: 'image/png'
},
{
src: '/icon-256x256.png',
sizes: '256x256',
type: 'image/png'
},
{
src: '/icon-384x384.png',
sizes: '384x384',
type: 'image/png'
},
{
src: '/icon-512x512.png',
sizes: '512x512',
type: 'image/png'
}
]
},
devOptions: {
enabled: true,
/* when using generateSW the PWA plugin will switch to classic */
type: 'module',
navigateFallback: 'index.html',
suppressWarnings: true
}
}
if (pwaAssets) {
pwaOptions.pwaAssets = {
preset: 'minimal-2023',
overrideManifestIcons: true
}
}
const claims = true
const selfDestroying = true
function virtualMessagePlugin() {
const virtual = 'virtual:message'
const resolvedVirtual = `\0${virtual}`
return {
name: 'vite-plugin-test',
resolveId(id) {
return id === virtual ? resolvedVirtual : null
},
load(id) {
if (id === resolvedVirtual)
return `export const message = 'Message from Virtual Module Plugin'`
}
} satisfies Plugin
}
// eslint-disable-next-line no-constant-condition
if (true) {
pwaOptions.srcDir = 'src'
pwaOptions.filename = claims ? 'claims-sw.js' : 'prompt-sw.js'
pwaOptions.strategies = 'injectManifest'
// ;(pwaOptions.manifest as Partial<ManifestOptions>).name = 'PWA Inject Manifest'
// ;(pwaOptions.manifest as Partial<ManifestOptions>).short_name = 'PWA Inject'
pwaOptions.injectManifest = {
minify: false,
enableWorkboxModulesLogs: true,
buildPlugins: {
vite: [virtualMessagePlugin()]
}
}
}
if (claims) pwaOptions.registerType = 'autoUpdate'
if (selfDestroying) pwaOptions.selfDestroying = selfDestroying
// https://vitejs.dev/config/
export default defineConfig({
build: {
sourcemap: true
},
plugins: [vue(), vueJsx(), VueDevTools(), virtualMessagePlugin(), VitePWA(pwaOptions)],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
}
})