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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document plugins option? #919

Open
peteruithoven opened this issue Nov 6, 2023 · 3 comments
Open

Document plugins option? #919

peteruithoven opened this issue Nov 6, 2023 · 3 comments

Comments

@peteruithoven
Copy link

馃悰 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

@peteruithoven
Copy link
Author

peteruithoven commented Nov 6, 2023

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.

@mikew
Copy link

mikew commented Jan 10, 2024

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.

@wachunga
Copy link

This lack of docs tripped me up as well.

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

No branches or pull requests

3 participants