From 0639583a6dc701341cb6feef29cb134d57d1dc04 Mon Sep 17 00:00:00 2001 From: Rody Davis Date: Sun, 17 May 2026 20:35:54 -0700 Subject: [PATCH] fix: revert base path injection in mpaHtmlPlugin to fix build resolution Vite handles the base path automatically for absolute paths in HTML. Pre-pending it in the plugin caused Rollup to fail during asset resolution. --- vite.config.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/vite.config.js b/vite.config.js index 0273086..b909666 100644 --- a/vite.config.js +++ b/vite.config.js @@ -42,7 +42,8 @@ function getHtmlEntries() { } // Vite plugin to rewrite HTML absolute assets to be subfolder-scoped -const mpaHtmlPlugin = (base = '/') => { +// Vite plugin to rewrite HTML absolute assets to be subfolder-scoped +const mpaHtmlPlugin = () => { return { name: 'mpa-html-plugin', transformIndexHtml: { @@ -53,7 +54,7 @@ const mpaHtmlPlugin = (base = '/') => { const subfolder = parts[0]; let transformed = html - // Rewrite absolute src/href paths like "/src/main.ts" to "/base/subfolder/src/main.ts" + // Rewrite absolute src/href paths like "/src/main.ts" to "/subfolder/src/main.ts" .replace(/(src|href)="\/([^"]+)"/g, (match, attr, path) => { if (path.startsWith('http://') || path.startsWith('https://')) { return match; @@ -61,8 +62,7 @@ const mpaHtmlPlugin = (base = '/') => { if (path.startsWith(subfolder)) { return match; } - const prefix = base === '/' ? '' : base.replace(/\/$/, ''); - return `${attr}="${prefix}/${subfolder}/${path}"`; + return `${attr}="/${subfolder}/${path}"`; }); // Clean up platform-specific non-module scripts like capacitor.js which fail Vite build @@ -158,7 +158,7 @@ const externalizeMissingPlugin = () => { export default defineConfig({ base: '/lit-examples/', - plugins: [mpaHtmlPlugin('/lit-examples/'), tsResolvePlugin(), externalizeMissingPlugin()], + plugins: [mpaHtmlPlugin(), tsResolvePlugin(), externalizeMissingPlugin()], resolve: { alias: { 'lit/decorators': 'lit/decorators.js',