feat: 更新 Vite 配置,优化资源管理和背景图像处理

This commit is contained in:
zhongyidian committed 2025-09-14 20:44:41 +08:00
1 parent 66842e9d58
commit 02ddfd0c07
11 files changed
+202 -11

No files matched your search

+13 -1
View File
@@ -1,4 +1,9 @@
//访问静态图片
// 图片资源映射 - 使用静态导入确保构建时包含所有图片
const imageModules = import.meta.glob('../assets/images/**/*.{png,jpg,jpeg,gif,svg,webp}', {
eager: true
})
//访问静态图片 - 使用静态导入确保构建后路径正确
export const getStaticImage = (path: string) => {
try {
// 确保路径以正确的格式结尾
@@ -12,6 +17,13 @@ export const getStaticImage = (path: string) => {
? `../assets/images/${path}`
: `../assets/images/${path}.png`
// 使用静态导入的模块
const module = imageModules[imagePath]
if (module && typeof module === 'object' && 'default' in module) {
return module.default as string
}
// 回退到URL方式
return new URL(imagePath, import.meta.url).href
} catch (error) {
console.error('Failed to load image:', path, error)