首页 > 解决方案 > 是否可以将 antd 与 create-react-app 2 一起使用?

问题描述

我的理解是 react-app-rewired 不再适用于 create-react-app 的 v2。

看来你需要进入 babel(因此 react-app-rewired)。

标签: create-react-appantd

解决方案


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

来自react-app-rewired 问题评论的信息:

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

更少
Ant 设计 + 更少 + modifyVars
蚂蚁设计 + 更少 + modifyVars + Preact
Preact

在 craco repo 的 /recipes 目录中有更多示例

craco.config.js来自ndbroadbent的示例:

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 }],
};

推荐阅读