Webpack-dev-server: Restart after config change

Created on 31 Mar 2016  路  5Comments  路  Source: webpack/webpack-dev-server

This is a minor feature request: In addition to regular source files, also watch for changes on the webpack.config.js file. When it changes, restart the entire process (or whatever subprocess/system necessary) to run with the updated config.

Helps avoid the issue of config changes not applying to the running server, which sometimes takes minutes to hours to realize.

If this sounds like a good idea, I may be able to help implement it (haven't yet looked at the source of this repo).

4 (nice to have) approved

Most helpful comment

I found a way to do this with the ever-useful nodemon
nodemon restarts webpack-dev-server any time I change my webpack.config.js file.


I frequently forget to restart my server after config changes and I've wasted lots of time "debugging" things that work because of that. I think anything that can lower the cognitive overhead in our workflows is generally worthwhile. The fewer environmental gotchas I need to worry about, the more of my limited brainpower I can direct towards the important stuff--writing cool apps.

However I can see an argument for _not adding_ a restart feature to webpack (keeping it light and focused on what it does well). If my 'nodemon' hack is sufficient, perhaps it could become an example in the documentation.


I've set up the command in my packages.json as the start script .
  I now run $ npm start
  instead of $ webpack-dev-server

"scripts": {
  "start": "nodemon --watch webpack.config.js ./node_modules/.bin/webpack-dev-server",

  "test": "echo \"Error: no test specified. Write some tests, you slacker\" && exit 1"
},
"dependencies": 
  ...

note: nodemon's --watch flag doesn't like paths to be prefixed with ./

All 5 comments

Or allow, add list of files to watch for changes that restart the server if changed.

I found a way to do this with the ever-useful nodemon
nodemon restarts webpack-dev-server any time I change my webpack.config.js file.


I frequently forget to restart my server after config changes and I've wasted lots of time "debugging" things that work because of that. I think anything that can lower the cognitive overhead in our workflows is generally worthwhile. The fewer environmental gotchas I need to worry about, the more of my limited brainpower I can direct towards the important stuff--writing cool apps.

However I can see an argument for _not adding_ a restart feature to webpack (keeping it light and focused on what it does well). If my 'nodemon' hack is sufficient, perhaps it could become an example in the documentation.


I've set up the command in my packages.json as the start script .
  I now run $ npm start
  instead of $ webpack-dev-server

"scripts": {
  "start": "nodemon --watch webpack.config.js ./node_modules/.bin/webpack-dev-server",

  "test": "echo \"Error: no test specified. Write some tests, you slacker\" && exit 1"
},
"dependencies": 
  ...

note: nodemon's --watch flag doesn't like paths to be prefixed with ./

I've been thinking about this for a bit, and I think this is actually something that should be fixed in webpack. webpack already has watchpack as a dependency (a package to watch files), and has the power to reload the config. It wouldn't make sense to do this in the dev-server, since it doesn't know anything about the config itself.

@diskodan For some reason, nodemon --watch config/webpack.config.js --exec webpack-dev-server --config config/webpack.config.js doesn't work. More details: https://stackoverflow.com/questions/51611788/nodemon-failed-to-parse-config-webpack-config-js

EDIT: I figured it out

"start:dev": "nodemon --watch config --exec 'webpack-dev-server --config ./config/webpack.config.js'"

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tulika21-zz picture tulika21-zz  路  3Comments

Jack-Works picture Jack-Works  路  3Comments

antoinerousseau picture antoinerousseau  路  3Comments

eyakcn picture eyakcn  路  3Comments

piotrszaredko picture piotrszaredko  路  3Comments