0

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",
插件有问题还是??

3个回答

-1

已采纳

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

0

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

撰写答案