Webpack4.0 npm script uses-- mode development to set development mode and production mode

use webpack4.0 to package
npm script

"webpack --mode development --config webpack.config.dev.js  --progress --colors  "

tell me how to use the-- mode field in the configuration file code to make a judgment

Feb.28,2021

https://doc.webpack-china.org.

ides/environment-variables" rel=" nofollow noreferrer "> use environment variables

the official example is to export a function instead of an exported object in a configuration file, where you can directly access the

of mode.
module.exports = (env, argv) => ({
  // ... 
  optimization: {
    minimize: false,
    //  argv  mode 
    minimizer: argv.mode === 'production' ? [
      new UglifyJsPlugin({ /*  */ }), 
      // 
      // mode  production  webpack  JS  plugin
    ] : [],
  },
})...

there are mode fields in the webpack configuration.. Just write directly.

config = {
    mode: 'development'
}
Menu