Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

accessing environment variable from react component

I have some non-sensitive data that I need to set to different values based on what environment node runs in staging or production. I believe accessing something like process.env.NODE_ENV will not work within a react component itself, only in a server-side file, hence need a way to somehow pass this down to my react component.

It is simply to show if string "Staging" or "Production" inside the footer component.

like image 789
Ilja Avatar asked Jun 28 '16 11:06

Ilja


1 Answers

Consider using the DefinePlugin:

Define free variables. Useful for having development builds with debug logging or adding global constants.

Example:

new webpack.DefinePlugin({
    VERSION: JSON.stringify("5fa3b9"),
    BROWSER_SUPPORTS_HTML5: true,
    TWO: "1+1",
    "typeof window": JSON.stringify("object")
})
like image 96
CD.. Avatar answered Sep 17 '22 23:09

CD..