vladshcherbin / rollup-plugin-svg-sprite

Create external svg sprite file from your bundle using Rollup
21 stars 5 forks source link

Use height and width attrs when viewBox is not present #5

Open e-pavlica opened 4 years ago

e-pavlica commented 4 years ago

Some of the older SVGs that our application uses were exported were exported with a height and width, but no viewBox causing this plugin to break. The "correct" way to fix this problem would be to correct the SVG sources, but that was not something I wanted to pursue.

As a non-perfect fallback for this situation, use the height and width attributes to construct a viewBox string so that compilation can continue.

I didn't add a test for this as I was reluctant to add another fixture to the repo, but can if you prefer.

I also thought about adding a console warning for SVGs missing the viewBox attr but thought that might just be annoying/heavy-handed.

codecov[bot] commented 4 years ago

Codecov Report

Merging #5 into master will not change coverage. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master        #5   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            1         1           
  Lines           29        30    +1     
  Branches         6         7    +1     
=========================================
+ Hits            29        30    +1     
Impacted Files Coverage Δ
src/index.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update f00ef0a...3deed80. Read the comment docs.