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"
  ]
}
相關文章
相關標籤/搜索