Files
Code-Create/vite.config.ts

57 lines
1.5 KiB
TypeScript
Raw Normal View History

2026-05-14 09:53:22 +08:00
import type { UserConfig } from 'vite'
import type { ViteSSGOptions } from 'vite-ssg'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import generateSitemap from 'vite-ssg-sitemap'
2026-05-14 13:08:29 +08:00
import { fileURLToPath, URL } from 'node:url'
2026-05-14 09:53:22 +08:00
// https://vite.dev/config/
const config = {
2026-05-19 10:36:33 +08:00
ssg: {
// 静默所有警告
silent: true,
// 或者只忽略特定警告
onWarning: (warning, message) => {
// 忽略 ResizeObserver 和 localStorage 相关警告
if (message.includes('ResizeObserver')) {
return;
}
console.warn(warning);
}
},
// 全局定义模拟对象
define: {
'ResizeObserver': 'typeof ResizeObserver !== "undefined" ? ResizeObserver : class ResizeObserver { observe() {} unobserve() {} disconnect() {} }',
},
2026-05-14 09:53:22 +08:00
base: '/',
plugins: [vue()],
2026-05-14 15:10:57 +08:00
ssr: {
noExternal: ['@kagol/vue-carousel']
},
2026-05-14 09:53:22 +08:00
ssgOptions: {
2026-05-19 10:36:33 +08:00
mock: true,
2026-05-14 09:53:22 +08:00
dirStyle: 'nested',
script: 'defer',
onFinished() {
generateSitemap({
// 1. 必填:你官网部署后的正式域名。
// 生成的 sitemap.xml 里需要用这个域名 + 路由路径拼成完整 URL (如 https://site.com/about)
hostname: 'https://your-website.com/',
// 2. 扫描目录:通常是打包后的输出目录
outDir: 'dist'
})
}
2026-05-14 13:08:29 +08:00
},
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
_c: fileURLToPath(new URL('./src/components', import.meta.url))
}
},
2026-05-14 09:53:22 +08:00
} satisfies UserConfig & { ssgOptions: ViteSSGOptions }
export default defineConfig(config)