DocSpring / craco-antd

A craco plugin to use Ant Design with create-react-app
MIT License
234 stars 49 forks source link

Use overrideCracoConfig #1

Closed patricklafrance closed 5 years ago

patricklafrance commented 5 years ago

You don't need to merge it, I wanted to show you that you could also use overrideCracoConfig to add a babel plugin

ndbroadbent commented 5 years ago

Oh awesome! I was a bit confused about how that works, but that makes a lot of sense now! Thanks!

ndbroadbent commented 5 years ago

Hi @patricklafrance, just wanted to mention that this code actually has a bug in this line:

const { babel: { plugins = [] } = {} } = cracoConfig;

This does initialize a new plugins array if it didn't already exist at cracoConfig.babel.plugins, but it doesn't actually modify the original cracoConfig variable. It just returns an empty array that isn't attached to anything.

You actually need to call this:

if (!cracoConfig.babel) cracoConfig.babel = {};
if (!cracoConfig.babel.plugins) cracoConfig.babel.plugins = [];

That will modify the data in the original cracoConfig so that the changes to plugins will be saved when you call return cracoConfig.

patricklafrance commented 5 years ago

@ndbroadbent good catch, sorry about that!