Babel 默認只轉換新的 JavaScript 語法
babel-plugin-transform-runtime:babel打包的一個plugin,用來把babel-runtime polyfill注入到代碼里
babel-preset-es2015:ES6的語法轉換,Generator的ployfill,打包代碼的方式(amd,commonjs,systemjs,umd)
babel-runtime:Generator的ployfill,ES6 polyfill 集合
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,為當前環境提供一個墊片。
babel-runtime
babel-runtime 是為了減少重復代碼而生的。babel-runtime插件能夠將這些工具函數的代碼轉換成require語句,指向為對babel-runtime的引用。
babel-plugin-transform-runtime
以插件的形式在打包時引入到文件里
指定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"
]
}