Files
Code-Create/vite.config.ts
X1627315083@163.com 55cc4cb40f fix
2026-05-19 10:36:33 +08:00

57 lines
1.5 KiB
TypeScript

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'
import { fileURLToPath, URL } from 'node:url'
// https://vite.dev/config/
const config = {
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() {} }',
},
base: '/',
plugins: [vue()],
ssr: {
noExternal: ['@kagol/vue-carousel']
},
ssgOptions: {
mock: true,
dirStyle: 'nested',
script: 'defer',
onFinished() {
generateSitemap({
// 1. 必填:你官网部署后的正式域名。
// 生成的 sitemap.xml 里需要用这个域名 + 路由路径拼成完整 URL (如 https://site.com/about)
hostname: 'https://your-website.com/',
// 2. 扫描目录:通常是打包后的输出目录
outDir: 'dist'
})
}
},
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
_c: fileURLToPath(new URL('./src/components', import.meta.url))
}
},
} satisfies UserConfig & { ssgOptions: ViteSSGOptions }
export default defineConfig(config)