babeljsbabel-preset-env

babel-preset-env runtime version check


babel-preset-env allows to automatically determine the needed polyfills and transformation but how does it check at runtime if the target versions specified at compile time are really available.

Let say I target safari 10 using

"targets": {
   "safari": 10
}

but the code is run on an older version of safari.

How does babel-preset-env recognize this or what are the typical ways to deal with this common problem?


Solution

  • babel-preset-env does not carry out any runtime checks. It enables only the transforms that are required for your specified environment. You're effectively setting your minimum supported environment, and opting out of any transforms that would be required to support lower versions.

    For example, if all of the browser versions specified in my config supported ES2015 classes, Babel would not transform classes into an ES5-supported form, since it's not necessary to do so!