Skip to content
Discussion options

You must be logged in to vote

Next.js 16 shipped Turbopack condition rules, which allow loaders to be applied conditionally.

For example, you can use the path condition to apply SVGR only to the icons folder while keeping the default loader for all other SVGs:

turbopack: {
  rules: {
    "*.svg": {
      loaders: ["@svgr/webpack"],
      condition: {
        path: "icons/**"
      },
      as: "*.js",
    },
  },
},

The only challenge is typings: TypeScript is not aware of Turbopack rules, so an imported .svg file might be treated either as a React component or as a static image { src, width, height }.

In my projects, I replaced SVGR with inlining icons as data URIs. It’s more performant and also solves the typing iss…

Replies: 2 comments 10 replies

Comment options

You must be logged in to vote
10 replies
@RafaelFerreiraTVD
Comment options

@RafaelFerreiraTVD
Comment options

@alex-statsig
Comment options

@vitalets
Comment options

Answer selected by clement-escolano
@emmgfx
Comment options

@vitalets
Comment options

@clement-escolano
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
6 participants