score:231
create-react-app and react-scripts
react-scripts
is a set of scripts from the create-react-app
starter pack. create-react-app helps you kick off projects without configuring, so you do not have to setup your project by yourself.
react-scripts start
sets up the development environment and starts a server, as well as hot module reloading. You can read here to see what everything it does for you.
with create-react-app you have following features out of the box.
- React, JSX, ES6, and Flow syntax support.
- Language extras beyond ES6 like the object spread operator.
- Autoprefixed CSS, so you don’t need -webkit- or other prefixes.
- A fast interactive unit test runner with built-in support for coverage reporting.
- A live development server that warns about common mistakes.
- A build script to bundle JS, CSS, and images for production, with hashes and sourcemaps.
- An offline-first service worker and a web app manifest, meeting all the Progressive Web App criteria.
- Hassle-free updates for the above tools with a single dependency.
npm scripts
npm start
is a shortcut for npm run start
.
npm run
is used to run scripts that you define in the scripts
object of your package.json
if there is no start
key in the scripts object, it will default to node server.js
Sometimes you want to do more than the react scripts gives you, in this case you can do react-scripts eject
. This will transform your project from a "managed" state into a not managed state, where you have full control over dependencies, build scripts and other configurations.
score:7
"start" is a name of a script, in npm you run scripts like this npm run scriptName
, npm start
is also a short for npm run start
As for "react-scripts" this is a script related specifically to create-react-app
score:15
succinctly - it runs this
node node_modules/react-scripts/bin/react-scripts.js start
score:110
As Sagiv b.g. pointed out, the npm start
command is a shortcut for npm run start
. I just wanted to add a real-life example to clarify it a bit more.
The setup below comes from the create-react-app
github repo. The package.json
defines a bunch of scripts which define the actual flow.
"scripts": {
"start": "npm-run-all -p watch-css start-js",
"build": "npm run build-css && react-scripts build",
"watch-css": "npm run build-css && node-sass-chokidar --include-path ./src --include-path ./node_modules src/ -o src/ --watch --recursive",
"build-css": "node-sass-chokidar --include-path ./src --include-path ./node_modules src/ -o src/",
"start-js": "react-scripts start"
},
For clarity, I added a diagram.
The blue boxes are references to scripts, all of which you could executed directly with an npm run <script-name>
command. But as you can see, actually there are only 2 practical flows:
npm run start
npm run build
The grey boxes are commands which can be executed from the command line.
So, for instance, if you run npm start
(or npm run start
) that actually translate to the npm-run-all -p watch-css start-js
command, which is executed from the commandline.
In my case, I have this special npm-run-all
command, which is a popular plugin that searches for scripts that start with "build:", and executes all of those. I actually don't have any that match that pattern. But it can also be used to run multiple commands in parallel, which it does here, using the -p <command1> <command2>
switch. So, here it executes 2 scripts, i.e. watch-css
and start-js
. (Those last mentioned scripts are watchers which monitor file changes, and will only finish when killed.)
The
watch-css
makes sure that the*.scss
files are translated to*.css
files, and looks for future updates.The
start-js
points to thereact-scripts start
which hosts the website in a development mode.
In conclusion, the npm start
command is configurable. If you want to know what it does, then you have to check the package.json
file. (and you may want to make a little diagram when things get complicated).
Source: stackoverflow.com
Related Query
- What exactly is the timeout value in React CSS Transition Group doing?
- What does bind(this) is exactly doing in this example of the React app?
- what are the command to send my local react app files to Github repository in VsCode?
- what is the terminal command in windows for creating a react ionic app with Cordova ? I tried searching but didn't get anything
- What is the difference between React Native and React?
- What is the difference between using constructor vs getInitialState in React / React Native?
- How to access a DOM element in React? What is the equilvalent of document.getElementById() in React
- What is the best way to access redux store outside a react component?
- What exactly is the 'react-scripts start' command?
- React functional stateless component, PureComponent, Component; what are the differences and when should we use what?
- What is the best way to redirect a page using React Router?
- What is the best way to trigger onchange event in react js
- What is the best way to deal with a fetch error in react redux?
- what is the preferred way to mutate a React state?
- What is the difference between NextJs and Create React App
- What is the quickest way to convert a React app to React Native?
- React with Redux? What about the 'context' issue?
- What is the TypeScript return type of a React stateless component?
- react custom hooks vs normal functions, what is the difference
- What is the default unit of style in React Native?
- What is the difference between hashHistory and browserHistory in react router?
- React - What is the best way to handle login and authentication?
- What is the difference between import * as react from 'react' vs import react from 'react'
- What is the correct way of adding a dependency to react in your package.json for a react component
- What is the core difference of redux & reflux in using react based application?
- What is the difference between using constructor vs state = {} to declare state in react component?
- What is workflow of the React
- What is the react-app-env.d.ts in a react typescript project for
- React js - What is the difference betwen HOC and decorator
- What is the React equivalent of an Angular directive that only works on attributes?
More Query from same tag
- Upload image to redux and show in React-Konva
- React Hook useState behavior
- How to send response from Nodemailer
- How to access elements rendered in another React component?
- How to write the type annotation of class method React.Component?
- Passing Multiple Attributes to a Component
- React working slow on input change
- use SWR with depending request data
- Where to make Ajax calls in React flux
- Using Nightmare web-scraping with React (create-react-app)
- React Redux hooks in Gatsby useDispatch "Invalid hook call"
- React/Redux Loading application state in component constructor
- How can you make the cards for ant.design smaller?
- Component that adds its own Provider
- how to make multiline chart with dashed line segment in each line in d3
- Adding functions to redux store within reducer is an anti pattern?
- How to change state in react typescript
- Fieldset like div container with headers/subheader
- React: onClick on table data (button) - get whole data related to row which are generated using map
- How can I render a fully bundled react app inside of an iframe?
- jQuery needed for Bootstrap in React project
- Reach-Router and React-Bootstrap Navbar
- What is the React equivalent of an Angular directive that only works on attributes?
- Using click events on button click
- Returning an array from a JSX function and destructuring it elsewhere
- React Hooks state update applies only once when called from callbacks in an array of components
- Why fetched data do not populate the state after i set them?
- Controlling an array according to its elements
- How to update react state with dropdown menu selection? I am using semantic UI for the dropdown
- How to show text over an image and flow that text upward if it overflows?