是否可以将antd与create-react-app 2一起使用?

时间:2018-11-08 15:12:12

标签: create-react-app antd

我的理解是react-app-rewired在create-react-app的v2中不再起作用。

似乎您需要进入babel(因此,react-app-rewired)。

1 个答案:

答案 0 :(得分:3)

您可以使用craco来代替react-app-rewired。

来自react-app-rewired issue comments的信息:

  

以下是一些craco.config.js配置文件示例:

     

Less
  Ant Design + Less + modifyVars
  Ant Design + Less + modifyVars + Preact
  Preact

     

some more examples in the /recipes directory in the craco repo

来自ndbroadbentcraco.config.js的示例:

const CracoAntDesignPlugin = require('craco-antd');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const WebpackBar = require('webpackbar');

module.exports = {
  webpack: {
    alias: { react: 'preact-compat', 'react-dom': 'preact-compat' },
    plugins: [
      new BundleAnalyzerPlugin(),
      new WebpackBar({ profile: true }),
    ],
  },
  plugins: [{ plugin: CracoAntDesignPlugin }],
};