Gle*_*ift 6 javascript webpack babeljs create-react-app babel-plugin
我正在通过以下.babelrc 使用babel-preset-react-app:
{
"presets": ["react-app"],
"plugins": [
"transform-es2015-modules-commonjs",
"transform-async-generator-functions"
]
}
Run Code Online (Sandbox Code Playgroud)
我需要覆盖babel-plugin-transform-runtime选项。我尝试通过以下方式安装插件并将其添加到.babelrc中:
{
"presets": ["react-app"],
"plugins": [
["babel-plugin-transform-runtime", {
"helpers": false,
"polyfill": false,
"regenerator": false
}],
"transform-es2015-modules-commonjs",
"transform-async-generator-functions"
]
}
Run Code Online (Sandbox Code Playgroud)
但这对我不起作用。
有什么办法可以完成而无需复制整个预设并将其粘贴到.babelrc中?
Babel 目前似乎不支持此类覆盖(请参阅https://github.com/babel/babel/issues/8799)。幸运的是我找到了一个解决方法babel-preset-react-app。有一个未记录的选项useESModules:
['react-app', { useESModules: false }]
这是适用于 Node.js 的配置babel-plugin-react-app:
presets: [
['react-app', { useESModules: false }],
[
'@babel/preset-env',
{
modules: 'commonjs',
targets: {
node: 'current',
},
},
],
],
Run Code Online (Sandbox Code Playgroud)
当然,如果您用于客户端捆绑包,则使用babel-preset-react-app最有意义。create-react-app如果您不使用create-react-app,那么您可以考虑直接使用@babel/preset-react,在这种情况下您无需担心覆盖该useESModules设置。
| 归档时间: |
|
| 查看次数: |
192 次 |
| 最近记录: |