fix(dev-server): fix unparsable dummy-data fson file

main
Bastien Wirtz 2025-08-17 17:26:37 +02:00
parent a941e94a3b
commit 308deb95e0
1 changed files with 22 additions and 0 deletions

View File

@ -1,5 +1,8 @@
import { VitePWA } from "vite-plugin-pwa";
import { fileURLToPath, URL } from "url";
import fs from "fs";
import path from "path";
import process from "process";
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
@ -11,6 +14,25 @@ export default defineConfig({
assetsDir: "resources",
},
plugins: [
// Custom plugin to serve dummy-data JSON files without sourcemap injection
{
name: "dummy-data-json-handler",
configureServer(server) {
server.middlewares.use((req, res, next) => {
if (req.url?.startsWith("/dummy-data/")) {
// Remove query parameters from URL to get the actual file path
const urlWithoutQuery = req.url.split("?")[0];
const filePath = path.join(process.cwd(), urlWithoutQuery);
if (fs.existsSync(filePath) && fs.statSync(filePath).isFile()) {
res.end(fs.readFileSync(filePath, "utf8"));
return;
}
}
next();
});
},
},
vue(),
VitePWA({
registerType: "autoUpdate",