Babel7の設定ファイル

f:id:utouto97:20210706233740j:plain

前回、Babelでトランスパイルを試してみました。

utouto97.hatenablog.com

このとき、利用したBabelのバージョンは7です。

$ > ./node_modules/.bin/babel --version
7.14.5 (@babel/core 7.14.6)

Babel7では、設定ファイルとして.babelrcファイルだけではなく、babel.config.jsファイルも利用できるようです。

そこで、.babelrcbabel.config.jsの違いや使い分けについて調べてみました。
Babelのドキュメントで言及されていました。

babeljs.io

  • Project-wide configuration
    • babel.config.json files, with the different extensions (.js, .cjs, .mjs)
  • File-relative configuration
    • .babelrc.json files, with the different extensions (.babelrc, .js, .cjs, .mjs)
    • package.json files with a "babel" key

↑のように書かれています。
つまり、babel.config.js (babel.config.json) は、プロジェクト全体の設定を記述し,
.babelrc (.babelrc.json) は、ファイル毎の設定を記述するようです。

終わり