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

Clone SVGO opts object before mutating it #250

Merged
merged 2 commits into from
May 3, 2019
Merged

Conversation

cpmsmith
Copy link
Contributor

@cpmsmith cpmsmith commented Mar 5, 2019

Currently, when adding the essential SVGO plugins, react-svg-core directly mutates the opts object it's passed, which can cause problems if you're reusing the same options in multiple places, e.g.:

const SVGOOptions = {
	plugins: [
		{ removeTitle: true },
		{ removeStyleElement: false }
	],
	floatPrecision: 2
};

// later, in webpack.config
const output = {
	// [...]
	module: {
		rules: [
			{
				test: [/\.svg$/],
				issuer: [/\.jsx$/],
				use: [{
					loader: 'react-svg-loader',
					options: { svgo: SVGOOptions }
				}]
			}, {
				test: [/\.svg$/],
				issuer: [/\.scss$/],
				use: [{
					loader: 'image-webpack-loader',
					options: { svgo: SVGOOptions }
				}]
			}
		]
	}
	// [...]
};

When react-svg-loader is used first, it causes image-webpack-loader to apply its essential SVGO plugins. This PR prevents this.

@boopathi boopathi merged commit ad5f274 into boopathi:master May 3, 2019
boopathi added a commit that referenced this pull request May 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants