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