We are currently facing the issue that icons paths for external sprites are not getting replaced.
What is the expected behavior?
The svg url should be replaced with the correct one.
also overwriting _valueAsString will fix the issue:
function replaceInModuleSource(module, replacements) {
const source = module._source;
if (typeof source === 'string') {
module._source = replaceSpritePlaceholder(source, replacements);
} else if (typeof source === 'object' && typeof source._value === 'string') {
source._value = replaceSpritePlaceholder(source._value, replacements);
// this fixes the issue
source._valueAsString = source._value;
// not needed now but who knows
source._valueAsBuffer = Buffer.from(source._value);
}
return module;
}
on top here is another improvement suggestion which is not mandatory. ;)
function replaceSpritePlaceholder(content, replacements) {
let result = content;
Object.keys(replacements)
.forEach((subj) => {
let re = new RegExp(escapeRegExpSpecialChars(subj), 'g');
result = result.replace(re, replacements[subj]);
if (isWindows) {
re = new RegExp(escapeRegExpSpecialChars(subj), 'g');
result = result.replace(/\\\\/g, '\\').replace(re, replacements[subj]);
}
});
return result;
What is the current behavior?
We are currently facing the issue that icons paths for external sprites are not getting replaced.
What is the expected behavior?
The svg url should be replaced with the correct one.
also overwriting _valueAsString will fix the issue:
on top here is another improvement suggestion which is not mandatory. ;)
this could be refactored to
this avoids the side effect of removing to many \ from the result.
Please tell us about your environment: