# Installing and Configuring Babel — Babel & SWC

Source: https://www.geekswithgeeks.com/en/babel-swc/bs-babel-install

> Get Babel running with core packages and a .babelrc configuration.

## npm install @babel/core and @babel/cli

Every Babel project starts with the core library and optional CLI for command-line transpilation.

```bash
npm install --save-dev @babel/core @babel/cli
```

## .babelrc: the configuration file

Create a `.babelrc` file in your project root to tell Babel which presets and plugins to use.

```json
{
  "presets": ["@babel/preset-env"],
  "plugins": []
}
```

## Running Babel from the CLI

Use `npx babel` to transpile files or directories. Babel reads `.babelrc` automatically.

```bash
npx babel src/index.js
npx babel src -d dist  # transpile directory
```

Output:

```
let x = [1, 2, 3].map(n => n * 2);
// becomes:
var x = [1, 2, 3].map(function(n) {
  return n * 2;
});
```
