I have a react preset, and I want to pass pragma params to transform-react-jsx.
For now I’m installing transform-react-jsx separatly and set my .babelrc
like so:
{
"presets": [
"react"
],
"plugins": [
["transform-react-jsx", {
"pragma": "dom.hJSX"
}]
]
}
But I wonder if there is another way to pass settings to plugins in presets.
Ordering matters for each visitor in the plugin. This means if two transforms both visit “Program”, the transforms will run in either plugin or preset order.
Using a Plugin If the plugin is on npm, you can pass in the name of the plugin and Babel will check that it's installed in node_modules . This is added to the plugins config option, which takes an array. You can also specify an relative/absolute path to your plugin.
In Babel, a preset is a set of plugins used to support particular language features. The two presets Babel uses by default: es2015 : Adds support for ES2015 (or ES6) JavaScript. react : Adds support for JSX.
@babel/preset-env is a smart preset that allows you to use the latest JavaScript without needing to micromanage which syntax transforms (and optionally, browser polyfills) are needed by your target environment(s). This both makes your life easier and JavaScript bundles smaller!
So I got to babel github and as I found out now there is no way to pass settings to plugins in presets.
On the bright side there is another discussion that could turn into something sometime sooner or later.
UPD: babel moved all issues to phabricator and these discussions seem to be lost forever. However this feature seems to be a step forward towards solving the issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With