Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How "npm start" works in create-react-apps

What is happening in the background after you execute the npm start command? Is it generating something like a web server so that your browser can communicate with?

like image 913
Thong Yi Xuen Avatar asked Apr 02 '18 10:04

Thong Yi Xuen


1 Answers

npm start in create-react-app is doing many things, and among those it uses webpack-dev-server to start a development server which you can communicate with.

If you are more interested in how it works you should try to run npm run eject.

This will allow you to see what Create-React-App does since it places the scripts run by npm start directly in your application directory. It further add the webpack config files used by those scripts to your directory. Finally it updates your package.json file, such that you can actually see what dependencies Create-React-App is using (Among those you will find webpack-dev-server)

If you then look into package.json and check out the "scripts" section you can start following what each command actually do. For instance the "start" command can be found here. This will call the start.js file in your scripts folder. This is the file where you will see the webpack-dev-server being started.

In general you can check out the two folders scripts and config to learn about the details.

like image 159
the_cheff Avatar answered Sep 24 '22 00:09

the_cheff