Skip to content

Commit

Permalink
Merge pull request #98 from vadymshymko/add-plugin-options
Browse files Browse the repository at this point in the history
Add plugin options
  • Loading branch information
vadymshymko authored Feb 3, 2024
2 parents c4940ee + 7c57492 commit ed4adcc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "svg-sprite-generation-loader",
"version": "2.0.18",
"version": "2.1.0",
"description": "Webpack loader for generating external svg symbol sprite files",
"main": "index.js",
"scripts": {
Expand Down
6 changes: 5 additions & 1 deletion plugin.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
const svgSpriteState = require('./utils/spriteState');

class SvgSpriteGeneratorPlugin {
constructor(params) {
this.params = params;
}

// eslint-disable-next-line class-methods-use-this
apply(compiler) {
// webpack module instance can be accessed from the compiler object,
Expand All @@ -22,7 +26,7 @@ class SvgSpriteGeneratorPlugin {
Object.keys(svgSpriteState.sprites).forEach((spriteFilePath) => {
compilation.emitAsset(
spriteFilePath,
new RawSource(svgSpriteState.getSpriteContent(spriteFilePath))
new RawSource(svgSpriteState.getSpriteContent(spriteFilePath, this.params))
);
});
}
Expand Down
4 changes: 2 additions & 2 deletions utils/spriteState.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ class SvgSpriteGenerationState {
this.sprites[spriteFilePath][icon.symbolId] = icon;
}

getSpriteContent(spriteFilePath) {
getSpriteContent(spriteFilePath, options = {}) {
return `${Object.keys(this.sprites[spriteFilePath]).reduce(
(result, iconId) =>
`${result}<symbol viewBox="${this.sprites[spriteFilePath][iconId].attributes.viewBox}" fill="none" id="${iconId}">${this.sprites[spriteFilePath][iconId].content}</symbol>`,
`${result}<symbol viewBox="${this.sprites[spriteFilePath][iconId].attributes.viewBox}"${options.unsetSymbolFill ? '' : ' fill="none"'} id="${iconId}">${this.sprites[spriteFilePath][iconId].content}</symbol>`,
'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">'
)}</svg>`;
}
Expand Down

0 comments on commit ed4adcc

Please sign in to comment.