-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.js
123 lines (114 loc) · 2.98 KB
/
vite.config.js
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
114
115
116
117
118
119
120
121
122
123
import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import Components from 'unplugin-vue-components/vite'
import AutoImport from 'unplugin-auto-import/vite'
import { IonicResolver } from 'unplugin-vue-components/resolvers'
import { VitePWA } from 'vite-plugin-pwa'
import replace from '@rollup/plugin-replace'
import lightningcss from 'vite-plugin-lightningcss'
const pwaOptions = {
mode: 'development',
base: '/',
includeAssets: ['favicon.svg'],
manifest: {
name: 'Vue 3 PWA ',
short_name: 'Vite 3 PWA ',
theme_color: '#ffffff',
display: 'standalone',
background_color: '#ffffff',
icons: [
{
src: 'pwa-192x192.png',
sizes: '192x192',
type: 'image/png'
},
{
src: 'pwa-512x512.png',
sizes: '512x512',
type: 'image/png'
},
{
src: 'pwa-512x512.png',
sizes: '512x512',
type: 'image/png',
purpose: 'any maskable'
}
]
}
/*devOptions: {
enabled: process.env.SW_DEV === 'true',
when using generateSW the PWA plugin will switch to classic
type: 'module',
navigateFallback: 'index.html',
suppressWarnings: true
}*/
}
const replaceOptions = { __DATE__: new Date().toISOString() }
const claims = process.env.CLAIMS === 'true'
const reload = process.env.RELOAD_SW === 'true'
const selfDestroying = process.env.SW_DESTROY === 'true'
if (process.env.SW === 'true') {
pwaOptions.srcDir = 'src'
pwaOptions.filename = claims ? 'claims-sw.js' : 'prompts-sw.js'
pwaOptions.strategies = 'injectManifest'
pwaOptions.manifest.name = 'PWA Inject Manifest'
pwaOptions.manifest.short_name = 'PWA Inject'
pwaOptions.injectManifest = {
globPatterns: [
// all packaged resources are stored here
'**/*.{css,js,html,svg,png,ico,txt,woff2}',
'assets/*'
]
}
}
if (claims) {
pwaOptions.registerType = 'autoUpdate'
pwaOptions.workbox = {
globPatterns: ['**/*.{css,js,html,svg,png,ico,txt,woff2}']
}
}
if (reload) {
// @ts-expect-error overrides
replaceOptions.__RELOAD_SW__ = 'true'
}
if (selfDestroying) pwaOptions.selfDestroying = selfDestroying
// https://vitejs.dev/config/
export default defineConfig({
define: {
'process.env': {}
},
plugins: [
vue(),
VitePWA(pwaOptions),
replace(replaceOptions, {
preventAssinment: true
}),
lightningcss({
browserslist: '>= 0.25%'
}),
Components({
resolvers: [IonicResolver()]
}),
AutoImport({
// targets to transform
include: [
/\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
/\.vue$/,
/\.vue\?vue/ // .vue
],
// global imports to register
imports: [
// presets
'vue',
'vue-router',
{ '@ionic/vue': ['IonicVue'], '@ionic/vue-router': ['createRouter', 'createWebHistory'] }
]
})
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
}
})