Files
EmailBill/Web/vite.config.js

119 lines
3.0 KiB
JavaScript
Raw Normal View History

2025-12-25 11:20:56 +08:00
import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'
import { VitePWA } from 'vite-plugin-pwa'
2025-12-25 11:20:56 +08:00
// https://vite.dev/config/
export default defineConfig({
plugins: [
vue(),
vueDevTools(),
VitePWA({
strategies: 'injectManifest',
srcDir: 'src',
filename: 'sw.js',
registerType: 'prompt', // 使用提示模式,以便在 App.vue 中显示刷新按钮
injectRegister: 'auto',
manifest: {
name: '账单',
short_name: '账单',
description: '个人账单管理与邮件解析',
start_url: '/',
display: 'standalone',
background_color: '#ffffff',
theme_color: '#1989fa',
orientation: 'portrait-primary',
icons: [
{
src: 'icons/icon-72x72.svg',
sizes: '72x72',
type: 'image/svg+xml',
purpose: 'any maskable'
},
{
src: 'icons/icon-96x96.svg',
sizes: '96x96',
type: 'image/svg+xml',
purpose: 'any maskable'
},
{
src: 'icons/icon-128x128.svg',
sizes: '128x128',
type: 'image/svg+xml',
purpose: 'any maskable'
},
{
src: 'icons/icon-144x144.svg',
sizes: '144x144',
type: 'image/svg+xml',
purpose: 'any maskable'
},
{
src: 'icons/icon-152x152.svg',
sizes: '152x152',
type: 'image/svg+xml',
purpose: 'any maskable'
},
{
src: 'icons/icon-192x192.svg',
sizes: '192x192',
type: 'image/svg+xml',
purpose: 'any maskable'
},
{
src: 'icons/icon-384x384.svg',
sizes: '384x384',
type: 'image/svg+xml',
purpose: 'any maskable'
},
{
src: 'icons/icon-512x512.svg',
sizes: '512x512',
type: 'image/svg+xml',
purpose: 'any maskable'
}
],
shortcuts: [
{
name: '查看账单',
short_name: '账单',
description: '快速查看账单列表',
url: '/',
icons: [
{
src: 'icons/icon-96x96.png',
sizes: '96x96'
}
]
}
]
},
devOptions: {
enabled: true,
type: 'module'
}
})
2025-12-25 11:20:56 +08:00
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
},
},
2025-12-25 14:15:43 +08:00
build: {
// 确保 Service Worker 和 manifest 被正确复制
rollupOptions: {
input: {
main: fileURLToPath(new URL('./index.html', import.meta.url))
}
}
},
server: {
headers: {
// 允许 Service Worker 在开发环境中工作
'Service-Worker-Allowed': '/'
}
}
2025-12-25 11:20:56 +08:00
})