How to Use SVGR in Your Project: Online, CLI, Node.js, and Webpack Plugin
Updated
SVGR is available in four main integration modes: an online playground, a CLI, a Node.js API, and a webpack plugin. Pick the online tool for one-off conversions, the CLI for scripts and build steps, the Node.js API when you need programmatic control inside your own tooling, and the webpack plugin when you want SVGs imported as React components automatically during bundling. All four share the same transformation engine, so the choice is about where the conversion should live, not about output quality.
What SVGR does in all four modes
SVGR takes an SVG file and transforms it into a React component. According to the site, it "handles all type of SVG and transforms it into a React component," and it is "entirely configurable" — you can use built-in settings or write your own plugin for advanced cases. Because the same engine backs every mode, a conversion you validate in the playground will behave the same way when you move it into a build pipeline, as long as the configuration matches.
The four ways to use SVGR
| Mode | Where it runs | Best for | Trade-off |
|---|---|---|---|
| Online | In the browser | Quick trials, single conversions, checking output before committing to a setup | Manual, not repeatable in a build |
| CLI | Terminal / scripts | Batch conversion, CI steps, generating components into a source folder | You manage file paths and re-runs yourself |
| Node.js API | Inside your own Node code | Custom tooling, generators, non-webpack bundlers | Requires writing and maintaining the integration |
| Webpack plugin | During bundling | Importing .svg directly as React components in a webpack app |
Tied to a webpack-based build |
Online: fastest way to see the output
Use this when you want to check what SVGR produces from a specific SVG before wiring anything up. You paste or load an SVG, get the React component back, and can judge whether the default output suits your codebase. It is a trial surface, not a pipeline — there is no repeatable step to commit. If you only need to convert a handful of icons once, this may be all you need.
CLI and Node.js: scripted and programmatic conversion
The CLI suits batch jobs: converting a folder of SVGs, regenerating components in CI, or producing files into a source directory. The Node.js API is the same capability exposed for code, so you can call it from a custom script, a generator, or a bundler that isn't webpack. Choose the CLI when a shell command is enough; choose the Node.js API when the conversion has to be driven by your own logic. Both require you to decide where output files go and when the step re-runs.
Webpack plugin: conversion during the build
This is the option for webpack projects that want to import an SVG and receive a React component, with no separate conversion step to maintain. The transformation happens as part of bundling, so the component stays in sync with the source SVG automatically. The cost is coupling: this path only makes sense if your project already builds with webpack.
How to choose
- One SVG, one time → online tool.
- Many SVGs, repeatable, shell-driven → CLI.
- Conversion driven by your own code or a non-webpack bundler → Node.js API.
- Webpack app that wants SVG imports to be components → webpack plugin.
A useful check: if you would otherwise commit generated components by hand, move to the CLI or webpack plugin so the step is reproducible. If you are still deciding what the output should look like, stay in the online tool until the configuration is settled.
Why this matters for adoption
SVGR is already widely used — the site notes it appears in WordPress, Next.js, and Create React App, and that "you probably already use SVGR in your project." That means the integration you pick is likely to match patterns your team already has: a webpack plugin in a webpack app, or a CLI step in a scripted build. Matching the existing build rather than adding a new mechanism keeps the setup small.
Verifying your setup
Whichever mode you choose, confirm two things: that the generated component renders the SVG correctly in your app, and that re-running the conversion (or rebuilding, for the webpack plugin) reproduces the same result. If output differs between the online tool and your build, compare configurations first — the engine is the same, so a mismatch usually points to different settings rather than a different tool.