From f476c8ec7e928efd5c11324bed95a8110214dc79 Mon Sep 17 00:00:00 2001 From: Adrian Pascu <1521321+adipascu@users.noreply.github.com> Date: Mon, 11 Mar 2019 00:54:39 +0200 Subject: [PATCH] fix: keep viewBox when dimensions are removed (#281) --- packages/cli/src/__snapshots__/index.test.js.snap | 2 +- packages/core/src/__snapshots__/convert.test.js.snap | 2 +- .../plugin-svgo/src/__snapshots__/index.test.js.snap | 2 ++ packages/plugin-svgo/src/index.js | 3 ++- packages/plugin-svgo/src/index.test.js | 10 ++++++++++ 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/__snapshots__/index.test.js.snap b/packages/cli/src/__snapshots__/index.test.js.snap index c2c8046b..d6f2ee71 100644 --- a/packages/cli/src/__snapshots__/index.test.js.snap +++ b/packages/cli/src/__snapshots__/index.test.js.snap @@ -218,7 +218,7 @@ exports[`cli should support various args: --no-dimensions 1`] = ` "import React from 'react' const SvgFile = props => ( - + ) diff --git a/packages/core/src/__snapshots__/convert.test.js.snap b/packages/core/src/__snapshots__/convert.test.js.snap index e23891ce..92f31af3 100644 --- a/packages/core/src/__snapshots__/convert.test.js.snap +++ b/packages/core/src/__snapshots__/convert.test.js.snap @@ -4,7 +4,7 @@ exports[`convert config should support options { dimensions: false } 1`] = ` "import React from 'react' const SvgComponent = props => ( - + "`; +exports[`svgo should not remove viewBox with when dimensions is false 1`] = `""`; + exports[`svgo should optimize svg 1`] = `""`; exports[`svgo should support config.svgoConfig 1`] = `"Created with Sketch."`; diff --git a/packages/plugin-svgo/src/index.js b/packages/plugin-svgo/src/index.js index 3bdaee99..4a3bd831 100644 --- a/packages/plugin-svgo/src/index.js +++ b/packages/plugin-svgo/src/index.js @@ -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 } diff --git a/packages/plugin-svgo/src/index.test.js b/packages/plugin-svgo/src/index.test.js index 78738fba..4ddb9e8b 100644 --- a/packages/plugin-svgo/src/index.test.js +++ b/packages/plugin-svgo/src/index.test.js @@ -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,