Open peteruithoven opened 1 year ago
To get vite + react + svgr + svgo working I needed to install @svgr/plugin-svgo
and use the following config:
// vite.config.ts
import { defineConfig } from "vitest/config";
import react from "@vitejs/plugin-react";
import svgr from "vite-plugin-svgr";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
react(),
// https://github.com/pd4d10/vite-plugin-svgr#options
svgr({
svgrOptions: {
plugins: ["@svgr/plugin-svgo", "@svgr/plugin-jsx"],
svgoConfig: {
// https://github.com/svg/svgo/blob/main/plugins/cleanupNumericValues.js#L32
floatPrecision: 2,
},
},
}),
],
});
I'm afraid I don't know how this translates to the other platforms svgr supports, like webpack. So I'm hesitant to do documentation pull requests.
Some explanation of why they're needed would be great as well. At work we need to use svgoOptions
to make sure the viewBox is set, and it's really not clear why we have to add both @svgr/plugin-svgo
and @svgr/plugin-jsx
, especially when the docs seem to imply svgo is included and we're coming from webpack, where defining these plugins isn't needed.
This lack of docs tripped me up as well.
🐛 Bug Report
The
plugins
option is undocumented? It's not mentioned on: https://react-svgr.com/docs/options/While it is needed to enable for example the svgo plugin: https://www.npmjs.com/package/@svgr/plugin-svgo
Another place to possibly add a note about this requirement might be: https://react-svgr.com/docs/options/#svgo