Gathering detailed insights and metrics for @svgr/webpack
Gathering detailed insights and metrics for @svgr/webpack
Gathering detailed insights and metrics for @svgr/webpack
Gathering detailed insights and metrics for @svgr/webpack
npm install @svgr/webpack
Typescript
Module System
Min. Node Version
Node Version
NPM Version
TypeScript (64.93%)
MDX (20.67%)
JavaScript (14.4%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
10,860 Stars
650 Commits
430 Forks
35 Watchers
3 Branches
129 Contributors
Updated on Jul 10, 2025
Latest Version
8.1.0
Package Id
@svgr/webpack@8.1.0
Unpacked Size
14.84 kB
Size
5.25 kB
File Count
6
NPM Version
lerna/6.6.0/node@v18.17.0+arm64 (darwin)
Node Version
18.17.0
Published on
Aug 15, 2023
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Webpack loader for SVGR.
npm install @svgr/webpack --save-dev
In your webpack.config.js
:
1{ 2 test: /\.svg$/, 3 use: ['@svgr/webpack'], 4}
In your code:
1import Star from './star.svg' 2 3const App = () => ( 4 <div> 5 <Star /> 6 </div> 7)
1{ 2 test: /\.svg$/, 3 use: [ 4 { 5 loader: '@svgr/webpack', 6 options: { 7 native: true, 8 }, 9 }, 10 ], 11}
url-loader
or file-loader
It is possible to use it with url-loader
or file-loader
.
In your webpack.config.js
:
1{ 2 test: /\.svg$/, 3 use: ['@svgr/webpack', 'url-loader'], 4}
In your code:
1import starUrl, { ReactComponent as Star } from './star.svg' 2 3const App = () => ( 4 <div> 5 <img src={starUrl} alt="star" /> 6 <Star /> 7 </div> 8)
The named export defaults to ReactComponent
, but can be customized with the namedExport
option.
Please note that by default, @svgr/webpack
will try to export the React Component via default export if there is no other loader handling svg files with default export. When there is already any other loader using default export for svg files, @svgr/webpack
will always export the React component via named export.
If you prefer named export in any case, you may set the exportType
option to named
.
By default, @svgr/webpack
includes a babel-loader
with an optimized configuration. In some case you may want to apply a custom one (if you are using Preact for an example). You can turn off Babel transformation by specifying babel: false
in options.
1// Example using preact 2{ 3 test: /\.svg$/, 4 use: [ 5 { 6 loader: 'babel-loader', 7 options: { 8 presets: ['preact', 'env'], 9 }, 10 }, 11 { 12 loader: '@svgr/webpack', 13 options: { babel: false }, 14 } 15 ], 16}
It is possible to detect the module that requires your SVG using Rule.issuer
in Webpack 5. Using it you can specify two different configurations for JavaScript and the rest of your files.
1;[ 2 { 3 test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, 4 issuer: /\.[jt]sx?$/, 5 use: ['babel-loader', '@svgr/webpack', 'url-loader'], 6 }, 7 { 8 test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, 9 loader: 'url-loader', 10 }, 11]
Rule.issuer in Webpack 4 has additional conditions which are not available in Webpack 5.
MIT
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
GitHub workflow tokens follow principle of least privilege
Details
Reason
license file detected
Details
Reason
no binaries found in the repo
Reason
Found 18/28 approved changesets -- score normalized to 6
Reason
0 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
81 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More