Skip to content

Commit 308deb9

Browse files
committed
fix(dev-server): fix unparsable dummy-data fson file
1 parent a941e94 commit 308deb9

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

vite.config.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { VitePWA } from "vite-plugin-pwa";
22
import { fileURLToPath, URL } from "url";
3+
import fs from "fs";
4+
import path from "path";
5+
import process from "process";
36

47
import { defineConfig } from "vite";
58
import vue from "@vitejs/plugin-vue";
@@ -11,6 +14,25 @@ export default defineConfig({
1114
assetsDir: "resources",
1215
},
1316
plugins: [
17+
// Custom plugin to serve dummy-data JSON files without sourcemap injection
18+
{
19+
name: "dummy-data-json-handler",
20+
configureServer(server) {
21+
server.middlewares.use((req, res, next) => {
22+
if (req.url?.startsWith("/dummy-data/")) {
23+
// Remove query parameters from URL to get the actual file path
24+
const urlWithoutQuery = req.url.split("?")[0];
25+
const filePath = path.join(process.cwd(), urlWithoutQuery);
26+
27+
if (fs.existsSync(filePath) && fs.statSync(filePath).isFile()) {
28+
res.end(fs.readFileSync(filePath, "utf8"));
29+
return;
30+
}
31+
}
32+
next();
33+
});
34+
},
35+
},
1436
vue(),
1537
VitePWA({
1638
registerType: "autoUpdate",

0 commit comments

Comments
 (0)