craco-plugin for creatin SVG sprites.
Motivation: How to use SVG sprites in a project.
You have to learn what SVG sprites.
then,Learn how to use SVGO to compress SVG.
Finally, summarize the application in the project
Three package involved:
npm install craco-plugin-svg-sprite --save-dev
... or with Yarn
yarn add craco-plugin-svg-sprite -D
// craco.config.js => plugins
const cracoPluginSvgSprite = require("craco-plugin-svg-sprite");
{
plugin: cracoPluginSvgSprite,
options: {
include: "src", // required
compress: true, // option
svgoConfig: { // option
},
spriteLoaderConfig: { // option
},
svgPrefixName: "icon" // option
},
}
configuration parameter:
Property | Description | Type | Default | Option |
---|---|---|---|---|
include | files to include | string |
- | required |
svgPrefixName | svg file prefix name | string |
- | option |
compress | is a svgo used | boolean |
true | option |
svgoConfig | svgo-loader config | object |
- | option |
spriteLoaderConfig | svg-sprite-loader config | object |
- | option |