question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support custom babel presets & plugins via environment variables

See original GitHub issue

Hello, I found an easy way to enable additional presets & plugins in my fork of react-scripts. I want to share it with others and the maintainer of this original repository may find this feature useful and add it to the main react-scripts.

Basically, what I did was just introducing two environment variables BABEL_PRESETS and BABEL_PLUGINS, which accept JSON encoded list of path strings. Users can enable any kind of presets/plugins by specify those two variables before they run npm start.

For example, I need to enable react-relay support. What I did is just execute this command before I start the development server:

export BABEL_PLUGINS="[\"`pwd`/plugins/relay-plugin.js\"]"

With my forked react-scripts (@philiptzou/react-scripts) and other related relay packages installed, the webpack server is able to handle Relay.QL syntax now.

I just noticed that we can use .env file to specify REACT_APP_ initial variables. It maybe a more elegant way to do this in the future.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
philiptzoucommented, Dec 5, 2016

Using .babelrc is more gentle and friendly than my above solution. And we can still have the default settings for everyone who doesn’t want or need customizations.

1reaction
spudlycommented, Dec 2, 2016

My 2¢:

I would love to have the ability to add custom presets. At the moment, my only option is to fork the repo. I also understand why you would want to wait to implement something like this.

When you are ready to support something like this, I’d like it to just let me configure babel the way I do in all my other projects (using the babel key in package.json, or a .babelrc file).

Would you (eventually) accept a pull request that would make the webpack config file autodetect a .babelrc or package.json/babel key and (if detected), use that config instead of babel-preset-react-app?

Read more comments on GitHub >

github_iconTop Results From Across the Web

babel/preset-env
@babel/preset-env takes any target environments you've specified and checks them against its mappings to compile a list of plugins and passes it to...
Read more >
environment variables in babel.config.js - Stack Overflow
1 Answer 1 · Install the plugin npm install babel-plugin-inline-dotenv · Include the plugin and the path to the .env file in your...
Read more >
Advanced Features: Customizing Babel Config - Next.js
To add presets/plugins with custom configuration, do it on the next/babel preset like so: { "presets": [ [ "next/babel", { "preset-env": {} ...
Read more >
Environment variables and Babel | harrytheo.com
Install the plugin with npm install babel-plugin-inline-dotenv; Include the plugin and the path to the .env file in your Babel config file:.
Read more >
Babel | Gatsby
If you'd like to add custom Babel presets or plugins, you can create your own .babelrc at the root of your site, import...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found