Build modes via scripts in Webpack
You can set the build mode not in the configuration file, but through the scripts setting of the package.json file. Now in this file we have the build command, which builds the project in the mode specified in the configuration file:
"scripts": {
"build": "webpack"
}
Let's add a command that builds the project in development mode:
"dev": "webpack --mode development"
Let's also add a command that builds the project in production mode:
"prod": "webpack --mode production"
As a result, our package.json file will look like this:
"scripts": {
"build": "webpack",
"dev": "webpack --mode development",
"prod": "webpack --mode production",
}
Now in the terminal we can call the build in different modes with different commands. For the build in development mode we will write the following:
npm run dev
And for assembly in production mode - the following:
npm run prod
Update your package.json with the appropriate settings.
Build your project in development mode.
Build your project in production mode.