fix: revert base path injection in mpaHtmlPlugin to fix build resolution
Build and Deploy / build-and-deploy (push) Successful in 1m36s

Vite handles the base path automatically for absolute paths in HTML. Pre-pending it in the plugin caused Rollup to fail during asset resolution.
This commit is contained in:
2026-05-17 20:35:54 -07:00
parent 22a1020d15
commit 0639583a6d
+5 -5
View File
@@ -42,7 +42,8 @@ function getHtmlEntries() {
} }
// Vite plugin to rewrite HTML absolute assets to be subfolder-scoped // 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 { return {
name: 'mpa-html-plugin', name: 'mpa-html-plugin',
transformIndexHtml: { transformIndexHtml: {
@@ -53,7 +54,7 @@ const mpaHtmlPlugin = (base = '/') => {
const subfolder = parts[0]; const subfolder = parts[0];
let transformed = html 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) => { .replace(/(src|href)="\/([^"]+)"/g, (match, attr, path) => {
if (path.startsWith('http://') || path.startsWith('https://')) { if (path.startsWith('http://') || path.startsWith('https://')) {
return match; return match;
@@ -61,8 +62,7 @@ const mpaHtmlPlugin = (base = '/') => {
if (path.startsWith(subfolder)) { if (path.startsWith(subfolder)) {
return match; return match;
} }
const prefix = base === '/' ? '' : base.replace(/\/$/, ''); return `${attr}="/${subfolder}/${path}"`;
return `${attr}="${prefix}/${subfolder}/${path}"`;
}); });
// Clean up platform-specific non-module scripts like capacitor.js which fail Vite build // Clean up platform-specific non-module scripts like capacitor.js which fail Vite build
@@ -158,7 +158,7 @@ const externalizeMissingPlugin = () => {
export default defineConfig({ export default defineConfig({
base: '/lit-examples/', base: '/lit-examples/',
plugins: [mpaHtmlPlugin('/lit-examples/'), tsResolvePlugin(), externalizeMissingPlugin()], plugins: [mpaHtmlPlugin(), tsResolvePlugin(), externalizeMissingPlugin()],
resolve: { resolve: {
alias: { alias: {
'lit/decorators': 'lit/decorators.js', 'lit/decorators': 'lit/decorators.js',