mirror of https://github.com/bastienwirtz/homer
fix(dev-server): fix unparsable dummy-data fson file
parent
a941e94a3b
commit
308deb95e0
|
@ -1,5 +1,8 @@
|
||||||
import { VitePWA } from "vite-plugin-pwa";
|
import { VitePWA } from "vite-plugin-pwa";
|
||||||
import { fileURLToPath, URL } from "url";
|
import { fileURLToPath, URL } from "url";
|
||||||
|
import fs from "fs";
|
||||||
|
import path from "path";
|
||||||
|
import process from "process";
|
||||||
|
|
||||||
import { defineConfig } from "vite";
|
import { defineConfig } from "vite";
|
||||||
import vue from "@vitejs/plugin-vue";
|
import vue from "@vitejs/plugin-vue";
|
||||||
|
@ -11,6 +14,25 @@ export default defineConfig({
|
||||||
assetsDir: "resources",
|
assetsDir: "resources",
|
||||||
},
|
},
|
||||||
plugins: [
|
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(),
|
vue(),
|
||||||
VitePWA({
|
VitePWA({
|
||||||
registerType: "autoUpdate",
|
registerType: "autoUpdate",
|
||||||
|
|
Loading…
Reference in New Issue