ElementUI / babel-plugin-component

Modular element-ui build plugin for babel.
452 stars 96 forks source link

解析的组件对象名不正确 #56

Closed lc-soft closed 4 years ago

lc-soft commented 5 years ago

能够重现此问题的测试用例已经提交至 PR #55 ,切换到这个 PR 的分支然后运行 npm test 即可重现:

2019-10-23 15-52-21 的屏幕截图

第一次解析 MessageBox.alert(text) 的结果是正常的:

function alert(text) {
  _messageBox2.default.alert(text);
}

第二次解析 MessageBox.confirm(text) 时 MessageBox 却被解析为 _MessageBox

function confirm(text) {
  return _messageBox.confirm(text);
}
lc-soft commented 5 years ago

解决方法: 改用 babel-plugin-import,重命名 .babelrc 为 .babelrc.js,然后将插件配置改为:

```js
[
  "import",
  {
    "libraryName": "element-ui",
    "style": (name) => {
      return `element-ui/lib/theme-chalk/${name.substr(name.lastIndexOf('/') + 1)}.css`
    }
  },
  "element-ui"
],
lc-soft commented 4 years ago

https://github.com/ant-design/babel-plugin-import/commit/36cb5e46f09797556f06401fca5bf4a110df9ae5