[TASK] Revert to simple replace
This commit is contained in:
parent
b943b1d69c
commit
a766364cf3
22
index.js
22
index.js
@ -23,33 +23,15 @@ HtmlWebpackAlterDataPlugin.prototype.apply = function (compiler) {
|
|||||||
var manifest = JSON.parse(
|
var manifest = JSON.parse(
|
||||||
compilation.assets[this.options.manifestFilename]._value
|
compilation.assets[this.options.manifestFilename]._value
|
||||||
);
|
);
|
||||||
//callback();
|
|
||||||
//return;
|
|
||||||
for (var basename in compilation.assets) {
|
for (var basename in compilation.assets) {
|
||||||
var result = compilation.assets[basename].source();
|
var result = compilation.assets[basename].source();
|
||||||
if (typeof result == 'string') {
|
if (typeof result == 'string') {
|
||||||
var root = parse(result);
|
|
||||||
var nodes = root.querySelectorAll('svg use');
|
|
||||||
if (!nodes) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
for (var i = 0; i < nodes.length; i++) {
|
|
||||||
var node = nodes[i];
|
|
||||||
var attribute = node.getAttribute('xlink:href');
|
|
||||||
if (!attribute) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
var attributeReplace = attribute;
|
|
||||||
for (var [source, target] of Object.entries(manifest)) {
|
for (var [source, target] of Object.entries(manifest)) {
|
||||||
attributeReplace = attributeReplace.replace(
|
result = result.replace(
|
||||||
this.options.assetPrefix + source + '#',
|
new RegExp(this.options.assetPrefix + source + '#', 'g'),
|
||||||
target + '#',
|
target + '#',
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
// Just use replace as using html pasrser to set attribute breaks the
|
|
||||||
// js module escaping
|
|
||||||
result = result.replace(attribute, attributeReplace);
|
|
||||||
}
|
|
||||||
compilation.assets[basename] = new RawSource(result);
|
compilation.assets[basename] = new RawSource(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user