Update the logic of assets path.
This commit is contained in:
@@ -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 }) => ({
|
const copyServerFilesPlugin = ({ sourceDir, outDir }) => ({
|
||||||
name: 'copy-bridgeable-server-files',
|
name: 'copy-bridgeable-server-files',
|
||||||
buildStart() {
|
buildStart() {
|
||||||
@@ -59,6 +89,7 @@ const copyServerFilesPlugin = ({ sourceDir, outDir }) => ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
normalizeScssManifestEntries(outDir);
|
normalizeScssManifestEntries(outDir);
|
||||||
|
normalizeCssAssetUrls(outDir);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user