ReactJS - Installation
ReactJS - Installation
ReactJS - Installation
This chapter explains the installation of React library and its related tools in your
machine. Before moving to the installation, let us verify the prerequisite first.
React provides CLI tools for the developer to fast forward the creation,
development and deployment of the React based web application. React CLI tools
depends on the Node.js and must be installed in your system. Hopefully, you have
installed Node.js on your machine. We can check it using the below command −
node --version
You could see the version of Nodejs you might have installed. It is shown as below
for me,
v14.2.0
Toolchain
To develop lightweight features such as form validation, model dialog, etc., React
library can be directly included into the web application through content delivery
network (CDN). It is similar to using jQuery library in a web application. For
moderate to big application, it is advised to write the application as multiple files
and then use bundler such as webpack, parcel, rollup, etc., to compile and bundle
the application before deploying the code.
React toolchain helps to create, build, run and deploy the React application. React
toolchain basically provides a starter project template with all necessary code to
bootstrap the application.
Let us learn the basics of the above mentioned tools and how to install those in
this chapter.
Let us create a simple static site and serve the application using serve app.
cd /go/to/your/workspace
Create a new folder, static_site and change directory to newly created folder.
mkdir static_site
cd static_site
Next, create a simple webpage inside the folder using your favorite html editor.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Static website</title>
</head>
<body>
<div><h1>Hello!</h1></div>
</body>
</html>
serve .
We can also serve single file, index.html instead of the whole folder.
serve ./index.html
Next, open the browser and enter http://localhost:5000 in the address bar and
press enter. serve application will serve our webpage as shown below.
The serve will serve the application using default port, 5000. If it is not available, it
will pick up a random port and specify it.
│ Serving! │
│ │
│ - Local: http://localhost:57311 │
│ - On Your Network: http://192.168.56.1:57311 │
│ │
│ This port was picked because 5000 is in use. │
│ │
│ Copied local address to clipboard!
Babel compiler
Babel is a JavaScript compiler which compiles many variant (es2015, es6, etc.,) of
JavaScript into standard JavaScript code supported by all browsers. React uses JSX,
an extension of JavaScript to design the user interface code. Babel is used to
compile the JSX code into JavaScript code.
To install Babel and it’s React companion, run the below command −
Print Page