Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep viewBox when dimensions are removed #281

Merged
merged 1 commit into from
Mar 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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