Skip to content

Commit 19b2ede

Browse files
authored
Fix compound external assets path in bundle (#26069)
1 parent 3fd6b62 commit 19b2ede

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

webpack.config.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,7 @@ function getAssetOutputPath(url, resourcePath) {
733733
// `res` is the parent dir for our own assets in various layers
734734
// `dist` is the parent dir for KaTeX assets
735735
const prefix = /^.*[/\\](dist|res)[/\\]/;
736+
736737
/**
737738
* Only needed for https://github.com/vector-im/element-web/pull/15939
738739
* If keeping this, we are not able to load external assets such as SVG
@@ -742,6 +743,21 @@ function getAssetOutputPath(url, resourcePath) {
742743
throw new Error(`Unexpected asset path: ${resourcePath}`);
743744
}
744745
let outputDir = path.dirname(resourcePath).replace(prefix, "");
746+
747+
/**
748+
* Imports from Compound are "absolute", we need to strip out the prefix
749+
* coming before the npm package name.
750+
*
751+
* This logic is scoped to compound packages for now as they are the only
752+
* package that imports external assets. This might need to be made more
753+
* generic in the future
754+
*/
755+
const compoundImportsPrefix = /@vector-im(?:\\|\/)compound-(.*?)(?:\\|\/)/;
756+
const compoundMatch = outputDir.match(compoundImportsPrefix);
757+
if (compoundMatch) {
758+
outputDir = outputDir.substring(compoundMatch.index + compoundMatch[0].length);
759+
}
760+
745761
if (isKaTeX) {
746762
// Add a clearly named directory segment, rather than leaving the KaTeX
747763
// assets loose in each asset type directory.

0 commit comments

Comments
 (0)