Skip to content

Commit

Permalink
fix: keep viewBox when dimensions are removed (#281)
Browse files Browse the repository at this point in the history
  • Loading branch information
adipascu authored and gregberge committed Mar 10, 2019
1 parent 31cb597 commit f476c8e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/cli/src/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ exports[`cli should support various args: --no-dimensions 1`] = `
"import React from 'react'
const SvgFile = props => (
<svg {...props}>
<svg viewBox=\\"0 0 48 1\\" {...props}>
<path d=\\"M0 0h48v1H0z\\" fill=\\"#063855\\" fillRule=\\"evenodd\\" />
</svg>
)
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/__snapshots__/convert.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exports[`convert config should support options { dimensions: false } 1`] = `
"import React from 'react'
const SvgComponent = props => (
<svg {...props}>
<svg viewBox=\\"0 0 88 88\\" {...props}>
<g
stroke=\\"#063855\\"
strokeWidth={2}
Expand Down
2 changes: 2 additions & 0 deletions packages/plugin-svgo/src/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ exports[`svgo should not load runtime configuration with \`runtimeConfig: false\
exports[`svgo should not remove viewBox with icon option 1`] = `"<svg width=\\"88\\" height=\\"88\\" viewBox=\\"0 0 88 88\\" xmlns=\\"http://www.w3.org/2000/svg\\"><g id=\\"svgo__Blocks\\" stroke=\\"none\\" stroke-width=\\"1\\" fill=\\"none\\" fill-rule=\\"evenodd\\" stroke-linecap=\\"square\\"><g id=\\"svgo__Dismiss\\" stroke=\\"#063855\\" stroke-width=\\"2\\"><path d=\\"M51 37L37 51\\" id=\\"svgo__Shape\\"/><path d=\\"M51 51L37 37\\"/><style></style></g></g></svg>"`;
exports[`svgo should not remove viewBox with when dimensions is false 1`] = `"<svg width=\\"88\\" height=\\"88\\" viewBox=\\"0 0 88 88\\" xmlns=\\"http://www.w3.org/2000/svg\\"><g id=\\"svgo__Blocks\\" stroke=\\"none\\" stroke-width=\\"1\\" fill=\\"none\\" fill-rule=\\"evenodd\\" stroke-linecap=\\"square\\"><g id=\\"svgo__Dismiss\\" stroke=\\"#063855\\" stroke-width=\\"2\\"><path d=\\"M51 37L37 51\\" id=\\"svgo__Shape\\"/><path d=\\"M51 51L37 37\\"/><style></style></g></g></svg>"`;
exports[`svgo should optimize svg 1`] = `"<svg width=\\"88\\" height=\\"88\\" xmlns=\\"http://www.w3.org/2000/svg\\"><g id=\\"prefix__Blocks\\" stroke=\\"none\\" stroke-width=\\"1\\" fill=\\"none\\" fill-rule=\\"evenodd\\" stroke-linecap=\\"square\\"><g id=\\"prefix__Dismiss\\" stroke=\\"#063855\\" stroke-width=\\"2\\"><path d=\\"M51 37L37 51\\" id=\\"prefix__Shape\\"/><path d=\\"M51 51L37 37\\"/><style></style></g></g></svg>"`;
exports[`svgo should support config.svgoConfig 1`] = `"<svg width=\\"88\\" height=\\"88\\" xmlns=\\"http://www.w3.org/2000/svg\\"><desc>Created with Sketch.</desc><g id=\\"prefix__Blocks\\" stroke=\\"none\\" stroke-width=\\"1\\" fill=\\"none\\" fill-rule=\\"evenodd\\" stroke-linecap=\\"square\\"><g id=\\"prefix__Dismiss\\" stroke=\\"#063855\\" stroke-width=\\"2\\"><path d=\\"M51 37L37 51\\" id=\\"prefix__Shape\\"/><path d=\\"M51 51L37 37\\"/><style></style></g></g></svg>"`;
Expand Down
3 changes: 2 additions & 1 deletion packages/plugin-svgo/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ function getBaseSvgoConfig(config) {
const baseSvgoConfig = {
plugins: [{ prefixIds: true }],
}
if (config.icon) baseSvgoConfig.plugins.push({ removeViewBox: false })
if (config.icon || config.dimensions === false)
baseSvgoConfig.plugins.push({ removeViewBox: false })
return baseSvgoConfig
}

Expand Down
10 changes: 10 additions & 0 deletions packages/plugin-svgo/src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ describe('svgo', () => {
expect(result).toMatchSnapshot()
})

it('should not remove viewBox with when dimensions is false', () => {
const result = svgo(
baseSvg,
{ svgo: true, dimensions: false, runtimeConfig: true },
{ filePath: path.join(__dirname, '../__fixtures__/svgo') },
)

expect(result).toMatchSnapshot()
})

it('should be possible to disable id prefixing', () => {
const result = svgo(
baseSvg,
Expand Down

1 comment on commit f476c8e

@vercel
Copy link

@vercel vercel bot commented on f476c8e Mar 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully aliased the URL https://svgr-bxkpqpxzgw.now.sh to the following alias.

Please sign in to comment.