Using DefinePlugin to set process.env.NODE_ENV, it remains unset in babel-loader. It is available in other steps, as webpack is able to drop requires inside conditionals checking NODE_ENV.
babel-loader explicitly checks for process.env.NODE_ENV in order to pass it on to babel, but it is undefined.
Ah, that was it, thanks. In
webpack.config.js
If I doin addition to configuring DefinePlugin, it is available to babel-loader as well as the other processors.
@imjared DefinePlugin transforms code parsed by webpack after all loaders. It doesn’t do anything to the global environment. You can either literally set NODE_ENV in your
webpack.config.js
file as a single statement or set the environment when running webpack.OR
If there is code that is going into the webpack’d source that tests process.env.NODE_ENV, you’ll want both DefinePlugin and the actual shell environment variable to be set.