M
M
Michael2018-06-23 08:14:43
webpack
Michael, 2018-06-23 08:14:43

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

1 answer(s)
N
Nikita Egorov, 2018-06-24
@sibidor

// js (НЕ webpack.config.js)

console.log(process.env.NODE_ENV)

The environment variable process.env.NODE_ENVwill not work in the webpack config file, for webpack version 4.
Specify the environment

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question