ECMAScript Cookbook
上QQ阅读APP看书,第一时间看更新

There's more...

The previous recipe uses the ES2015 preset. This means that Babel will always produce ES2015 (ES5)-compatible code regardless of current browser support.

The Babel env preset is more sophisticated, and uses platform compatibility to determine which language features need to be translated. See the following example from the project readme:

 // .baberc 
{ 
  "presets": [ 
    ["env", { 
   "targets": { 
     "browsers": ["last 2 versions", "safari >= 7"] 
   } 
 }] 
  ] 
} 

The preceding configuration targets the last two version of all browsers except Safari, which is targeted all the way back to version 7. This project allows Babel to discard translations that are no longer needed as browsers implement more language features.

You can find more documentation and support for the babel-preset-env project at its repository at:  https://github.com/babel/babel-preset-env.