On a working machine, you can create your scripts with the command
NODE_ENV=production webpack
On the other hand, passing this variable to /etc/environment also a solution.
process.env.NODE_ENV converted to a static string in bundle.js
for example, if you run NODE_ENV=production webpack in this snippet
if(process.env.NODE_ENV == 'development'){ console.log('this is visible in development'); }
in bundle.js you will find (edited)
if ('production' == 'development') { console.log('this is visible in development'); }
if (false) { // 'production' == 'development' console.log('this is visible in development'); }
So, in accordance with the question of enabling / disabling functions, your code is valid.
If you want to remove the condition body, if it is false (as in the above example, you do not want to show console.log('this is visible in development'); in the production environment), you should use
new webpack.optimize.UglifyJsPlugin()
It will remove all your if statements with the false condition.
source share