I am setting up Redux DevTools (https://www.npmjs.com/package/redux-devtools) in my project and want to exclude the DevTools when building my project for production. The documentation says that this can be accomplished by using this code:
if (process.env.NODE_ENV === 'production') {
module.exports = require('./configureStore.prod');
} else {
module.exports = require('./configureStore.dev');
}
I already have a module with constants so I have put the checking for the NODE_ENV in there.
Constants.PRODUCTION = process.env.NODE_ENV === 'production'
In my Webpack config file I have the following code that works like it should:
const production = process.env.NODE_ENV === 'production'
var config = {
// configuration goes here
}
if (production) {
config.plugins = [
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
},
}),
].concat(config.plugins)
}
When running set NODE_ENV=production&&webpack
the build get's minified and using just webpack
dosen't minify the build. However, in the source code itself the NODE_ENV is undefined:
console.log(process.env.NODE_ENV) // Output: Undefined
If I set my Constants.PRODUCTION
to true
then DevTools is not included in the build. Somehow I am supposed to use DefinePlugin or ProvidePlugin (the Redux DevTools documentation mention them both but on different places), but I can't figure out how. I am using Windows 10, DevTools 3.0.0 and npm scripts to run the build process. Can anyone help me with how I'm supposed to set up DefinePlugin or ProvidePlugin in my webpack config file?
production
variable. Thanks. – Deontology