0.0.4 • Published 5 years ago

babel-plugin-jsx-svg-import v0.0.4

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

babel-plugin-jsx-svg-import

中文文档

add svg file imports for jsx elements。

with svg-sprite-loader

Function

  • There is no need to manually import the svg file, which automatically import svg in the file.
  • There is no need to provide a custom Icon component, the plugin can automatically import the Icon component

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

propdesctypedefault
widthsvg element widthstring | number'1em'
heightsvg element heightstring | number'1em'
fillsvg element fill colorstring'currentColor'
classNamesvg element classstring-
stylesvg element styleCSSProperties-