Repository navigation
Expand file tree
/
Copy pathvite.config.js
More file actions
121 lines (119 loc) · 3.97 KB
/
Copy pathvite.config.js
File metadata and controls
121 lines (119 loc) · 3.97 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
112
113
114
115
116
117
118
119
120
121
import { fileURLToPath, URL } from 'node:url'
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import { VitePWA } from 'vite-plugin-pwa'
export default defineConfig(({ mode }) => {
// Load environment variables
const env = loadEnv(mode, '.', '')
// Get BASE_PATH from environment variable, default to './' for relative paths
// Using './' ensures the app works when deployed at any sub-path without configuration
// Ensure base path ends with slash for proper URL construction
let base = env.BASE_PATH || './'
if (!base.endsWith('/')) {
base = base + '/'
}
return {
base,
define: {
// Make BASE_PATH available to client-side code through import.meta.env
'import.meta.env.BASE_PATH': JSON.stringify(base)
},
plugins: [
vue(),
vueJsx(),
VitePWA({
registerType: 'autoUpdate',
base: base, // Make sure PWA respects the base path
includeAssets: [
'app_icons/web/favicon.ico',
'app_icons/web/splash-750x1334@2x.png',
'app_icons/web/splash-1170x2532@3x.png',
'app_icons/web/splash-1290x2796@3x.png',
'app_icons/web/splash-2048x2732@2x.png'
],
manifest: {
name: 'MiniQR',
short_name: 'MiniQR',
description: 'A minimal QR code generator and scanner',
theme_color: '#ffffff',
background_color: '#ffffff',
display: 'standalone',
orientation: 'portrait',
start_url: base, // Use the base path as start URL
icons: [
{
src: 'app_icons/web/icon-192.png',
sizes: '192x192',
type: 'image/png'
},
{
src: 'app_icons/web/icon-192-maskable.png',
sizes: '192x192',
type: 'image/png',
purpose: 'maskable'
},
{
src: 'app_icons/web/icon-512.png',
sizes: '512x512',
type: 'image/png'
},
{
src: 'app_icons/web/icon-512-maskable.png',
sizes: '512x512',
type: 'image/png',
purpose: 'maskable'
}
],
screenshots: [
{
src: 'app_icons/web/screenshot-narrow.png',
sizes: '3510x7596',
type: 'image/png',
form_factor: 'narrow'
},
{
src: 'app_icons/web/screenshot-wide.png',
sizes: '7596x3510',
type: 'image/png',
form_factor: 'wide'
}
]
},
workbox: {
globPatterns: ['**/*.{js,css,svg,png,jpg,jpeg,gif,ico,woff,woff2}'], // Removed html from patterns
// Exclude large files from precaching and HTML files to avoid base path issues
globIgnores: ['**/app_preview.*', '**/presets/*.svg', '**/*.html', '**/config.js'],
maximumFileSizeToCacheInBytes: 5 * 1024 * 1024, // 5MB limit
// Don't precache index.html to avoid base path issues
dontCacheBustURLsMatching: /\.\w{8}\./,
navigateFallback: null, // Disable navigate fallback to avoid issues
navigateFallbackDenylist: [/^\/_/, /\/[^/?]+\.[^/]+$/],
// Remove modifyURLPrefix as it's causing conflicts with the base path
runtimeCaching: [
{
urlPattern: ({ request }) => request.destination === 'document',
handler: 'NetworkFirst',
options: {
cacheName: 'pages',
expiration: {
maxEntries: 10,
maxAgeSeconds: 86400 // 1 day
}
}
}
]
},
devOptions: {
// enabled: true,
type: 'module'
}
})
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
}
}
})