作为标题,我正在学习巴别塔和我试图理解的最新版本
@babel/plugin-transform-runtime
,以下是我目前的结论:
-
从我的设置
@babel/preset-env
下面,我将需要安装
core-js@3
-
(我不确定)但是自从
@babel/插件转换运行时
require("@babel/runtime...")
相反,在那里我们仍然需要进行多边形填充,所以
@babel/runtime-corejs3
,这是的依赖项
@babel/插件转换运行时
核心-js@3
或者类似的。
我猜
那
应包括
core-js
,所以我不需要安装它。我已经测试过如果我移除
包裹json
npm run server
npx babel src --out-dir dist
仍然可以在没有任何错误的情况下运行。那么要点是什么呢?
.巴别LRC。js
:
const presets = [
[
"@babel/preset-env",
{
"useBuiltIns": "usage",
"corejs": "3.13",
"debug": true
}
]
]
const plugins = [
[
"@babel/plugin-transform-runtime",
{ "corejs": 3 }
]
]
包裹json
{
"name": "official-docs",
"version": "1.0.0",
"description": "",
"main": "src/index.js",
"scripts": {
"server": "npx webpack serve",
"build": "npx webpack --watch"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/cli": "^7.14.8",
"@babel/core": "^7.14.8",
"@babel/plugin-transform-arrow-functions": "^7.14.5",
"@babel/plugin-transform-classes": "^7.14.9",
"@babel/plugin-transform-computed-properties": "^7.14.5",
"@babel/plugin-transform-runtime": "^7.15.0",
"@babel/preset-env": "^7.14.9",
"babel-loader": "^8.2.2",
"html-webpack-plugin": "^5.3.2",
"webpack": "^5.48.0",
"webpack-cli": "^4.7.2",
"webpack-dev-server": "^4.0.0"
},
"dependencies": {
"@babel/runtime": "^7.15.3",
"@babel/runtime-corejs2": "^7.15.3",
"@babel/runtime-corejs3": "^7.15.3",
"core-js": "^3.16.2", // <------ I've tested removing this line.
"jquery": "^3.6.0"
}
}
test01。js
:
function* bar() {}
let foo = () => {
if ("foobar".includes("foo")) {
return 2
}
return 1
}
class List {
constructor(pi = 1, ps = 10) {
this.pi = 1
this.ps = 10
}
loadData() {
}
static genId() {
return ++this.id
}
}
let name = 'raining'
let obj = {
baseName: name,
[name + '_id']: 'baseName'
}
产量
:
@babel/preset-env: `DEBUG` option
Using targets:
{}
Using modules transform: auto
Using plugins:
proposal-class-properties { }
proposal-private-methods { }
proposal-numeric-separator { }
proposal-logical-assignment-operators { }
proposal-nullish-coalescing-operator { }
proposal-optional-chaining { }
proposal-json-strings { }
proposal-optional-catch-binding { }
transform-parameters { }
proposal-async-generator-functions { }
proposal-object-rest-spread { }
transform-dotall-regex { }
proposal-unicode-property-regex { }
transform-named-capturing-groups-regex { }
transform-async-to-generator { }
transform-exponentiation-operator { }
transform-template-literals { }
transform-literals { }
transform-function-name { }
transform-arrow-functions { }
transform-block-scoped-functions { }
transform-classes { }
transform-object-super { }
transform-shorthand-properties { }
transform-duplicate-keys { }
transform-computed-properties { }
transform-for-of { }
transform-sticky-regex { }
transform-unicode-escapes { }
transform-unicode-regex { }
transform-spread { }
transform-destructuring { }
transform-block-scoping { }
transform-typeof-symbol { }
transform-new-target { }
transform-regenerator { }
transform-member-expression-literals { }
transform-property-literals { }
transform-reserved-words { }
proposal-export-namespace-from { }
transform-modules-commonjs
proposal-dynamic-import
corejs3: `DEBUG` option
Using targets: {}
Using polyfills with `usage-global` method:
regenerator: `DEBUG` option
Using targets: {}
Using polyfills with `usage-global` method:
[.../babel-practice/official-docs/src/index.js]
Based on your code and targets, the corejs3 polyfill did not add any polyfill.
[.../babel-practice/official-docs/src/index.js]
Based on your code and targets, the regenerator polyfill did not add any polyfill.
[.../babel-practice/official-docs/src/test01.js]
Based on your code and targets, the corejs3 polyfill did not add any polyfill.
[.../babel-practice/official-docs/src/test01.js]
Based on your code and targets, the regenerator polyfill did not add any polyfill.
Successfully compiled 2 files with Babel (366ms).