DEV Community

Soumya Mishra
Soumya Mishra

Posted on

Use Case for Babel Configuration Files

One cannot imagine working on a Javascript project without babel. Whether it's NodeJs or browsers, you need babel.

Babel provides 2 ways for the configuration:

  1. babel.config.json (there are multiple supported extension)
  2. babelrc.json (there are multiple supported extension)

Now, the point comes which of the above files to be used as per your use case.

  1. babel.config.json

This has been included with the babelv7.x to resolve multiple project-wide Issues. This configuration file comes into the picture when you just want to have a single configuration for the whole project. If you are using a mono-repo or you want to compile your node_modules.

This file is created at the root of your project, where package.json resides. This configuration file applies broadly to the project and even applies plugins and presets to the node modules folder.

  1. babelrc.json

You have a configuration that only applies to a single part of your project. It allows you to create independent configurations for subsections of a package.

Also, both the config files can be used together in a case where you want to have a project-wide configuration, but also need some independent configurations.

For example, a mono-repo can have a project-wide configuration, but each of its packages can be build using a babelrc.json file.

Hope, that my learnings will help someone.

Happy Learning!

Latest comments (0)