Webpack-dev-server: How to kill current process before starting new one

Created on 7 Jul 2016  路  4Comments  路  Source: webpack/webpack-dev-server

If I enter commmand webpack-dev-server the webpack server will obviously start. But If I type that commnad again, I got error, because an instance the server is running and it's taking the locahost port.

Is there way to config webpack dev server so that it kill whatever instance of it before it starts?

Most helpful comment

Running killall node before restarting usually does the trick for me.

All 4 comments

Running killall node before restarting usually does the trick for me.

like this?

scripts : {
    "dev" : "killall node && webpack-dev-server"
}

not working. error No matching processes belonging to you were found

When you're running killall node and there's nothing to kill, that's what it will return. I wouldn't recommend adding it to an npm script, just run it as needed, or have a script to run it only if there are node processes running that need to be killed.

If you search on "find and kill process in bash" on Google you'll find a lot of answers on how to do this. This StackOverflow question for example. From a quick test, pkill -f webpack-dev-server; webpack-dev-server works. Note the use of ; instead of &&, because pkill will return a non-zero exit-code if it can't find any processes.

Edit: if you want to be sure that you only kill the webpack-dev-server process of the current project, use pkill -f project_folder/node_modules/.bin/webpack-dev-server

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MJ111 picture MJ111  路  3Comments

daryn-k picture daryn-k  路  3Comments

adiachenko picture adiachenko  路  3Comments

nikirossi picture nikirossi  路  3Comments

Ky6uk picture Ky6uk  路  3Comments