Providing themode configuration option tells webpack to use its built-in optimizations accordingly.
string = 'production': 'none' | 'development' | 'production'
Provide themode option in the config:
module.exports={ mode:'development',};or pass it as aCLI argument:
webpack --mode=developmentThe following string values are supported:
| Option | Description |
|---|---|
development | Setsprocess.env.NODE_ENV onDefinePlugin to valuedevelopment. Enables useful names for modules and chunks. |
production | Setsprocess.env.NODE_ENV onDefinePlugin to valueproduction. Enables deterministic mangled names for modules and chunks,FlagDependencyUsagePlugin,FlagIncludedChunksPlugin,ModuleConcatenationPlugin,NoEmitOnErrorsPlugin andTerserPlugin. |
none | Opts out of any default optimization options |
If not set, webpack setsproduction as the default value formode.
Ifmode is not provided via configuration or CLI, CLI will use any validNODE_ENV value formode.
// webpack.development.config.jsmodule.exports={ mode:'development',};// webpack.production.config.jsmodule.exports={ mode:'production',};// webpack.custom.config.jsmodule.exports={ mode:'none',};If you want to change the behavior according to themode variable inside thewebpack.config.js, you have to export a function instead of an object:
var config={ entry:'./app.js',//...};module.exports=(env, argv)=>{if(argv.mode==='development'){ config.devtool='source-map';}if(argv.mode==='production'){//...}return config;};