From 85ef1e4e441b27f634ce069c171b6b1e37237391 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Sun, 27 Sep 2026 18:08:58 +0000 Subject: [PATCH] fix(vite): pass renderer template path to transformIndexHtml Vite derives the HTML filename from the URL, so passing "/" made relative imports in inline + + +

html template

+ + diff --git a/test/vite/html-template-fixture/src/style.css b/test/vite/html-template-fixture/src/style.css new file mode 100644 index 0000000000..e9a20421be --- /dev/null +++ b/test/vite/html-template-fixture/src/style.css @@ -0,0 +1,3 @@ +.imported-style { + color: rebeccapurple; +} diff --git a/test/vite/html-template-fixture/vite.config.ts b/test/vite/html-template-fixture/vite.config.ts new file mode 100644 index 0000000000..dc884054e6 --- /dev/null +++ b/test/vite/html-template-fixture/vite.config.ts @@ -0,0 +1,6 @@ +import { defineConfig } from "vite"; +import { nitro } from "nitro/vite"; + +export default defineConfig({ + plugins: [nitro()], +}); diff --git a/test/vite/html-template.test.ts b/test/vite/html-template.test.ts new file mode 100644 index 0000000000..8fe7b91b0d --- /dev/null +++ b/test/vite/html-template.test.ts @@ -0,0 +1,39 @@ +import { fileURLToPath } from "node:url"; +import type { ViteDevServer } from "vite"; +import { beforeAll, afterAll, describe, expect, test } from "vitest"; + +const { createServer } = (await import( + process.env.NITRO_VITE_PKG || "vite" +)) as typeof import("vite"); + +describe("vite:html template", () => { + let server: ViteDevServer; + let serverURL: string; + + const rootDir = fileURLToPath(new URL("./html-template-fixture", import.meta.url)); + + beforeAll(async () => { + server = await createServer({ root: rootDir, logLevel: "warn" }); + await server.listen("0" as unknown as number); + const addr = server.httpServer?.address() as { + port: number; + address: string; + family: string; + }; + serverURL = `http://${addr.family === "IPv6" ? `[${addr.address}]` : addr.address}:${addr.port}`; + }, 30_000); + + afterAll(async () => { + await server?.close(); + }); + + // Relative imports in inline `