0.0.4 • Published 6 years ago
babel-plugin-jsx-svg-import v0.0.4
babel-plugin-jsx-svg-import
add
svgfile imports forjsxelements。with svg-sprite-loader
Function
- There is no need to manually import the
svgfile, which automatically importsvgin the file. - There is no need to provide a custom
Iconcomponent, the plugin can automatically import theIconcomponent
options
{
"displayName": "Icon",
"propName": "type",
"directory": "/assets/",
"importComponent": false,
}no use importComponent
[
'babel-plugin-jsx-svg-import',
{
displayName: 'Icon',
propName: 'type',
directory: '/assets/',
},
];import Icon from './Icon.jsx';
ReactDOM.render(<Icon type="close"/>);
↓ ↓ ↓ ↓ ↓ ↓
import './assets/close.svg'
ReactDOM.render(<Icon type="close"/>);use importComponent
[
'babel-plugin-jsx-svg-import',
{
displayName: 'Icon',
propName: 'type',
directory: '/assets/',
importComponent: true,
},
];ReactDOM.render(<Icon type="close"/>);
↓ ↓ ↓ ↓ ↓ ↓
import Icon from 'babel-plugin-jsx-svg-import/lib/runtime';
import './assets/close.svg'
ReactDOM.render(<Icon type="close"/>);Icon Component
from antd Icon
| prop | desc | type | default |
|---|---|---|---|
| width | svg element width | string | number | '1em' |
| height | svg element height | string | number | '1em' |
| fill | svg element fill color | string | 'currentColor' |
| className | svg element class | string | - |
| style | svg element style | CSSProperties | - |