Merge branch 'master' into 2.0

This commit is contained in:
Brian Ng 2017-09-18 20:15:30 -05:00
commit 9f0f8d99d5
2 changed files with 43 additions and 3 deletions

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2016 Babel
Copyright (c) 2016-2017 Babel
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -1,11 +1,23 @@
# babel-preset-env [![npm](https://img.shields.io/npm/v/babel-preset-env.svg)](https://www.npmjs.com/package/babel-preset-env) [![travis](https://img.shields.io/travis/babel/babel-preset-env/master.svg)](https://travis-ci.org/babel/babel-preset-env) [![npm-downloads](https://img.shields.io/npm/dm/babel-preset-env.svg)](https://www.npmjs.com/package/babel-preset-env) [![codecov](https://img.shields.io/codecov/c/github/babel/babel-preset-env/master.svg?maxAge=43200)](https://codecov.io/github/babel/babel-preset-env)
> A Babel preset that can automatically determine the Babel plugins and polyfills you need based on your supported environments.
> A Babel preset that compiles [ES2015+](https://github.com/tc39/proposals/blob/master/finished-proposals.md) down to ES5 by automatically determining the Babel plugins and polyfills you need based on your targeted browser or runtime environments.
```sh
npm install babel-preset-env --save-dev
```
Without any configuration options, babel-preset-env behaves exactly the same as babel-preset-latest (or babel-preset-es2015, babel-preset-es2016, and babel-preset-es2017 together).
```json
{
"presets": ["env"]
}
```
You can also configure it to only include the polyfills and transforms needed for the browsers you support. Compiling only what's needed can make your bundles smaller and your life easier.
This example only includes the polyfills and code transforms needed for the last two versions of each browser, and versions of Safari greater than or equal to 7. We use [browserslist](https://github.com/ai/browserslist) to parse this information, so you can use [any valid query format supported by browserslist](https://github.com/ai/browserslist#queries).
```json
{
"presets": [
@ -18,6 +30,34 @@ npm install babel-preset-env --save-dev
}
```
Similarly, if you're targeting Node.js instead of the browser, you can configure babel-preset-env to only include the polyfills and transforms necessary for a particular version:
```json
{
"presets": [
["env", {
"targets": {
"node": "6.10"
}
}]
]
}
```
For convenience, you can use `"node": "current"` to only include the necessary polyfills and transforms for the Node.js version that you use to run Babel:
```json
{
"presets": [
["env", {
"targets": {
"node": "current"
}
}]
]
}
```
- [How it Works](#how-it-works)
- [Install](#install)
- [Usage](#usage)
@ -58,7 +98,7 @@ If you are targeting IE 8 and Chrome 55 it will include all plugins required by
### Support a target option `"node": "current"` to compile for the currently running node version.
For example, if you are building on Node 4, arrow functions won't be converted, but they will if you build on Node 0.12.
For example, if you are building on Node 6, arrow functions won't be converted, but they will if you build on Node 0.12.
### Support a `browsers` option like autoprefixer.