[英]How to overwrite babel's preset plugin options
I'm using babel-preset-react-app via following .babelrc: 我通过以下.babelrc使用babel-preset-react-app :
{
"presets": ["react-app"],
"plugins": [
"transform-es2015-modules-commonjs",
"transform-async-generator-functions"
]
}
I need to overwrite babel-plugin-transform-runtime
options. 我需要覆盖
babel-plugin-transform-runtime
选项。 I tried installing plugin and adding it to .babelrc in a following way: 我尝试安装插件并以下列方式将其添加到.babelrc:
{
"presets": ["react-app"],
"plugins": [
["babel-plugin-transform-runtime", {
"helpers": false,
"polyfill": false,
"regenerator": false
}],
"transform-es2015-modules-commonjs",
"transform-async-generator-functions"
]
}
but it doesn't work for me. 但它对我不起作用。
Is there any way I can do it without copy and pasting entire preset to my .babelrc? 有没有办法我可以做到没有复制并将整个预设粘贴到我的.babelrc?
It seems that Babel doesn't currently support these sorts of overrides (see https://github.com/babel/babel/issues/8799 ). 似乎Babel目前不支持这些类型的覆盖(请参阅https://github.com/babel/babel/issues/8799 )。 Fortunately I found a workaround for
babel-preset-react-app
. 幸运的是,我找到了
babel-preset-react-app
的解决方法。 There is an undocumented option, useESModules
: 有一个未记录的选项,
useESModules
:
['react-app', { useESModules: false }]
Here's a config using babel-plugin-react-app
that works for node.js: 这是使用适用于node.js的
babel-plugin-react-app
的配置:
presets: [
['react-app', { useESModules: false }],
[
'@babel/preset-env',
{
modules: 'commonjs',
targets: {
node: 'current',
},
},
],
],
Of course, using babel-preset-react-app
makes the most sense if you're using create-react-app
for your client-side bundle. 当然,如果你正在为你的客户端捆绑使用
create-react-app
,那么使用babel-preset-react-app
最有意义。 If you're not using create-react-app
, then you could consider just using @babel/preset-react directly, in which case you wouldn't need to worry about overriding the useESModules
setting. 如果你没有使用
create-react-app
,那么你可以考虑直接使用@ babel / preset-react ,在这种情况下你不必担心覆盖useESModules
设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.