Gathering detailed insights and metrics for svg-url-loader
Gathering detailed insights and metrics for svg-url-loader
Gathering detailed insights and metrics for svg-url-loader
Gathering detailed insights and metrics for svg-url-loader
svg-mixed-loader
Webpack loader resolving svg into url string and multiple component formats.
@ecomfe/svg-mixed-loader
Webpack loader resolving svg into url string and multiple component formats.
image-trace-loader
Loads images and exports traced outlines as image/svg+xml URL-encoded data
preact-cli-svg-loader
Removes svg extension file-loader, url-loader and raw-loader and use preact-svg-loader to load svg file as preact components
A webpack loader which loads SVG file as utf-8 encoded DataUrl string.
npm install svg-url-loader
Typescript
Module System
Min. Node Version
Node Version
NPM Version
85.9
Supply Chain
61.9
Quality
74.6
Maintenance
100
Vulnerability
99.6
License
v8.0.0
Updated on Sep 04, 2022
Performance improvements
Updated on Nov 29, 2020
Add resourceQuery support
Updated on Nov 27, 2020
Fallback to file-loader using default options
Updated on Nov 26, 2020
Deprecate stripdeclarations option
Updated on May 24, 2020
Compatible with Yarn 2
Updated on May 24, 2020
JavaScript (98.36%)
Less (0.55%)
SCSS (0.55%)
CSS (0.54%)
Total Downloads
107,744,568
Last Day
8,837
Last Week
292,717
Last Month
1,326,052
Last Year
14,188,181
MIT License
242 Stars
1,168 Commits
33 Forks
3 Watchers
2 Branches
10 Contributors
Updated on Jun 28, 2025
Minified
Minified + Gzipped
Latest Version
8.0.0
Package Id
svg-url-loader@8.0.0
Unpacked Size
9.98 kB
Size
4.23 kB
File Count
5
NPM Version
8.16.0
Node Version
16.15.0
Cumulative downloads
Total Downloads
Last Day
-14.9%
8,837
Compared to previous day
Last Week
-12.9%
292,717
Compared to previous week
Last Month
5.9%
1,326,052
Compared to previous month
Last Year
3.4%
14,188,181
Compared to previous year
1
1
A webpack loader which loads SVG file as utf-8 encoded DataUrl string.
Existing url-loader
always does Base64 encoding for data-uri. As SVG content is a human-readable xml string, using base64 encoding is not mandatory. Instead, one may only escape unsafe characters and replace "
with '
as described in this article.
There are some benefits for choosing utf-8 encoding over base64.
Parameters can be passed both in an url or from webpack config file. See Loaders section in webpack documentation for more details.
Passing parameters using resourceQuery
is also supported:
1.selector { 2 background-image: url(../assets/foo.svg?encoding=base64); 3}
The loader supports the following parameters:
limit
If given, loader will not encode the source file if its content is greater than this limit.
Defaults to no limit.
If the file is greater than the limit the file-loader
is used, receiving all query parameters set for svg-url-loader.
1require("svg-url-loader?limit=1024!./file.svg"); 2// => DataUrl if "file.png" is smaller that 1kb 3 4require("svg-url-loader?prefix=img/!./file.svg"); 5// => Parameters for the file-loader are valid too 6// They are passed to the file-loader if used.
stripdeclarations
This option is true by default. It will be removed in the next major release.
See this issue for more context about this decision.
If given will tell the loader to strip out any XML declaration, e.g. <?xml version="1.0" encoding="UTF-8"?>
at the beginning of imported SVGs.
Internet Explorer (tested in Edge 14) cannot handle XML declarations in CSS data URLs (content: url("data:image/svg...")
).
1require("svg-url-loader?stripdeclarations!./file.svg");
iesafe
This option tells loader to fall back to the file-loader if the file contains a style-element and the encoded size is above 4kB no matter the limit
specified.
This option was introduced because Internet Explorer (including IE11) stops parsing style-elements in SVG data-URIs longer than 4kB. This results in black fill-color for all styled shapes.
You can either specify iesafe
option in the query:
1// apply `iesafe` option only for 'foo.svg' 2require("svg-url-loader?iesafe!./foo.svg");
Or, you can set this option globally in you webpack config:
1module.exports = { 2 //... 3 module: { 4 rules: [ 5 { 6 test: /\.svg/, 7 use: { 8 loader: "svg-url-loader", 9 options: { 10 // make all svg images to work in IE 11 iesafe: true, 12 }, 13 }, 14 }, 15 ], 16 }, 17 //... 18};
encoding
This option controls which encoding to use when constructing a data-URI for an SVG. When set to a non-"none" value, loader does not apply quotes to the resulting data-URI.
Possible values are "base64" and "none". Defaults to "none".
Normally, setting encoding
option to base64
should not be required, as using base64 encoding defeats the original purpose of this loader - embed svg with minimal size overhead. However, because of incompatibility with some tools, we support this mode, too.
You can either specify base64
option in the query:
1// apply `base64` option only for 'foo.svg' 2require("svg-url-loader?encoding=base64!./foo.svg");
Or, you can set this option globally in you webpack config:
1module.exports = { 2 //... 3 module: { 4 rules: [ 5 { 6 test: /\.svg/, 7 use: { 8 loader: "svg-url-loader", 9 options: { 10 // make loader to behave like url-loader, for all svg files 11 encoding: "base64", 12 }, 13 }, 14 }, 15 ], 16 }, 17 //... 18};
1require("svg-url-loader!./file.svg"); 2// => DataUrl for file.svg
1.icon { 2 background: url("../images/file.svg"); 3}
1module.exports = { 2 //... 3 module: { 4 rules: [ 5 { 6 test: /\.svg/, 7 use: { 8 loader: "svg-url-loader", 9 options: {}, 10 }, 11 }, 12 ], 13 }, 14 //... 15};
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
30 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 4
Details
Reason
8 existing vulnerabilities detected
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
Found 0/6 approved changesets -- 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
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-30
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