初识react(7)——利用 react-app-rewired 实现按需打包

首先下载 react-app-rewired:

npm install --save-dev babel-plugin-import react-app-rewired

定义加载配置的js模块——在项目根目录下创建 config-overrides.js 文件,代码如下:

const {injectBabelPlugin} = require('react-app-rewired');
module.exports = function override(config, env) {
    config = injectBabelPlugin(['import', {libraryName: 'antd', style: 'css'}], config);
    return config;
};

在这里插入图片描述
修改配置 :package.json 文件:

  "scripts": {
    "start": "react-app-rewired start",  
    "build": "react-app-rewired build",
    "test": "react-app-rewired test",
   "eject": "react-scripts eject"
  }

你可能感兴趣的:(React)