From 5e0a4c43e6f2ca82510a65fd6ffe04751f625dd9 Mon Sep 17 00:00:00 2001 From: Loi Nguyen Date: Thu, 30 Jul 2026 21:10:53 +0700 Subject: [PATCH] fix: respect custom base paths for built assets (#4879) --- assets/build.spec.ts | 24 ++++++++++++++++++++++++ vite.config.ts | 1 + 2 files changed, 25 insertions(+) create mode 100644 assets/build.spec.ts diff --git a/assets/build.spec.ts b/assets/build.spec.ts new file mode 100644 index 00000000..8e49e75d --- /dev/null +++ b/assets/build.spec.ts @@ -0,0 +1,24 @@ +import { build } from "vite"; +import { describe, expect, it } from "vitest"; + +describe("production build", () => { + it("emits font URLs relative to the generated stylesheet", async () => { + const result = await build({ + configFile: "vite.config.ts", + logLevel: "silent", + build: { write: false }, + }); + const outputs = Array.isArray(result) ? result : [result]; + const stylesheet = outputs + .flatMap((output) => ("output" in output ? output.output : [])) + .find((item) => item.type === "asset" && item.fileName.endsWith(".css")); + + expect(stylesheet).toBeDefined(); + if (!stylesheet || stylesheet.type !== "asset") { + throw new Error("Production build did not emit a stylesheet"); + } + const css = String(stylesheet.source); + expect(css).toMatch(/url\(\.\/jetbrains-mono/); + expect(css).not.toMatch(/url\(\/assets\/jetbrains-mono/); + }, 15_000); +}); diff --git a/vite.config.ts b/vite.config.ts index 9340c1a0..456de3be 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -13,6 +13,7 @@ import svgLoader from "vite-svg-loader"; import tailwindcss from "@tailwindcss/vite"; export default defineConfig(() => ({ + base: "./", define: { __CLOUD_URL__: JSON.stringify(process.env.CLOUD_URL || "https://cloud.dozzle.dev"), },