<h3 align="center">@chialab/babel-preset</h3>

<p align="center">
  Babel preset for Chialab projects
</p>

<p align="center">
    <a href="https://travis-ci.org/Chialab/babel-preset">
        <img alt="Travis status" src="https://img.shields.io/travis/chialab/babel-preset.svg?style=flat-square">
    </a>
    <a href="https://www.npmjs.com/package/@chialab/babel-preset">
        <img alt="NPM" src="https://img.shields.io/npm/v/@chialab/babel-preset.svg?style=flat-square">
    </a>
    <a href="https://github.com/Chialab/babel-preset/blob/master/LICENSE">
        <img alt="License" src="https://img.shields.io/npm/l/@chialab/babel-preset.svg?style=flat-square">
    </a>
</p>

---

A custom set of plugins, based on the [`@babel/preset-env`](https://www.npmjs.com/package/@babel/preset-env), which includes:

* [`@babel/plugin-proposal-class-properties`](https://www.npmjs.com/package/@babel/plugin-proposal-class-properties) Support for class private and public fields
* [`@babel/plugin-proposal-decorators`](https://www.npmjs.com/package/@babel/plugin-proposal-decorators) for decorators support
* [`@babel/plugin-syntax-dynamic-import`](https://www.npmjs.com/package/@babel/plugin-syntax-dynamic-import) for dynamic `import()` syntax support
* [`babel-plugin-transform-inline-environment-variables`](https://www.npmjs.com/package/babel-plugin-transform-inline-environment-variables): `process.env` replacements
* [`babel-plugin-istanbul`](https://www.npmjs.com/package/babel-plugin-istanbul): code coverage
* [`@babel/plugin-transform-react-jsx`](https://www.npmjs.com/package/@babel/plugin-transform-react-jsx): transpile JSX
* [`babel-plugin-jsx`](./plugins/babel-plugin-jsx): auto import JSX pragma
* [`babel-plugin-jsx-template`](./plugins/babel-plugin-jsx-template): auto export a function with a JSX template
* [`babel-plugin-assertions`](./plugins/babel-plugin-assertions): polyfill assertion statements with [Chai](http://www.chaijs.com/)
* [`babel-plugin-transform-commonjs`](./plugins/babel-plugin-transform-commonjs): try to convert CommonJS modules to ES6 modules

# Install

```sh
npm install @chialab/babel-preset -D
# or
yarn add @chialab/babel-preset -D
```

# Usage

Add to the `.babelrc` file the preset:
```js
{
    "presets": [
        ["@chialab/babel-preset", { ... }]
    ],
    "plugins": [ ... ]
}
```

# Options

The preset inherits all the `@babel/preset-env` options, available [here](https://babeljs.io/docs/en/next/babel-preset-env.html#options).

| Name                     | Accepts   | Default | Description                                        |
| ------------------------ | --------- | ------- | -------------------------------------------------- |
| `env`                    | `Boolean` | `true`  | Should use `@babel/preset-env`.                    |
| `pragma`                 | `String`  | -       | The JSX pragma.                                    |
| `pragmaModule`           | `String`  | -       | The module path which exports the pragma.          |
| `pragmaDefault`          | `Boolean` | `false` | Import pragma as default member.                   |
| `assertions`             | `Boolean` | `false` | Polyfill assertion statements with Chai.           |
| `coverage`               | `Boolean` | `false` | Should enable code coverage.                       |
| `coverageInclude`        | `Array`   | `[]`    | A list of files to include in the coverage.        |
| `coverageExclude`        | `Array`   | `[]`    | A list of files to exclude from the coverage.      |
| `transformCommonjs`      | `Boolean` | `false` | Should convert CommonJS modules.                   |
| `transformCommonjsCache` | `Boolean` | `false` | A Map instance to use as cache for the tranformer. |
