From a766364cf3214328203fb69b2830aedb8245d671 Mon Sep 17 00:00:00 2001 From: Philipp Dieter Date: Mon, 2 May 2022 18:29:19 +0200 Subject: [PATCH] [TASK] Revert to simple replace --- index.js | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/index.js b/index.js index 95e8344..ad1c3a9 100644 --- a/index.js +++ b/index.js @@ -23,32 +23,14 @@ HtmlWebpackAlterDataPlugin.prototype.apply = function (compiler) { var manifest = JSON.parse( compilation.assets[this.options.manifestFilename]._value ); - //callback(); - //return; for (var basename in compilation.assets) { var result = compilation.assets[basename].source(); 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)) { - attributeReplace = attributeReplace.replace( - this.options.assetPrefix + source + '#', - target + '#', - ) - } - // Just use replace as using html pasrser to set attribute breaks the - // js module escaping - result = result.replace(attribute, attributeReplace); + for (var [source, target] of Object.entries(manifest)) { + result = result.replace( + new RegExp(this.options.assetPrefix + source + '#', 'g'), + target + '#', + ) } compilation.assets[basename] = new RawSource(result); }