[英]Vite serving shader file with wrong (none) MIME type
我正在开发一个 BabylonJS 应用程序。 BabylonJS PostProcess class 将.fragment.fx
附加到给定的文件名并从服务器请求它。 当我的本地 Vite(版本 4.0.4)开发服务器提供此文件时, content-type
header 为空。 这导致 Firefox 将其解释为类型xml
并失败。 Chrome 通过不同但我认为相关的机制失败。
如何配置 Vite 以text/plain
格式提供*.fragment.fx
static 文件? 我假设我需要禁用默认中间件并改为编写一些自定义代码,如下所示: https://vitejs.dev/config/server-options.html#server-middlewaremode但我想先检查没有别的东西继续/配置/修复此问题的更简单方法。
vite dev server 使用vite --host --port 3000 --force
启动, vite.config.js
中的配置为:
import { defineConfig } from 'vite';
export default defineConfig(({ command, mode }) => {
// if (command === 'serve') {
// return {
// // dev specific config
// }
// } else {
// // command === 'build'
// return {
// // build specific config
// }
// }
return {
resolve: {
alias: {
"babylonjs": mode === "development" ? "babylonjs/babylon.max" : "babylonjs",
}
},
base: "",
// assetsInclude: ['**/*.fx'],
};
});
* 编辑 1 *
我已经看到有一个 参数?raw
可以添加到 URL 但是我不控制 BabylonJS forms URL 的方式,所以我看不到如何在这种情况下进行这项工作。
我按照这些说明使用 express 设置了一个开发服务器。 我在调用app.use(vite.middlewares)
的上方添加了这段代码:
app.use("**/*.*.fx", async (req, res, next) => {
const url = req.originalUrl
const file_path = path.resolve(__dirname, "." + url)
const file = fs.readFileSync(file_path, "utf-8")
res.status(200).set({ "Content-Type": "text/plain" }).end(file)
})
我现在使用"dev": "node server",
我找不到通过配置默认的 vite 开发服务器来解决这个问题的方法。
问题未解决?试试以下方法:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.