Reputation: 1004
It is my first time working on the Front end. The application is Node plus react. It has the below directories:
--config
--flow-typed
--node_modules
--script
--server
--src
There is a radio button on the app which has a default selected value now. I need to pick up the value from the system registry. The file where the default value for the radio is being set is in a package under /src.
Instead of :
color: Colors.RED
I need to do
color: process.env.COLOR
When I do above, the radio button now has no value selected by default.
If I add a constant in
/config/env.js as :
const COLOR = process.env.COLOR;
console.log("-------------COLOR IS :" + COLOR);
It logs correctly. But it is not being picked up from under the
/src/myconcerneddirectory.
Under /scripts, there is a start.js, I have added the process.env.COLOR there for testing purposes. I start the app using npm start(for node) and npm run start-server(for react).
Upvotes: 0
Views: 36
Reputation: 51
In a case you use webpack, you need to specify your global variable (in your case it’s the process.env.COLOR) in your webpack config. That you can do with DefinePlugin. https://webpack.js.org/plugins/define-plugin/
new webpack.DefinePlugin({
'process.env.COLOR': process.env.COLOR
});
Upvotes: 1