Reputation: 494
I'm trying to add environment variables to a SPO Webpart written in React. The webpart has a dependency on an API and the instance of the API to be used varies depending on the environment. Webpart deployed to IST should use the IST API. Webpart deployed to UAT should use the UAT instance of the API.
In regular app development this is straightforward. But not for React Webparts.
I've gone through and tried the following:
Using .env files in SharePoint Framework development
How To Handle Env Variable Using DefinePlugin In SPFx Solutions
Read and manipulate SPFx configuration values in your code like a boss
Using environment variables in React
SPFx environment variable for CI / CD for SharePoint on-premise
Does anyone have a working solution?
Upvotes: 1
Views: 668
Reputation: 938
The first link you posted helped me, I got it working as described here: Environment variables in a React SharePoint Webpart?
The trick is to prefix the environment variables with SPFX_
, otherwise it does not work.
Upvotes: 0