统计信息:字数 2450 阅读5分钟
Babel can be configured! Many other tools have similar configs: ESLint (.eslintrc), Prettier (.prettierrc).
All Babel API options are allowed. However, if the option requires JavaScript, you may want to use a JavaScript configuration file.
What's your use case? You are using a monorepo? You want to compile node_modules? babel.config.json is for you!
You have a configuration that only applies to a single part of your project? .babelrc.json is for you!
We recommend using the babel.config.json format. Babel itself is using it.
Create a file called babel.config.json with the following content at the root of your project (where the package.json is).
Check out the babel.config.json documentation to see more configuration options.
Create a file called .babelrc.json with the following content in your project.
Check out the .babelrc documentation to see more configuration options.
Alternatively, you can choose to specify your .babelrc.json config from within package.json using the babel key like so:
You can also write babel.config.json and .babelrc.json files using JavaScript:
You can read more about JavaScript configuration files in the dedicated documentation
Using the CLI (@babel/cli) babel --plugins @babel/plugin-transform-arrow-functions script.js
Check out the babel-cli documentation to see more configuration options.
Using the API (@babel/core) require("@babel/core").transform("code", { plugins: ["@babel/plugin-transform-arrow-functions"] });
Check out the babel-core documentation to see more configuration options.