一个 includes 不兼容引发的基础学习
ECMAScript
ES5 - 2009完成
ES6/ES2015 2015
ECMAScript 2016 (includes)
ECMAScript 2016 (ECMA-262)
The definition of 'Array.prototype.includes' in that specification. Standard
ECMAScirpt Proposals
Polyfill
polyfill and shim
polyfill rewrite prototype 、shim new methods
{
"presets": [
["env", {
"modules": false,
"targets": {
"browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
}
}],
"es2015",
"stage-2"
],
"plugins": ["transform-vue-jsx", "transform-runtime"],
"env": {
"test": {
"presets": ["env", "stage-2"],
"plugins": ["transform-vue-jsx",
"transform-es2015-modules-commonjs",
"dynamic-import-node"]
}
}
}
presets - plugin 集合 (从最后一个执行)
plugins - 单一特殊代码转换 (先执行)
{
"presets": [
["env", {
"modules": false,
"targets": {
"browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
}
}],
"es2015",
"stage-2"
]
}
preset
es2015 es6
react
stage-0 transform-do-expressions / transform-function-bind (向下包含)
stage-1
stage-2
...
语法转义器。主要对javascript最新的语法糖进行编译
并不负责转译javascript新增的api和全局对象
babel-polyfill ->(core-js)-> includes
https://babeljs.io/docs/usage/polyfill/
transform-runtime -> babel-runtime (可配置 polyfill)
https://babeljs.io/docs/plugins/transform-runtime
* 不支持实例化的方法Array.includes(x) 就不能转化
* 如果使用的API用的次数不是很多,那么transform-runtime 引入polyfill的包会比不是transform-runtime 时大
The main difference is that polyfill works for all polyfills but must be installed as a production dependency. And you need to use import 'babel-polyfill'; to make it work. And it will pollute the global scope.
The transform-runtime provides many of the same features, but won't provide special functions like array.includes() or array.values(). So it's safer to use inside a library.
If you're building an app, you can use babel-polyfill. If you're building a library, make sure not to use babel-polyfill, and only the transform-runtime.
You'll need to find alternatives for implementing any of the functions like array.includes or array.values().
module.exports = {
"plugins": {
"postcss-import": {},
"postcss-url": {},
"autoprefixer": {
"browsers": "> 5%"
}
}
}
browserlist
Version Map
babel
By pokerone
babel
- 765