Ant设计失败使用babel-plugin-import和create-react-app-rewired

问题描述 投票:2回答:2

我正在关注qazxsw poi的Ant设计指南。

我已经安装了“react-app-rewired”,“customize-cra”和“babel-plugin-import”。这是我的完整package.json文件:

minimizing library size

我还有一个config-overrides.js文件:

{
  "name": "client",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "antd": "^3.10.0",
    "react": "^16.5.1",
    "react-dom": "^16.5.1",
    "react-infinite-scroller": "^1.2.2",
    "react-scripts": "1.1.5"
  },
  "scripts": {
    "analyze": "source-map-explorer build/static/js/main.*",
    "start": "react-app-rewired start",
    "build": "react-app-rewired build",
    "test": "react-app-rewired test --env=jsdom",
    "eject": "react-scripts eject"
  },
  "proxy": "http://localhost:3001",
  "devDependencies": {
    "babel-plugin-import": "^1.11.0",
    "customize-cra": "^0.2.10",
    "react-app-rewired": "^2.0.2",
    "source-map-explorer": "^1.6.0"
  }
}

但是,“start”命令失败,并出现以下错误:

const { override, fixBabelImports } = require('customize-cra');
module.exports = override(
    fixBabelImports('import', {
        libraryName: 'antd',
        libraryDirectory: 'es',
        style: 'css',
    }),
);

如何修复此错误/可能的原因是什么?我很确定我完全遵循了Ant Design的指南。

reactjs webpack create-react-app antd babel-loader
2个回答
1
投票

看起来你正在使用/home/vedantroy/Programming/app_name/client/node_modules/customize-cra/index.js:49 getBabelLoader(config).options.plugins.push(plugin); ^ TypeError: Cannot read property 'options' of undefined at Object.config (/home/vedantroy/Programming/app_name/client/node_modules/customize-cra/index.js:49:25) at Object.webpack (/home/vedantroy/Programming/app_name/client/node_modules/lodash.flow/index.js:177:42) at Object.<anonymous> (/home/vedantroy/Programming/app_name/client/node_modules/react-app-rewired/scripts/start.js:22:15) at Module._compile (internal/modules/cjs/loader.js:689:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10) at Module.load (internal/modules/cjs/loader.js:599:32) at tryModuleLoad (internal/modules/cjs/loader.js:538:12) at Function.Module._load (internal/modules/cjs/loader.js:530:3) at Function.Module.runMain (internal/modules/cjs/loader.js:742:12) at startup (internal/bootstrap/node.js:266:19) 你需要[email protected]更改上面的版本并按照提到的步骤@ [email protected]

它将开始工作。

注意:https://www.npmjs.com/package/react-app-rewire-antd-theme适用于customize-cra


0
投票

您可以使用[email protected]useBabelRc()函数,在.babelrc中,您可以为antd编写babel配置。

© www.soinside.com 2019 - 2024. All rights reserved.