babel-runtime 和 babel-polyfill

Babel 默认只转换新的 JavaScript 语法html

babel-plugin-transform-runtime:babel打包的一个plugin,用来把babel-runtime polyfill注入到代码里json

babel-preset-es2015:ES6的语法转换,Generator的ployfill,打包代码的方式(amd,commonjs,systemjs,umd)浏览器

babel-runtime:Generator的ployfill,ES6 polyfill 集合babel

babel-polyfill:Generator的ployfill,ES6 polyfill 集合函数

babel-plugin-transform-runtime
    babel-runtime
        core-js // ES6 polyfill
        regenerator-runtime // Generator polyfill
babel-polyfill
    babel-runtime
        core-js // ES6 polyfill
        regenerator-runtime // Generator polyfill
    regenerator-runtime // Generator polyfill
    core-js // ES6 polyfill

babel-polyfill工具

Babel 默认只转换新的 JavaScript 语法,而不转换新的 API。例如,Iterator、Generator、Set、Maps、Proxy、Reflect、Symbol、Promise 等全局对象,以及一些定义在全局对象上的方法(好比 Object.assign)都不会转译。若是想使用这些新的对象和方法,必须使用 babel-polyfill,为当前环境提供一个垫片。post

babel-runtimeui

babel-runtime 是为了减小重复代码而生的。babel-runtime插件可以将这些工具函数的代码转换成require语句,指向为对babel-runtime的引用。插件

babel-plugin-transform-runtimecode

以插件的形式在打包时引入到文件里

指定plugin

默认的若是使用了 babel-preset-es2015 的 preset,那么就意味着你必需要使用全部的plugin,若是浏览器已经支持了Generator,你不想作转换,你能够使用这个库 babel-preset-es2015-without-regenerator

或者你能够本身定义plugin,把 babel-preset-es2015 里面的依赖抽取出来。自定义配置。好比这个没有 regenerator transform的babelrc配置

{
  "presets": [],
  "plugins": [
    "babel-plugin-check-es2015-constants",
    "babel-plugin-transform-es2015-arrow-functions",
    "babel-plugin-transform-es2015-block-scoped-functions",
    "babel-plugin-transform-es2015-block-scoping",
    "babel-plugin-transform-es2015-classes",
    "babel-plugin-transform-es2015-computed-properties",
    "babel-plugin-transform-es2015-destructuring",
    "babel-plugin-transform-es2015-duplicate-keys",
    "babel-plugin-transform-es2015-for-of",
    "babel-plugin-transform-es2015-function-name",
    "babel-plugin-transform-es2015-literals",
    "babel-plugin-transform-es2015-modules-commonjs",
    "babel-plugin-transform-es2015-object-super",
    "babel-plugin-transform-es2015-parameters",
    "babel-plugin-transform-es2015-shorthand-properties",
    "babel-plugin-transform-es2015-spread",
    "babel-plugin-transform-es2015-sticky-regex",
    "babel-plugin-transform-es2015-template-literals",
    "babel-plugin-transform-es2015-typeof-symbol",
    "babel-plugin-transform-es2015-unicode-regex"
  ]
}
相关文章
相关标签/搜索