Skip to content

Commit

Permalink
Keep viewBox when dimensions are removed
Browse files Browse the repository at this point in the history
  • Loading branch information
adipascu committed Mar 8, 2019
1 parent 31cb597 commit aa3d7d9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
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[`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 || !opts.dimensions)
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

0 comments on commit aa3d7d9

Please sign in to comment.