Reputation: 8467
I am following Ant Design's guide for minimizing library size.
I have installed "react-app-rewired", "customize-cra", and "babel-plugin-import". This is my full package.json file:
{
"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"
}
}
I also have a config-overrides.js file:
const { override, fixBabelImports } = require('customize-cra');
module.exports = override(
fixBabelImports('import', {
libraryName: 'antd',
libraryDirectory: 'es',
style: 'css',
}),
);
However, the "start" command fails with the following error:
/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)
How do I fix this error/what are possible causes? I'm pretty sure I followed Ant Design's guide exactly.
Upvotes: 2
Views: 2669
Reputation: 41
Looks like you are using [email protected]
for which you need [email protected]
Change the above version and follow the steps mentioned @
https://www.npmjs.com/package/react-app-rewire-antd-theme
It will start working.
Note: customize-cra
is for [email protected]
Upvotes: 1
Reputation: 1823
You can use useBabelRc()
function of customize-cra
and in .babelrc, you can write babel config for antd.
Upvotes: 0