Gathering detailed insights and metrics for svg-sprite-loader
Gathering detailed insights and metrics for svg-sprite-loader
Gathering detailed insights and metrics for svg-sprite-loader
Gathering detailed insights and metrics for svg-sprite-loader
@types/svg-sprite-loader
TypeScript definitions for svg-sprite-loader
nuxt-svg-sprite-loader
Nuxt.js module for svg-sprite-loader.
svg-classic-sprite-loader
Webpack loader for creating classic SVG sprites
external-svg-sprite-loader
A webpack loader and plugin that generate SVG sprites out of a collection of SVG files used in your JS and CSS files
npm install svg-sprite-loader
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (98.53%)
Shell (1.27%)
SCSS (0.2%)
Total Downloads
65,746,706
Last Day
35,153
Last Week
206,990
Last Month
936,570
Last Year
10,171,571
MIT License
2,028 Stars
675 Commits
276 Forks
46 Watchers
18 Branches
1,237 Contributors
Updated on Jun 29, 2025
Latest Version
6.0.11
Package Id
svg-sprite-loader@6.0.11
Size
305.13 kB
NPM Version
7.11.1
Node Version
14.15.3
Published on
Oct 24, 2021
Cumulative downloads
Total Downloads
Last Day
5.9%
35,153
Compared to previous day
Last Week
-1.8%
206,990
Compared to previous week
Last Month
8.5%
936,570
Compared to previous month
Last Year
-2%
10,171,571
Compared to previous year
8
35
Webpack loader for creating SVG sprites.
:tada: 2.0 is out, please read the migration guide & overview.
:warning: For old v0.x versions see the README in the v0 branch.
<svg><use xlink:href="#id"></use></svg>
.1npm install svg-sprite-loader -D 2# via yarn 3yarn add svg-sprite-loader -D
1// webpack 1 2{ 3 test: /\.svg$/, 4 loader: 'svg-sprite-loader', 5 query: { ... } 6} 7 8// webpack 1 multiple loaders 9{ 10 test: /\.svg$/, 11 loaders: [ 12 `svg-sprite-loader?${JSON.stringify({ ... })}`, 13 'svg-transform-loader', 14 'svgo-loader' 15 ] 16} 17 18// webpack >= 2 19{ 20 test: /\.svg$/, 21 loader: 'svg-sprite-loader', 22 options: { ... } 23} 24 25// webpack >= 2 multiple loaders 26{ 27 test: /\.svg$/, 28 use: [ 29 { loader: 'svg-sprite-loader', options: { ... } }, 30 'svg-transform-loader', 31 'svgo-loader' 32 ] 33}
symbolId
(string | function(path, query)
, default [name]
)How <symbol>
id
attribute should be named. All patterns from loader-utils#interpolateName
are supported. Also can be a function which accepts 2 args - file path and query string and return symbol id:
1{ 2 symbolId: filePath => path.basename(filePath) 3}
symbolRegExp
(default ''
)Passed to the symbolId interpolator to support the [N] pattern in the loader-utils name interpolator
esModule
(default true
, autoconfigured)Generated export format:
true
loader will produce export default ...
.false
the result is module.exports = ...
.By default depends on used webpack version: true
for webpack >= 2, false
otherwise.
When you require an image, loader transforms it to SVG <symbol>
, adds it to the special sprite storage and returns class instance
that represents symbol. It contains id
, viewBox
and content
(id
, viewBox
and url
in extract mode)
fields and can later be used for referencing the sprite image, e.g:
1import twitterLogo from './logos/twitter.svg'; 2// twitterLogo === SpriteSymbol<id: string, viewBox: string, content: string> 3// Extract mode: SpriteSymbol<id: string, viewBox: string, url: string, toString: Function> 4 5const rendered = ` 6<svg viewBox="${twitterLogo.viewBox}"> 7 <use xlink:href="#${twitterLogo.id}" /> 8</svg>`;
When browser event DOMContentLoaded
is fired, sprite will be automatically rendered and injected in the document.body
.
If custom behaviour is needed (e.g. a different mounting target) default sprite module could be overridden via spriteModule
option. Check example below.
spriteModule
(autoconfigured)Path to sprite module that will be compiled and executed at runtime.
By default it depends on target
webpack config option:
svg-sprite-loader/runtime/browser-sprite.build
for 'web' target.svg-sprite-loader/runtime/sprite.build
for other targets.If you need custom behavior, use this option to specify a path of your sprite implementation module.
Path will be resolved relative to the current webpack build folder, e.g. utils/sprite.js
placed in current project dir should be written as ./utils/sprite
.
Example of sprite with custom mounting target (copypasted from browser-sprite):
1import BrowserSprite from 'svg-baker-runtime/src/browser-sprite'; 2import domready from 'domready'; 3 4const sprite = new BrowserSprite(); 5domready(() => sprite.mount('#my-custom-mounting-target')); 6 7export default sprite; // don't forget to export!
It's highly recommended to extend default sprite classes:
symbolModule
(autoconfigured)Same as spriteModule
, but for sprite symbol. By default also depends on target
webpack config option:
svg-baker-runtime/browser-symbol
for 'web' target.svg-baker-runtime/symbol
for other targets.runtimeGenerator
(default generator)Path to node.js script that generates client runtime. Use this option if you need to produce your own runtime, e.g. React component configured with imported symbol. Example.
runtimeCompat
(default false
, deprecated)Should runtime be compatible with earlier v0.x loader versions. This option will be removed in the next major version release.
runtimeOptions
Arbitrary data passed to runtime generator. Reserved for future use when other runtime generators will be created.
In the extract mode loader should be configured with plugin, otherwise an error is thrown. Example:
1// webpack.config.js 2const SpriteLoaderPlugin = require('svg-sprite-loader/plugin'); 3 4... 5 6{ 7 plugins: [ 8 new SpriteLoaderPlugin() 9 ] 10}
extract
(default false
, autoconfigured)Switches loader to the extract mode. Enabled automatically for images imported from css/scss/sass/less/styl/html files.
spriteFilename
(type string|Function<string>
,default sprite.svg
)Filename of extracted sprite. Multiple sprites can be generated by specifying different loader rules restricted with include
option or
by providing custom function which recieves SVG file absolute path, e.g.:
1{ 2 test: /\.svg$/, 3 loader: 'svg-sprite-loader', 4 options: { 5 extract: true, 6 spriteFilename: svgPath => `sprite${svgPath.substr(-4)}` 7 } 8}
[hash]
in sprite filename will be replaced by it's content hash.
It is also possible to generate sprite for each chunk by using [chunkname]
pattern in spriteFilename option. This is experimental feature, use it with caution!
publicPath
(type: string
, default: __webpack_public_path__
)Custom public path for sprite file.
1{ 2 test: /\.svg$/, 3 loader: 'svg-sprite-loader', 4 options: { 5 extract: true, 6 publicPath: '/' 7 } 8}
outputPath
(type: string
, default: null`)Custom output path for sprite file.
By default it will use publicPath
.
This param is useful if you want to store sprite is a directory with a custom http access.
1{ 2 test: /\.svg$/, 3 loader: 'svg-sprite-loader', 4 options: { 5 extract: true, 6 outputPath: 'custom-dir/sprites/' 7 publicPath: 'sprites/' 8 } 9}
You can render plain sprite in extract mode without styles and usages. Pass plainSprite: true
option to plugin constructor:
1{ 2 plugins: [ 3 new SpriteLoaderPlugin({ plainSprite: true }) 4 ] 5}
Sprite <svg>
tag attributes can be specified via spriteAttrs
plugin option:
1{ 2 plugins: [ 3 new SpriteLoaderPlugin({ 4 plainSprite: true, 5 spriteAttrs: { 6 id: 'my-custom-sprite-id' 7 } 8 }) 9 ] 10}
See examples folder.
See CONTRIBUTING.md.
See LICENSE
Huge thanks for all this people.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 10/27 approved changesets -- score normalized to 3
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
branch protection not enabled on development/release branches
Details
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
Reason
136 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