๐ฆ plugin-svgr
An SVGR plugin to transform SVG files into React components automatically at build time.
์ค์นโ
- npm
- Yarn
- pnpm
- Bun
npm install --save @docusaurus/plugin-svgr
yarn add @docusaurus/plugin-svgr
pnpm add @docusaurus/plugin-svgr
bun add @docusaurus/plugin-svgr
If you use the preset @docusaurus/preset-classic, you don't need to install this plugin as a dependency.
You can configure this plugin through the preset options.
์ค์ โ
์ค์ ํ ์ ์๋ ํ๋
| ์ต์ ๋ช | ํ์ | ๊ธฐ๋ณธ๊ฐ | ์ค๋ช |
|---|---|---|---|
svgrConfig | object | {} | The SVGR config options, shallow-merged over the default SVGR config |
์ค์ ์์โ
You can configure this plugin through plugin options.
- ํ๋ฆฌ์ ์ต์
- ํ๋ฌ๊ทธ์ธ ์ต์
ํ๋ฆฌ์ ์ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ ํ๋ฆฌ์ ์ต์ ๋ฅผ ํตํด ํ๋ฌ๊ทธ์ธ์ ๊ตฌ์ฑํฉ๋๋ค.
module.exports = {
presets: [
[
'@docusaurus/preset-classic',
{
svgr: {
svgrConfig: {/* SVGR config */},
},
},
],
],
};
๋ ๋ฆฝ์ ์ผ๋ก ์คํ๋๋ ํ๋ฌ๊ทธ์ธ์ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ์๋ ํ๋ฌ๊ทธ์ธ์ ๋ํ ์ต์ ์ ์ง์ ์ค์ ํ ์ ์์ต๋๋ค.
module.exports = {
plugins: [
[
'@docusaurus/plugin-svgr',
{
svgrConfig: {/* SVGR config */},
},
],
],
};
Default configโ
The svgrConfig option is shallow-merged over the following default SVGR config:
const defaultSvgrConfig = {
prettier: false,
svgo: true,
titleProp: true,
svgoConfig: {
plugins: [
{
name: 'preset-default',
params: {
overrides: {
removeTitle: false,
removeViewBox: false,
},
},
},
{
name: 'prefixIds',
params: {
delim: '',
// Short hash of the SVG file path, relative to the site directory
prefix: (node, info) => `svg-${hash(info.path)}-`,
prefixClassNames: false,
},
},
],
},
};
The prefixIds plugin prefixes SVG ids (for example, id="a" becomes id="svg-3f2a1c-a") to avoid clashes between multiple SVGs inlined in the same page. Class names are not prefixed.
Providing svgoConfig replaces the default SVGO config entirely. Use svgoConfig: undefined to read your own svgo.config.js file instead.