Skip to content
This repository has been archived by the owner on Oct 9, 2020. It is now read-only.

Use loader context for loader interpolation #83

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ var regexSequences = [
[/\> \</g, "><"] // remove whitespace between tags
];

function getExtractedSVG(svgStr, query) {
function getExtractedSVG(loaderContext, svgStr, query) {
var config;
// interpolate hashes in classPrefix
if(!!query) {
config = assign({}, query);

if (!!config.classPrefix) {
const name = config.classPrefix === true ? '__[hash:base64:7]__' : config.classPrefix;
config.classPrefix = loaderUtils.interpolateName({}, name, { content: svgStr });
config.classPrefix = loaderUtils.interpolateName(loaderContext, name, { content: svgStr });
}

if (!!config.idPrefix) {
const id_name = config.idPrefix === true ? '__[hash:base64:7]__' : config.idPrefix;
config.idPrefix = loaderUtils.interpolateName({}, id_name, { content: svgStr });
config.idPrefix = loaderUtils.interpolateName(loaderContext, id_name, { content: svgStr });
}
}

Expand Down Expand Up @@ -62,7 +62,7 @@ function SVGInlineLoader(content) {
// Configuration
var query = loaderUtils.parseQuery(this.query);

return "module.exports = " + JSON.stringify(getExtractedSVG(content, query));
return "module.exports = " + JSON.stringify(getExtractedSVG(this, content, query));
}

SVGInlineLoader.getExtractedSVG = getExtractedSVG;
Expand Down