From 8055a15ea39064d39a9c7030f46ea330046b3fa2 Mon Sep 17 00:00:00 2001 From: Roman Axelrod Date: Tue, 5 May 2026 18:31:23 -0600 Subject: [PATCH] Update the logic of assets path. --- src/vite-config.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/vite-config.js b/src/vite-config.js index 378abbb..c477e03 100644 --- a/src/vite-config.js +++ b/src/vite-config.js @@ -35,6 +35,36 @@ const normalizeScssManifestEntries = (outDir) => { } }; +const normalizeCssAssetUrls = (outDir) => { + walkFiles(outDir, (absolutePath) => { + if (!absolutePath.endsWith('.css')) { + return; + } + + const cssDir = normalizePath(relative(outDir, dirname(absolutePath))); + if (!cssDir || cssDir === '.') { + return; + } + + const sameDirectoryAssetPrefix = `../${cssDir}/`; + const contents = readFileSync(absolutePath, 'utf8'); + const normalized = contents.replace( + /url\((['"]?)(?!data:|https?:|\/\/|\/)([^'")]+)\1\)/g, + (match, quote, assetUrl) => { + if (!assetUrl.startsWith(sameDirectoryAssetPrefix)) { + return match; + } + + return `url(${quote}${assetUrl.slice(sameDirectoryAssetPrefix.length)}${quote})`; + } + ); + + if (normalized !== contents) { + writeFileSync(absolutePath, normalized); + } + }); +}; + const copyServerFilesPlugin = ({ sourceDir, outDir }) => ({ name: 'copy-bridgeable-server-files', buildStart() { @@ -59,6 +89,7 @@ const copyServerFilesPlugin = ({ sourceDir, outDir }) => ({ }); normalizeScssManifestEntries(outDir); + normalizeCssAssetUrls(outDir); } });