🔄 How to get autoreload for webpack config changes too.
Francesco Di Donato
Posted on August 1, 2020
The webpack-dev-server package provides hot-reload for anything it bundles. But it does not consider the configuration file (usually webpack.config.js).
In this post I am going to show you how to autoreload depending on webpack config file changes by using Nodemon.
🤔 Problematic
Every change in webpack configuration requires a manual reboot of the webpack-dev-server (WDS).
📜 Example code
📦 Packages
💡 Solution
The activation of the webpack-dev-server is performed by nodemon. It is instructed to restart the process every time the webpack configuration file changes.
🤓 Implementing the Solution
Premise: webpack.config.js
is located in the root
Create a nodemon.json
file in the root. Two instructions are sufficient:
- watch for changes in the
webpack.config.js
. - execute the activation of the webpack-dev-server (in development mode).
{
"watch": ["webpack.config.js"],
"exec": "webpack-dev-server --mode development"
}
Lastly tweak the start script in the package.json
:
"scripts": {
"start": "nodemon",
},
😎 Checking the Outcome
Try the run npm start
and keep open the console. Just alter something in webpack.config.js
- it will reboot by itself.
❣ More Details surviveJS
Posted on August 1, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.