babel-plugin-import icon indicating copy to clipboard operation
babel-plugin-import copied to clipboard

为什么要重新命名变量名称

Open Hazyzh opened this issue 6 years ago • 0 comments

正如文档里描述的

import { Button } from 'antd';
ReactDOM.render(<Button>xxxx</Button>);

      ↓ ↓ ↓ ↓ ↓ ↓
      
var _button = require('antd/lib/button');
require('antd/lib/button/style/css');
ReactDOM.render(<_button>xxxx</_button>);

import 引入的内容如(Button)经过转换后会变成_button,后面代码中相关变量Button也要去修改为_button,还要考虑到作用域到问题,为什么不还是用原名程呢,仅仅改变引入的路径,就像这样

import { Button } from 'antd';
ReactDOM.render(<Button>xxxx</Button>);

      ↓ ↓ ↓ ↓ ↓ ↓
import Button from 'antd/lib/button';
import 'antd/lib/button/style/css';
...

自己写了一个简单改变import方式的import-separation,看起来也能运行

Hazyzh avatar Jun 24 '18 03:06 Hazyzh