Mode

Providing the mode configuration option tells webpack to use its built-in optimizations accordingly.

'none' | 'development' | 'production' = 'production'

Usage

Provide the mode option in the config:

export default {
  mode: "development",
};

or pass it as a CLI argument:

webpack --mode=development

The following string values are supported:

OptionDescription
developmentSets process.env.NODE_ENV on DefinePlugin to value development. Enables useful names for modules and chunks.
productionSets process.env.NODE_ENV on DefinePlugin to value production. Enables deterministic mangled names for modules and chunks, FlagDependencyUsagePlugin, FlagIncludedChunksPlugin, ModuleConcatenationPlugin, NoEmitOnErrorsPlugin and MinimizerPlugin.
noneOpts out of any default optimization options

If not set, webpack sets production as the default value for mode.

Defaults per mode

mode doesn't do anything by itself — it picks the defaults of other options, each of which you can still set explicitly. These are the options whose default depends on it:

Optiondevelopmentproductionnone
cache{ type: 'memory' }falsefalse
devtool'eval'falsefalse
output.pathinfotruefalsefalse
performance.hintsfalse'warning'false
optimization.chunkIds'named''deterministic''natural'
optimization.moduleIds'named''deterministic''natural'
optimization.nodeEnv'development''production'false
optimization.emitOnErrorstruefalsetrue
optimization.sideEffects'flag'true'flag'
optimization.usedExportsfalsetruefalse
optimization.innerGraphfalsetruefalse
optimization.mangleExportsfalsetruefalse
optimization.concatenateModulesfalsetruefalse
optimization.flagIncludedChunksfalsetruefalse
optimization.realContentHashfalsetruefalse
optimization.checkWasmTypesfalsetruefalse
optimization.minimizefalsetruefalse

optimization.splitChunks is also tuned by mode: minSize, enforceSizeThreshold, maxAsyncRequests and maxInitialRequests are stricter in production. See SplitChunksPlugin for their values.

Two rows come with a condition: performance.hints only applies to browser targets, and devtool stays false in development when the build outputs an ES module library. With experiments.css enabled, development additionally defaults CSS assets to source-map.

Mode: development

// webpack.development.config.js
export default {
  mode: "development",
};

Mode: production

// webpack.production.config.js
export default {
  mode: "production",
};

Mode: none

// webpack.custom.config.js
export default {
  mode: "none",
};

If you want to change the behavior according to the mode variable inside the webpack.config.js, you have to export a function instead of an object:

const config = {
  entry: "./app.js",
  // ...
};

export default (env, argv) => {
  if (argv.mode === "development") {
    config.devtool = "source-map";
  }

  if (argv.mode === "production") {
    // ...
  }

  return config;
};
Edit this page·
Next »
Output

6 Contributors

EugeneHlushkobyzykmrichmondFentalsnitin315chenxsan