Skip to content

Migrate SVGR support from core to plugin #9192

Closed

Description

@slorber

Have you read the Contributing Guidelines on issues?

Motivation

The SVGR support is currently in Docusaurus core:

// webpackUtils.ts

    svg: () => ({
      test: /\.svg$/i,
      oneOf: [
        {
          use: [
            {
              loader: require.resolve('@svgr/webpack'),
              options: {
                prettier: false,
                svgo: true,
                svgoConfig: {
                  plugins: [
                    {
                      name: 'preset-default',
                      params: {
                        overrides: {
                          removeTitle: false,
                          removeViewBox: false,
                        },
                      },
                    },
                  ],
                },
                titleProp: true,
                ref: ![path],
              },
            },
          ],
          // We don't want to use SVGR loader for non-React source code
          // ie we don't want to use SVGR for CSS files...
          issuer: {
            and: [/\.(?:tsx?|jsx?|mdx?)$/i],
          },
        },
        {
          use: [loaders.url({folder: 'images'})],
        },
      ],
    }),`

We should try to:

Challenges:

  • Not sure how to deal with the oneOf Webpack rule so that we can keep url/file-loader support in core and CSS files by default.
  • Is SVGR needed for any theme component? This requires to be double-checked.

Motivation:

Self-service

  • I'd be willing to do some initial work on this proposal myself.

Activity

  1. added
    proposal
    difficulty: intermediate
    on Aug 3, 2023
  2. pritipsingh commented on Sep 25, 2023

    @pritipsingh

    Hey @slorber I know it says it's for apprentice, but I would love to take this up. Will it be possible?

  3. slorber commented on Sep 26, 2023

    @slorber
    CollaboratorAuthor

    @pritipsingh if you understand what should be done and feel confortable handling it alone (ie I can't spend time helping you), please submit a draft PR.

  4. pritipsingh commented on Sep 26, 2023

    @pritipsingh

    thanks @slorber happy to take it up alone as I have some experience with component library. will start working on it tomorrow and will try to make a pr asap

  5. slorber commented on Feb 7, 2025

    @slorber
    CollaboratorAuthor

    Fixed in #10677

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    difficulty: intermediateproposal

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions