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

SVGO Documentation outdated #1192

Open
derweili opened this issue Apr 26, 2021 · 13 comments · Fixed by #1223 · May be fixed by #1233
Open

SVGO Documentation outdated #1192

derweili opened this issue Apr 26, 2021 · 13 comments · Fixed by #1223 · May be fixed by #1233

Comments

@derweili
Copy link

The svgo library got a major update on 19 February.
The Docs https://github.com/swashata/wp-webpack-script/blob/master/site/docs/tutorials/using-various-svg-loader.md only work with

"svgo": "^1.3.2",
"svgo-loader": "^2.2.2"

When using the latest svgo version the build process returns following error Error: Plugin name should be specified.

I haven't figured out what needs to be changed in the config yet, downgrading to the version mentioned above does work as a hotfix.

@swashata
Copy link
Owner

I do use svgo in my project. I will take a look and get back to you. Thank you for the info.

@sethrubenstein
Copy link

Running into the same issue.

@swashata
Copy link
Owner

Hello,

It turns out I use @svgr/webpack because my projects are react specific. But I took a look at the svg-loader documentation. It says the loader should be

loader: 'svgo-loader',
options: {
  configFile: './scripts/svgo.config.js'
}

So I am thinking, maybe try this and let me know how this works out

const {
	getFileLoaderOptions,
	issuerForNonStyleFiles,
	issuerForStyleFiles,
	babelLoader,
	fileLoader,
} = require('@wpackio/scripts');

module.exports = {
	// ...
	files: [
		{
			name: 'app',
			entry: {
				main: ['./src/app/index.js'],
				// stuff
			},
			// Extra webpack config to be dynamically created
			webpackConfig: (config, merge, appDir, isDev) => {
				const svgoLoader = {
					loader: 'svgo-loader',
-					options: {
-						plugins: [
-							{ removeTitle: true },
-							{ convertColors: { shorthex: false } },
-							{ convertPathData: false },
-						],
-					},
				};
				// create module rules
				const configWithSvg = {
					module: {
						rules: [
							// SVGO Loader
							// https://github.com/rpominov/svgo-loader
							// This rule handles SVG for javascript files
							{
								test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
								use: [
									{
										loader: fileLoader,
										options: getFileLoaderOptions(
											appDir,
											isDev,
											false
										),
									},
									svgoLoader,
								],
								issuer: issuerForNonStyleFiles,
							},
							// This rule handles SVG for style files
							{
								test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
								use: [
									{
										loader: fileLoader,
										options: getFileLoaderOptions(
											appDir,
											isDev,
											true
										),
									},
									svgoLoader,
								],
								issuer: issuerForStyleFiles,
							},
						],
					},
				};
				// merge the new module.rules with webpack-merge api
				return merge(config, configWithSvg);
			},
		},
	],
	// ...
};

and add a svgo.config.js to the root of your project.

@robsonsobral
Copy link
Contributor

robsonsobral commented Apr 28, 2021

Actually, svgo.config.js isn't required. The configurations just need to be directly inside options property, instead of an array within plugin property.

The following sample works:

options: {
  { removeTitle: true },
  { convertColors: { shorthex: false } },
  { convertPathData: false },
},

@swashata
Copy link
Owner

Thank you @robsonsobral, do you mind sending in a PR to update the docs?

@robsonsobral
Copy link
Contributor

robsonsobral commented Apr 29, 2021

Sure! I'm glad to help!


By the way, I'm still learning on how to make WPack to fully work.

@sethrubenstein
Copy link

Thanks all!

@swashata
Copy link
Owner

swashata commented May 1, 2021

@robsonsobral you can edit this file https://github.com/swashata/wp-webpack-script/blob/master/site/docs/tutorials/using-various-svg-loader.md and send a PR. Once I merge it, it will automatically update the site.

@robsonsobral
Copy link
Contributor

Done, @swashata . However, I think you have confused the other issue I opened with this one. ;-)

@robbertvancaem
Copy link

I just tried the configuration as proposed above, which didn't work for me. The configuration below however, does seem to work:

const svgoLoader = {
  loader: "svgo-loader",
  options: {
      removeTitle: true,
      convertColors: { shorthex: false },
      convertPathData: false ,
  },
};

@swashata swashata reopened this May 12, 2021
@swashata
Copy link
Owner

Thank you @robbertvancaem for the update. @robsonsobral could you please confirm this? We may need to update the docs.

@higginsd-la higginsd-la linked a pull request Jul 8, 2021 that will close this issue
@robsonsobral
Copy link
Contributor

"Five years later", yes, I confirm!

@swashata
Copy link
Owner

swashata commented Oct 1, 2021

Haha, no worries. I will keep this open for now and will update the docs when I get a chance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants