Answer the question
In order to leave comments, you need to log in
How to use webpack's mode/variable in js code?
The webpack.config is set to mode = 'development'
how can I use this variable in the code to display some debug messages depending on the mode, and ideally if the mode is 'production' so that this extra code does not exist at all.
Something like:
if you write like this, then it writes undefined, but I can’t understand how to make this variable available in the code.
if (mode == 'development') console.log (mode);
Answer the question
In order to leave comments, you need to log in
// js (НЕ webpack.config.js)
console.log(process.env.NODE_ENV)
process.env.NODE_ENV
will not work in the webpack config file, for webpack version 4. Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question