Installations
npm install svg-classic-sprite-loader
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
8.11.4
NPM Version
6.10.2
Score
49.5
Supply Chain
89.5
Quality
67.7
Maintenance
25
Vulnerability
97
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (56.06%)
CSS (26.36%)
HTML (17.59%)
Developer
vusion
Download Statistics
Total Downloads
17,877
Last Day
1
Last Week
13
Last Month
119
Last Year
3,389
GitHub Statistics
1 Stars
49 Commits
5 Watching
5 Branches
7 Contributors
Bundle Size
1.29 MB
Minified
372.63 kB
Minified + Gzipped
Package Meta Information
Latest Version
0.2.5
Package Id
svg-classic-sprite-loader@0.2.5
Unpacked Size
55.42 kB
Size
15.87 kB
File Count
39
NPM Version
6.10.2
Node Version
8.11.4
Total Downloads
Cumulative downloads
Total Downloads
17,877
Last day
-91.7%
1
Compared to previous day
Last week
-67.5%
13
Compared to previous week
Last month
-2.5%
119
Compared to previous month
Last year
-48.4%
3,389
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
svg-classic-sprite-loader
Webpack loader for creating classic SVG sprites.
The main reason we make a different loader from svg-sprite-loader is that non-classic way (not using background-position
) to create svg sprite does not work in Safari.
This article shows several ways to create svg sprites. You can take a look in different browers.
Installation
1npm install --save-dev svg-classic-sprite-loader
Note: This loader does not support Webpack@4.x currently.
Quick Start
Add loader
in webpack.config.js
like this:
1module.exports = { 2 ... 3 module: { 4 rules: [ 5 { test: /\.css$/, use: [ 6 'style-loader', 7 'css-loader', 8 'svg-classic-sprite-loader', 9 ] }, 10 { test: /\.svg$/, use: { 11 loader: 'file-loader', 12 options: { 13 name: '[name].[ext]' 14 } 15 } }, 16 ], 17 }, 18};
Use svgs in a CSS file:
1.foo { 2 background: url(./assets/check.svg); 3} 4.bar { 5 background: url(./assets/accessory.svg); 6}
The loader will merge svgs into a sprite file, and replace CSS codes:
1.foo { 2 background: url(sprite.svg) -20px -20px no-repeat; 3} 4.bar { 5 background: url(sprite.svg) -92px -20px no-repeat; 6}
For more examples, check here.
Features:sparkles:
- Easy to use, just set up the associated svg path in CSS only.
- Generating sprite according to need.
- Output multiple sprite.
Config
loader options
defaultName
- Type:
string
- Default:
'sprite'
Default file name of sprite output file.
padding
- Type:
number
- Default:
'sprite'
The margin between svgs in sprite.
filter
- Type:
string
- Default:
'all'
Options: 'all'
、'query'
、RegExp
How to filter svg files for merging:
'all'
: All imported svgs will be merged.'query'
: Only svg path with?sprite
query param will be merged.RegExp
: Only svg path matched by RegExp
queryParam
Customize key of query param in svg path. Only works when filter: 'query'
- Type:
string
- Default:
'sprite'
Examples
Use query
1/* webpack.config.js */ 2loader: 'svg-classic-sprite-loader', 3options: { 4 filter: 'query', 5},
1/* css */ 2.test { 3 background: url(./assets/log-check.svg?sprite); 4} 5.test1 { 6 background: url(./assets/check.svg?sprite=sprite); 7} 8.test2 { 9 background: url(./assets/apm-check.svg); 10}
log-check.svg
and check.svg
are merged into sprite.svg
. Finally output files are sprite.svg
and apm-check.svg
.
Output multiple sprites
1.foo { 2 background: url(./assets/check.svg?sprite=sprite1); 3} 4.bar { 5 background: url(./assets/accessory.svg?sprite=sprite2); 6} 7...
check.svg
is merged into sprite1.svg
, and accessory.svg
is merged into sprite2
. Finally output files are sprite1.svg
and sprite2.svg
.
Use RegExp
1/* webpack.config.js */ 2loader: 'svg-classic-sprite-loader', 3options: { 4 filter: /log/, 5},
1/* css */ 2.test{ 3 background: url(./assets/log-check.svg?sprite=sprite1); 4} 5.test1{ 6 background: url(./assets/check.svg?sprite=sprite1); 7}
Only log-check.svg
is merged into sprite1.svg
. Finally output files are sprite1.svg
and check.svg
.
Changelog
See Releases
Contribution Guide
LICENSE
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
project is archived
Details
- Warn: Repository is archived.
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Score
3
/10
Last Scanned on 2025-01-20
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