安装babel-plugin-import插件。下面方法二选一,都可以实现antd的按需加载

一、配置webpack.config.js文件

{
    test: /.jsx?$/,
    exclude: /(node_modules|bower_components)/,
    use: [{
        loader: 'babel-loader'
    }],
    options: {
        "plugins": [
            [
                "import", {
                    "libraryName": "antd",
                    "style": true
                }
            ]
        ]
    }
}

二、配置babelrc文件

{
  "presets": ["env", "react"],
  "plugins": [
    "transform-runtime",
    "transform-object-rest-spread",
    [
      "import", {
        "libraryName": "antd",
        "style": true
      }
    ]
  ]
}

相关文章:

  • 2022-12-23
  • 2021-07-08
  • 2021-11-23
  • 2022-12-23
  • 2021-04-30
  • 2021-05-13
  • 2021-07-29
猜你喜欢
  • 2022-12-23
  • 2021-08-05
  • 2022-12-23
  • 2021-06-21
  • 2021-11-14
相关资源
相似解决方案