You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to run a folder of SVGs through svg-sprite in order to create a <symbol> sprite and also to make individual SVGs have uniform code by configuring the shape settings in the config. One of the things I want to be uniform is to remove any width and height attributes on the SVG tag so that they resize responsively. But no matter what I seem to do the width and height are being adding to the individual SVGs that the svg-sprite shape config outputs.
Here is my code:
constspriter=newSVGSpriter({log: true,dest: 'web/assets/icons',shape: {dimension: {attributes: false},spacing: {// Add paddingpadding: 0},id: {separator: '-'},dest: 'intermediate-svg',// Keep the intermediate filestransform: [{svgo: {plugins: [{name: 'preset-default',params: {overrides: {removeComments: false,removeViewBox: false},},},{name: 'removeAttrs',params: {attrs: '(fill|stroke|class|id|data-name|width|height)',},},'removeStyleElement','removeScriptElement','removeDimensions']}}]},svg: {xmlDeclaration: false,dimensionAttributes: false,},mode: {symbol: {inline: true,example: true},view: true,stack: true}});constcwd=path.resolve('src');varicon_files=glob.sync('icons/**/*.svg',{ cwd });for(constfileoficon_files){// Create and add a vinyl file instance for each SVGspriter.add(new_File({path: path.join(cwd,file),// Absolute path to the SVG filebase: cwd,// Base path (see `name` argument)contents: fs.readFileSync(path.join(cwd,file))// SVG file contents}));}spriter.compile((error,result,data)=>{for(varmodeinresult){for(varresourceinresult[mode]){fs.mkdirSync(path.dirname(result[mode][resource].path),{recursive: true});fs.writeFileSync(result[mode][resource].path,result[mode][resource].contents);}}});
Here is an example of a SVG before it is ran through svg-sprite:
Notice how the output has a width and height even though my config for svg-sprite contains svg.dimensionAttributes = false. Unless I'm misunderstanding something about how this works, but i would think that that would mean that the width and height shouldn't be added to the output.
(Also, you'll notice that I set shape.dimension.attribute to false even though i think that was deprecated, because I was just trying anything to keep the output from containing the width and height attributes.)
I am trying to run a folder of SVGs through svg-sprite in order to create a
<symbol>
sprite and also to make individual SVGs have uniform code by configuring theshape
settings in the config. One of the things I want to be uniform is to remove anywidth
andheight
attributes on the SVG tag so that they resize responsively. But no matter what I seem to do thewidth
andheight
are being adding to the individual SVGs that the svg-spriteshape
config outputs.Here is my code:
Here is an example of a SVG before it is ran through svg-sprite:
Here it is afterwards:
Notice how the output has a
width
andheight
even though my config forsvg-sprite
containssvg.dimensionAttributes = false
. Unless I'm misunderstanding something about how this works, but i would think that that would mean that thewidth
andheight
shouldn't be added to the output.(Also, you'll notice that I set
shape.dimension.attribute
to false even though i think that was deprecated, because I was just trying anything to keep the output from containing the width and height attributes.)Versions
svg-sprite version: 2.0.2
node js version: 16.13.1
The text was updated successfully, but these errors were encountered: