Ichrak Mansour
Ichrak Mansour

Reputation: 1942

How to auto run Webpack-dev-server after each save?

I want to auto run and auto refresh webpack-dev-server when I used the package AutoSave OnChange of Atom and run my application.

My webpack-dev-server is :

devServer: {
        contentBase: './src/index.js',
        host: '0.0.0.0',
        compress: true,
        port: 3001, // port number
        historyApiFallback: true,
        quiet: true,
    }

I use the Reactify template, and the scriptsof my package.json is :

"scripts": {
    "start": "webpack-dev-server --mode development --inline --progress",
    "build": "webpack --mode production"
  },

Upvotes: 1

Views: 4181

Answers (4)

owillz
owillz

Reputation: 1

The marked answer didn't work for me (as of 2023). Most of the flags returned an unknown error.

What worked for me is:

{ "start" : "webpack-dev-server --mode development --progress"}

Upvotes: 0

Nitz
Nitz

Reputation: 15

WDS will handle restarting the server when you change a bundled file, but what about when you edit the webpack config? Restarting the development server each time you make a change tends to get boring after a while. The process can be automated as discussed in GitHub by using "nodemon" monitoring tool.

To get it to work, you have to install it first through npm install nodemon --save-dev. After that, you can make it watch webpack config and restart WDS on change. Here's the script if you want to give it a go:

package.json

"scripts": { "start": "nodemon --watch webpack.config.js --exec \"webpack-dev-server --mode development\"", "build": "webpack --mode production" }, It's possible WDS will support the functionality itself in the future. If you want to make it reload itself on change, you should implement this workaround for now.

Upvotes: 0

multy18
multy18

Reputation: 148

Add a watch flag to your start script.

"start": "webpack-dev-server --mode development --inline --progress --watch"

Upvotes: 3

Tom Finney
Tom Finney

Reputation: 2928

Try adding the --watch flag to your start script!

Upvotes: 2

Related Questions