antd不起用按需加载就正常, 启用按需加载后就报错。Menu is not defined

barbelrc配置如下

{
  "presets": [
    ["es2015", "stage-0"],
    ["env", {
      "targets": {
        "browsers": ["last 2 versions", "safari >= 7"]
      }
    }],
    // Transpile React components to JavaScript
    "react"
  ],
  "plugins": [ 
    ["import", {
    "libraryName": "antd",
    "style": "css"
  }],
    "transform-runtime",
    // es7 装饰器
    "transform-decorators-legacy",
    // Enables React code to work with HMR.
    "react-hot-loader/babel"
    // "syntax-dynamic-import",

  ],
  "comments": false,
  "env": {
    "test": {
      "presets": [
        "env"
      ],
      "plugins": [
        "istanbul"
      ]
    },
    "production": {
      "presets": [
        "react-optimize"
      ]
    }
  }
}

报错

Uncaught ReferenceError: Menu is not defined
    at Object.<anonymous> (DailyOperation.js:19)
    at t (bootstrap 31102546e73623907bc2:19)
    at Object.<anonymous> (routerSync.js:12)
    at t (bootstrap 31102546e73623907bc2:19)
    at Object.<anonymous> (index.js:3)
    at t (bootstrap 31102546e73623907bc2:19)
    at bootstrap 31102546e73623907bc2:62
    at bootstrap 31102546e73623907bc2:62

插件版本"babel-plugin-import": "^1.4.0",
插件有问题还是??

阅读 6.1k
3 个回答

找到原因了是"react-optimize"的原因,大家记得antd使用按需加载的时候关掉这个东西。

这个跟babel 没关系吧。
第一步,安装antd ,npm install antd --save
第二步,在需要的地方引入 import {Menu} from 'antd';

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题