Compare commits
No commits in common. "master" and "b943b1d69cc81c655c9d920762c627f84a1239c2" have entirely different histories.
master
...
b943b1d69c
22
index.js
22
index.js
@ -23,15 +23,33 @@ 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)) {
|
||||||
result = result.replace(
|
attributeReplace = attributeReplace.replace(
|
||||||
new RegExp(this.options.assetPrefix + source + '#', 'g'),
|
this.options.assetPrefix + source + '#',
|
||||||
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