This is a general question though I haven't found where I am going wrong. Using Windows Server with Azures kudu stand alone to host a local project. Also using React, Webpack, Redux
Windows environment var is set to production Package.json has set NODE_ENV=production && etc.. for both start and build scripts web.config has iisnode node_env=production
running node I get the node_env is indeed production However when I build it's giving me the development build when I do something like
if (process.env.NODE_ENV === 'production') {
module.exports = require('./buildProduction.js')
}
else {
module.exports = require('./buildDevelopment.js')
}
What gives?
I came to the same conclusion and searched why this is and thanks to neagtivetwelve for the comment @ https://github.com/webpack/webpack/issues/1720
In short setting
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
}),
fixes the issue. Instead of
new webpack.DefinePlugin({
'process.env.NODE_ENV': process.env.NODE_ENV,
}),
Even though I have in the build script to set the session NODE_ENV var and set within the system environment vars I would still get the wrong result until this change was made even though opening node from cmd and typing process.env.NODE_ENV yields the correct result. Anyway I hope it helps someone else.