Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto reload react server on update

I'm new to React. I'm having some problems with react server. After starting the server by npm start if I work on the source code and make some changes, I have to stop the server and restart it to make that change available on the browser. Is there anyway to make it auto compile and refresh the browser on update ? (Like nodemon for node ?)

like image 388
Thidasa Pankaja Avatar asked Mar 01 '26 05:03

Thidasa Pankaja


1 Answers

I had a similar (or event the same) problem and I changed starting command in the package.json file by adding following flags: --watch --watch-poll to the webpack-dev-server:

{
    //...
    "scripts": {
        "start": "webpack-dev-server --env.ENVIRONMENT=development --content-base src/ --mode development --watch --watch-poll",
        // ...
    }
    // ...
}

Now, using npm start and then changing src files I can see changes in the browser.

Please here https://webpack.js.org/configuration/watch/ for more options.

like image 55
Tomasz Hławiczka Avatar answered Mar 02 '26 19:03

Tomasz Hławiczka



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!