UNPKG

4.37 kBMarkdownView Raw
1<h3 align="center">
2 babel-preset-latest-node
3</h3>
4
5<p align="center">
6 babel preset latest for node 14 (Current), node 12 (Active LTS) node 10 (Maintenance LTS)
7</p>
8
9<p align="center">
10 <a href="https://npmjs.org/package/babel-preset-latest-node"><img src="https://img.shields.io/npm/v/babel-preset-latest-node.svg?style=flat-square"></a>
11</p>
12
13# babel 7
14
15Since v2, this package requires `@babel/core@^7.0.0`. If you use babel 6, you can still use the version "1.0.0" of this package. If you want to migrate, you can read the [announcement](https://babeljs.io/blog/2018/08/27/7.0.0) and the [official migration guide](https://babeljs.io/docs/en/v7-migration).
16
17## Alternatives
18
19- [@babel/preset-env](https://www.npmjs.com/package/@babel/preset-env), especially `targets.node`
20
21## Options
22
23- `target`: `10`, `10.13`, `12`, `12.10`, `14` or `'current'` (`process.versions.node`)
24- `loose`: Enable “loose” transformations for any plugins in this preset that allow them (Disabled by default).
25- `modules` - Enable transformation of ES6 module syntax to another module type (Enabled by default to "commonjs"). Can be false to not transform modules, or "commonjs"
26- `es2019` - Enable es2019 features (Enabled by default)
27- `es2020` - Enable es2020 features (Enabled by default)
28- `shippedProposals` - Enable features in stages but already available in recent node version (Enabled by default)
29
30## [Compatibility Table](http://node.green/)
31
32| Feature | Node 10 | Node 10.13 | Node 12 | Node 14 | Node 14.8 |
33| --------------------------------------------------------------------------------------------------------------- | ------- | ---------- | ------- | --------- | --------- |
34| <h3>ES2015</h3> | | | | |
35| [transform-modules-commonjs](https://www.npmjs.com/package/@babel/plugin-transform-modules-commonjs) | flag | flag | flag | with .mjs | with .mjs |
36| <h3>ES2019</h3> | | | | |
37| [syntax-optional-catch-binding](https://www.npmjs.com/package/@babel/plugin-syntax-optional-catch-binding) | flag | yes | yes | yes | yes |
38| [json-strings](https://www.npmjs.com/package/@babel/plugin-proposal-json-strings) | yes | yes | yes | yes | yes |
39| <h3>ES2020</h3> | | | | |
40| [nullish-coalescing-operator](https://www.npmjs.com/package/@babel/plugin-proposal-nullish-coalescing-operator) | no | no | no | yes | yes |
41| [optional-chaining](https://www.npmjs.com/package/@babel/plugin-proposal-optional-chaining) | no | no | no | yes | yes |
42| <h3>Shipped Proposals</h3> | | | | |
43| [numeric-separator](https://www.npmjs.com/package/@babel/plugin-proposal-numeric-separator) | no | no | no | yes | yes |
44| [top-level-await](https://www.npmjs.com/package/@babel/plugin-syntax-top-level-await) | no | no | no | no | yes |
45
46Note that top level await is syntax only and is only available for supported versions.
47
48## Install
49
50```bash
51npm install --save-dev @babel/core babel-preset-latest-node
52yarn add --dev @babel/core babel-preset-latest-node
53```
54
55## Usage
56
57### Via `.babelrc`
58
59**.babelrc**
60
61```json
62{
63 "presets": ["latest-node"]
64}
65```
66
67```json
68{
69 "presets": [["latest-node", { "target": "current" }]]
70}
71```
72
73### Via CLI
74
75```sh
76babel script.js --presets latest-node
77```
78
79### Via Node API
80
81```javascript
82require('babel-core').transform('code', {
83 presets: [require('babel-preset-latest-node')],
84});
85```
86
87```javascript
88require('babel-core').transform('code', {
89 presets: [[require('babel-preset-latest-node'), { target: 'current' }]],
90});
91```