Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass params to plugins in presets in babel 6?

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.

like image 672
alice kibin Avatar asked Nov 11 '15 18:11

alice kibin


People also ask

Does Babel preset order matter?

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.

Where do I put Babel plugins?

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.

What are presets and plugins in Babel?

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.

What is preset ENV in Babel?

@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!


1 Answers

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.

like image 119
alice kibin Avatar answered Oct 29 '22 19:10

alice kibin