facebook / metro

🚇 The JavaScript bundler for React Native
https://metrobundler.dev
MIT License
5.24k stars 626 forks source link

[Feature] Pass through environment variables #634

Open mikeduminy opened 3 years ago

mikeduminy commented 3 years ago

Do you want to request a feature or report a bug? Feature

What is the current behavior? Environment variables set outside of metro server are not available in the initial bundle of the

What is the expected behavior? Webpack allows explicit environment variable pass through to bundle via a plugin. https://webpack.js.org/plugins/environment-plugin/

I'd like this sort of thing to be supported in metro too.

wnatrifork commented 1 month ago

There is already a babel plugin for such a feature: https://www.npmjs.com/package/babel-plugin-transform-inline-environment-variables

However, there's an error in the documentation. The .babelrc configuration should look like this:

{
  "plugins": ["babel-plugin-transform-inline-environment-variables"]
}