Files
mengyanote/mengyanote-frontend/vite.config.js
2026-05-16 19:03:44 +08:00

90 lines
2.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { VitePWA } from 'vite-plugin-pwa'
export default defineConfig({
plugins: [
react(),
VitePWA({
registerType: 'autoUpdate', // 发现新版本时自动更新
includeAssets: ['logo.png'],
manifest: {
name: '萌芽笔记',
short_name: '萌芽笔记',
description: '萌芽笔记 - Markdown 笔记 PWA',
theme_color: '#1a1a2e',
background_color: '#16213e',
display: 'standalone',
orientation: 'portrait-primary',
scope: '/',
start_url: './',
icons: [
{
src: 'logo.png',
sizes: '192x192',
type: 'image/png',
purpose: 'any'
},
{
src: 'logo.png',
sizes: '512x512',
type: 'image/png',
purpose: 'any'
},
{
src: 'logo.png',
sizes: '192x192',
type: 'image/png',
purpose: 'maskable'
},
{
src: 'logo.png',
sizes: '512x512',
type: 'image/png',
purpose: 'maskable'
}
]
},
workbox: {
globPatterns: ['**/*.{js,css,html,ico,png,svg,woff2}'],
runtimeCaching: [
{
urlPattern: /^https?:\/\/.*\/api\/.*/i,
handler: 'NetworkFirst',
options: {
cacheName: 'api-cache',
expiration: { maxEntries: 32, maxAgeSeconds: 24 * 60 * 60 },
networkTimeoutSeconds: 10,
cacheableResponse: { statuses: [0, 200] }
}
}
]
},
devOptions: { enabled: true } // 开发时也启用 PWA 便于调试
})
],
base: '/', // 使用绝对路径,确保 SPA 路由(/note/...)下资源加载正确
server: {
host: '0.0.0.0', // 监听所有网络接口(包括局域网)
port: 5173, // 端口号可选默认5173
proxy: {
// 开发:将 /api 转到本机 FastAPI默认 uvicorn 端口 8000与 mengyanote-backend 一致)
'/api': {
target: 'http://127.0.0.1:8000',
changeOrigin: true,
}
}
},
preview: {
host: '0.0.0.0',
port: 4173,
proxy: {
// npm run preview同上本地联调后端
'/api': {
target: 'http://127.0.0.1:8000',
changeOrigin: true,
}
}
}
})