# Installing and Configuring SWC — Babel & SWC

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

> Set up SWC as a Babel replacement with .swcrc configuration.

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

SWC installs similarly to Babel: core for the transpiler, cli for command-line usage.

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

## .swcrc: SWC configuration

`.swcrc` follows a similar structure to `.babelrc` but with different option names tailored to SWC.

```json
{
  "env": {
    "targets": {
      "chrome": "90"
    }
  },
  "jsc": {
    "parser": {
      "syntax": "ecmascript"
    }
  }
}
```

## Running SWC from the CLI

Use `npx swc` to transpile files. SWC automatically picks up `.swcrc` in the project root.

```bash
npx swc src/index.js
npx swc src -d dist  # much faster than Babel
```

Output:

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