美文网首页
antd 组件按需加载

antd 组件按需加载

作者: 喵喵同学嘛 | 来源:发表于2019-07-07 20:57 被阅读0次
    1. 安装react-app-rewired
      npm install react-app-rewired@2.0.2-next.0 babel-plugin-import --save

    2. 扩展webpack的配置
      2.1.1 在根目录下创建config-overrides.js文件

    const { injectBabelPlugin } = require("react-app-rewired");
    
    module.exports = function override(config, env) {
      // antd按需加载
      config = injectBabelPlugin(
        ["import", { libraryName: "antd", libraryDirectory: "es", style: "css" }],
        config
      );
      return config;
    };
    
    1. 修改package.json 的启动脚本为react-app-rewired启动
    "scripts": {
        "start": "react-app-rewired start",
        "build": "react-app-rewired build",
        "test": "react-app-rewired test",
        "eject": "react-app-rewired eject"
      }
    

    相关文章

      网友评论

          本文标题:antd 组件按需加载

          本文链接:https://www.haomeiwen.com/subject/fvaecqtx.html