I'm trying to set an external config in my webpack according to the NODE_ENV.
Here's my script code from package.json:
"scripts": {
"build": "set NODE_ENV=production && webpack --mode production",
"start": "webpack-dev-server --hot --mode development"
},
Then in my webpack.config.js I have the following code:
externals: {
'Config': JSON.stringify(process.env.NODE_ENV === 'production' ? {
apiUrl: "."
} : {
apiUrl: "http://localhost:3000"
})
},
Somehow this doesn't work. I always get the "false" (localhost) as value. I'm 100 % sure process.env.NODE_ENV is set since first of all, I log it at the beginning of the file (console.log(process.env.NODE_ENV)) and it gives me "production" as answer.
Second, I tried to create another config like:
externals: {
'Test': {"mytest": process.env.NODE_ENV } ...
and this sets mytest to "production" ....
I have no idea why this doesn't work, I copied the code from stackoverflow (How to store Configuration file and read it using React).
I tried everything... I wrapped around the JSON.stringify around other parts, I tried to debuff as good as I can. Its now the 4th hour I spend on this problem and I think its a good moment to ask here for some advise.
If you can help me solve this problem, I would be really thankful!
Have a nice day.