Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I want to add a babel plugin inside create-react-app

I want to add the following babel configuration in react-scripts I don't want to eject from cra I want to keep using it without ejecting. I see there is a way to fork the repo and add your custom configuration. But I want to know where exactly I can paste this.

// .babelrc or babel-loader option
{
  "plugins": [
    ["import", { "libraryName": "antd", "libraryDirectory": "es", "style": "css" }] // `style: true` for less
  ]
}
like image 753
Alqama Bin Sadiq Avatar asked Aug 22 '19 19:08

Alqama Bin Sadiq


People also ask

Does create react app include Babel?

Creating a React application requires you to set up build tools such as Babel and Webpack. These build tools are required because React's JSX syntax is a language that the browser doesn't understand.

Does create react app use Webpack and Babel?

react-scripts json . It's actually the react-scripts package that makes everything work. react-scripts specifies all of our app's development dependencies, like Webpack and Babel. Furthermore, it contains scripts that "glue" all of these dependencies together in a conventional manner.


1 Answers

There is, in theory, customize-cra, which lets you do things like override Babel plugins.

Here is a list of things you can do.

It doesn't appear to be maintained at time of writing, and for me didn't seem usable if your project is modules-based (ie import) as opposed to require.

CRA itself recommends forking their scripts as an alternative to ejecting, which is a pretty bold statement.

like image 124
SCdF Avatar answered Sep 18 '22 05:09

SCdF