$ gnpm install @svgr/plugin-jsx
Transforms SVG into JSX.
npm install --save-dev @svgr/plugin-jsx
.svgrrc
{
"plugins": ["@svgr/plugin-jsx"]
}
@svgr/plugin-jsx
consists in three phases:
@svgr/babel-preset
transformationsYou can extend the Babel config applied in this plugin using jsx.babelConfig
config path:
// .svgrrc.js
module.exports = {
jsx: {
babelConfig: {
plugins: [
// For an example, this plugin will remove "id" attribute from "svg" tag
[
'@svgr/babel-plugin-remove-jsx-attribute',
{
elements: ['svg'],
attributes: ['id'],
},
],
],
},
},
}
Several Babel plugins are available:
@svgr/babel-plugin-add-jsx-attribute
@svgr/babel-plugin-remove-jsx-attribute
@svgr/babel-plugin-remove-jsx-empty-expression
@svgr/babel-plugin-replace-jsx-attribute-value
@svgr/babel-plugin-svg-dynamic-title
@svgr/babel-plugin-svg-em-dimensions
@svgr/babel-plugin-transform-react-native-svg
@svgr/babel-plugin-transform-svg-component
If you want to create your own, reading Babel Handbook is a good start!
MIT
Copyright 2013 - present © cnpmjs.org | Home |