Update the logic of assets path.

This commit is contained in:
2026-05-05 18:31:23 -06:00
parent 512e70c033
commit 8055a15ea3
+31
View File
@@ -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);
}
});