Parcel: 馃檵 Environment Variables

Created on 14 Dec 2017  路  5Comments  路  Source: parcel-bundler/parcel

馃檵 Feature request

Define process.env variables within the bundle (similar to Webpack's EnvironmentPlugin, which relies on DefinePlugin).

馃 Expected Behavior



Add a plugin that reads environment variables and injects them into the bundle such that code can rely on process.env.VAR in browser.

馃槸 Current Behavior



There doesn't seem to be a simple way to define environment variables, this would add a simple way to add environment variables.

馃拋 Possible Solution


This plugin could use dotenv so that in order to define environment variables you can define a .env or .env.development or .env.production in the root of the project. This would make it pretty straight forward to use environment variables; however, it does raise the question of how to pass environment variables into a project without relying on dotenv (host environment variables).

馃敠 Context


An internal library relies on a variable being set in process.env - with Webpack, we use the EnvironmentPlugin to add it in.

馃實 Your Environment

| Software | Version(s)
| ---------------- | ----------
| Parcel | 1.2.0
| Node | ^8
| npm/Yarn | Yarn 1.3.2
| Operating System | macOS

Help Wanted Feature

Most helpful comment

You can just set environment variables in your shell when building. e.g.

SOME_VAR=test parcel index.html

and process.env.SOME_VAR will automatically be replaced with the value.

All 5 comments

You can just set environment variables in your shell when building. e.g.

SOME_VAR=test parcel index.html

and process.env.SOME_VAR will automatically be replaced with the value.

It will be nice if we could have a similar way to set custom environment variables like in Create react app https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#adding-custom-environment-variables

May be just babel-plugin-transform-inline-environment-variables to not bload the code base?

@devongovett that works, but as the original post commented, it'd really be good to have production/development env vars picked up automatically based on whether it's a build or not. I use this feature heavily in CRA and find it invaluable.

Having said that, I think this project looks _incredibly_ promising, so keep up the good work!

moving to #258. See additional discussion there.

Was this page helpful?
0 / 5 - 0 ratings