2017年Babel 的官网上在9月宣布 ES2015 / ES2016/ ES2017 等等 ES20xx 时代的 presets 统统被废弃(deprecated),取而代之的是 babel-preset-env,而且承诺它将成为“将来不会过期的(future-proof)”解决方案。git
也就是说: babel preset将基于你的实际浏览器及运行环境,自动的肯定babel插件及polyfills,转译ES2015及此版本以上的语言。 github
npm install babel-preset-env --save-dev
在没有配置项的状况下,babel-preset-env表现的同babel-preset-latest同样(或者能够说同babel-preset-es2015, babel-preset-es2016, and babel-preset-es2017结合到一块儿,表现的一致),具体的操做方法能够参考:http://www.javashuo.com/article/p-hkmonhiz-gq.htmlnpm
安装 babel-preset-es2015 时segmentfault
npm install --save-dev babel-preset-es2015
你会发现有以下的 Deprecated警告(文字很欢乐):浏览器
babel-preset-es2015@6.24.1: We're super ? excited that you're trying to use ES2015 syntax, but instead of making more yearly presets ? , Babel now has a better preset that we recommend you use instead: npm install babel-preset-env --save-dev. preset-env without options will compile ES2015+ down to ES5 just like using all the presets together and thus is more future proof. It also allows you to target specific browsers so that Babel can do less work and you can ship native ES2015+ to user ? ! We are also in the process of releasing v7, so please give http://babeljs.io/blog/2017/09/12/planning-for-7.0 a read and help test it out in beta! Thanks so much for using Babel ?, please give us a follow on Twitter @babeljs for news on Babel, join http://slack.babeljs.io for discussion/development and help sup port the project at opencollective.com/babel
是的,在2017年第三季度咱们终于要和 ES2015 preset 说再见了。babel
那么你可能会问咱们是要迁移到 ES2017 了吗?事实上并不是如此,babel-preset-es2017 只是增长了一些特性而已,且仍然须要安装 ES2015。less
为了节省你的阅读时间,我先给出一个如何升级的简单版:spa
首先卸载原来的 preset,而后安装 babel-preset-env:插件
npm uninstall --save-dev babel-preset-es2015 npm install --save-dev babel-preset-env@next
接下来将你的 .babelrc 文件中“es2015”修改“env”:code
{ "presets": [ "env" ], ... }
好了,恭喜你,就这么简单,你已经能够与 ES2015+ 保持更新了!
更近一步能够参考: https://zhuanlan.zhihu.com/p/29506685