Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using create-react-app with "npm run dev"

I am developing a React JS app on a remote server which uses Apache.

In the past I have built a React JS app manually with webpack/babel etc. and then used "npm run dev" to run the app.

With this method I could see any errors on the fly in the terminal and test in the browser automatically through the web browser.

I am now creating a new site with create-react-app which takes care of a lot of the tedious setup for you. One thing I cannot figure out is how to use something similar to "npm run dev". My two options seem to be:

  • npm run build - This takes a while and I have to rerun it every time I change my code. It does put the updated code in the /build directory which I can link to from my Apache server and see in my browser.
  • npm start - I can see any errors right away in the terminal, but I cannot see it in my browser because it runs on localhost and does not get compiled to the build directory.

What can I do so that I get the best of both worlds? Having quick rebuilds / error reporting and being able to see remotely through my Apache server?

Or would it be better just to go back to my old manual way of doing things?

like image 297
kojow7 Avatar asked Dec 21 '25 00:12

kojow7


1 Answers

This issue has been resolved over the last five years (when this question was posted). It seems to me that npm start does the same job as npm run dev at least with the latest version of npm and node that i am running. ([email protected] and [email protected]).

When I hit save in my editor (VScode) the terminal (on windows [i haven't tested on Linux]) gets updated right away and so does my browser - errors and all.

Due to the lack of documentation on the npm run dev command, one could only assume that it has been deprecated.

Another alternative to the above mentioned commands, would be to use Yarn which also does a great job of compiling your code, and in my own personal experience has done a better job at tougher projects, than npm.

like image 196
stonelar Avatar answered Dec 22 '25 17:12

stonelar