2 thoughts on “DefinePlugin NODE_ENV not visible to babel-loader

  1. Ah, that was it, thanks. In webpack.config.js If I do

    process.env.NODE_ENV = '"production"'

    in addition to configuring DefinePlugin, it is available to babel-loader as well as the other processors.

  2. @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.

    // webpack.config.js
    process.env.NODE_ENV = 'production';
    module.exports = {
      entry: './index.js',
      // ...
      plugins: [
        new DefinePlugin({
          'process.env.NODE_ENV': '"production"',


    NODE_ENV=production webpack --config=webpack.config.js

    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.

Comments are closed.