vite渲染时,本地资源必须要用符合vite的方式引入,不常见的格式需要手动配置
在vite.config.js文件中加入配置.glb文件即可:assetsInclude: ['**/*.glb'], // 明确包含GLB文件
具体代码:
vite.config.js:
import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
],
assetsInclude: ['**/*.glb'], // 明确包含GLB文件
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
},
chainWebpack: config => {
config.module
.rule('glb')
.test(/\.(glb|gltf)$/)
.use('file-loader')
.loader('file-loader')
.end();
},
server: {
https: false,
// host: "0.0.0.0",
port: 9001,
open: true,
cors: true,
strictPort: false,
proxy: {
'/api': {
target: 'http://1.117.236.127',
changeOrigin: true,
rewrite: (path) => path.replace("/api", "")
},
'/hy': {
target: 'http://192.168.110.90:9097',
changeOrigin: true,
rewrite: (path) => path.replace("/hy", "")
}
}
},
})