Building React with Bundlers

Bundlers like Webpack, Vite, Parcel, and others are essential tools for modern React development. They offer several key features that streamline the development process:

Key Features of Bundlers:

We can use any bundler for a React app. But in this course, Akshay used Parcel, a zero-configuration bundler.

We will be setting up our own npm create-react-app from scratch to learn in-depth. Once we learn this and know all the fundamentals, then we can use any bundler to set up our project.

To start with:

npm init

OR

npm init -y # with -y it will say yes to all questions

With this, we are initializing npm for our project, which will give us a package.json file with the project information.

What is npm?

Read more on NPM

Why do we need npm?

After doing npm init and setting up our package.json, we need to set up Parcel.

Install Parcel as a Dev Dependency

npm i -D parcel

or

npm i --save-dev parcel

Difference Between dependency and dev dependency

dependencies:

devDependencies:

Now, when we install any library we see its name with version for ex- ^2.8.2, ~2.8.2, >=2.8.2 and many more.

Let's understand what these terms means.

npm Versioning Specifiers

1. Tilde (~)

2. Caret (^)

3. Greater Than or Equal (>=)

And there are other as well but this much is enough.

Now when we do npm init we get package.json along with this we also get package-lock.json.

package.json vs package-lock.json

package.json

package-lock.json

Question by Akshay: Should We Add node_modules to Our Git?

 Note:- Anything that can be generated on server will be put inside .gitignore

After installing parcel we installed react and react-dom as dependency. Because we need these library to go on production also.

npm i react react-dom

Now we are ready to start our development server. To start just write the below cmd:

 npx parcel index.html

What Does npx Do?

Question by Akshay: Why Are React Apps Fast? Is It Only React?

Example by Akshay to Understand This:

Answer to tell to interviewer by Akshay

There is a browserslist package that help to make our website support to older browser too.

  "browserslist": [
    "last 2 versions"
  ]

With this configuration we are supporting Last 2 versions of each major browser.

This was it. In this session we successfully create our own create-react-app from the scratch.