Files
OneMD/vite.config.js
T
2026-06-19 14:45:07 +08:00

64 lines
1.6 KiB
JavaScript

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { VitePWA } from 'vite-plugin-pwa'
import { readFileSync } from 'fs'
function getPostPaths() {
try {
const data = JSON.parse(readFileSync('./src/generated/posts-data.json', 'utf-8'))
return data.paths
} catch {
return []
}
}
export default defineConfig({
plugins: [
vue(),
VitePWA({
registerType: 'autoUpdate',
includeAssets: ['pwa-192x192.png', 'pwa-512x512.png'],
manifest: {
name: '知识指南',
short_name: '知识指南',
description: '个人知识库与技术博客',
theme_color: '#24292e',
background_color: '#ffffff',
display: 'standalone',
start_url: '/',
icons: [
{
src: 'pwa-192x192.png',
sizes: '192x192',
type: 'image/png',
purpose: 'any'
},
{
src: 'pwa-512x512.png',
sizes: '512x512',
type: 'image/png',
purpose: 'any maskable'
}
]
},
workbox: {
maximumFileSizeToCacheInBytes: 5 * 1024 * 1024,
globPatterns: ['**/*.{js,css,html,svg,png,ico,woff,woff2}'],
runtimeCaching: [
{
urlPattern: /^https:\/\/cdnjs\.cloudflare\.com\/.*/i,
handler: 'CacheFirst',
options: {
cacheName: 'cdn-cache',
expiration: { maxEntries: 10, maxAgeSeconds: 60 * 60 * 24 * 30 }
}
}
]
}
})
],
ssgOptions: {
includedRoutes: () => getPostPaths().map(p => `/post/${p}`)
}
})