Auto reload react server on update

12,462

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.

Share:
12,462
Thidasa Pankaja
Author by

Thidasa Pankaja

Passionate Software Engineer at Twire working towards achieving professional goals, with an active drive to learn new technologies. Skilled in JavaScript, React, Go, PostgreSQL etc. Strong engineering professional with a Bachelor of Science (Hons) focused in Information Technology from University of Moratuwa.

Updated on June 29, 2022

Comments

  • Thidasa Pankaja
    Thidasa Pankaja almost 2 years

    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 ?)

    • Jacob
      Jacob over 6 years
      I normally use nodemon with babel-node. Looks like there may be other solutions out there. Haven't tried this, but: github.com/kmagiera/babel-watch
    • Thidasa Pankaja
      Thidasa Pankaja over 6 years
      yea @Jacob , even I'm using nodemon for Node server. But is it possible to use nodemon for react too ? And I tried installing babel-watch. But it gives me some errors. I'll check that out. Thanks
    • Luis Acero
      Luis Acero about 3 years
      You can see this answer, it can help you stackoverflow.com/a/65171489/13801206
  • Yacine Mahdid
    Yacine Mahdid about 4 years
    Worked by adding --watch --watch-poll
  • Paul
    Paul about 2 years
    I get the following error after npm start: [webpack-cli] Error: Unknown option '--env.ENVIRONMENT=development'