How to tell ReactJS to build project in Production mode ? - GeeksforGeeks (2024)

Last Updated : 31 Oct, 2023

Summarize

Comments

Improve

React production build creates minified bundles, lighter-weight source maps, and optimized assets. This improves the load time. React recommends using production mode while deploying the React app. We now know that production build helps in optimizing performance.

React.js provides a powerful and efficient build process that optimizes your application for production deployment. By default, React.js builds your project in development mode, which includes features like detailed error messages and debugging tools. However, when you’re ready to deploy your application, it’s important to build it in production mode to benefit from optimized performance and reduced bundle size.

Let’s see now a step-by-step guide to create a react app in production mode.

Steps to Create React Application

Step 1: Open the terminal and run the following command to create a project folder

npx create-react-app myapp

Step 2: Move into the project folder:

cd myapp

Project Structure

The initial project structure will look like the following.

How to tell ReactJS to build project in Production mode ? - GeeksforGeeks (1)

project structure

Step 3: Now edit the App.js file in the project and replace pre-existing code with the following code.

Javascript

// Filename -App.js

import logo from "./logo.svg";

import "./App.css";

function App() {

return (

<div className="App">

<header className="App-header">

<img

src={logo}

className="App-logo"

alt="logo"

/>

<p>This is my React App.</p>

</header>

</div>

);

}

export default App;

CSS

/* Filename - App.js */

.App {

text-align: center;

}

.App-logo {

height: 40vmin;

pointer-events: none;

}

@media (prefers-reduced-motion: no-preference) {

.App-logo {

animation: App-logo-spin infinite 20s linear;

}

}

.App-header {

background-color: #282c34;

min-height: 100vh;

display: flex;

flex-direction: column;

align-items: center;

justify-content: center;

font-size: calc(10px + 2vmin);

color: white;

}

@keyframes App-logo-spin {

from {

transform: rotate(0deg);

}

to {

transform: rotate(360deg);

}

}

Step to run the application: Go to the root of the project folder and run one of the following commands:

npm start

Output: The app will run on port 3000 and the output screen will look like this:

How to tell ReactJS to build project in Production mode ? - GeeksforGeeks (2)

Output Screen

Step 4: Now create the production build of the app. React App makes it quite simple to build in production. If your project is build with create-react-app, go to the root directory of the project and run:

npm run build

How to tell ReactJS to build project in Production mode ? - GeeksforGeeks (3)

How to tell ReactJS to build project in Production mode ? - GeeksforGeeks (4)

creating production build

This will create a build directory with production build of the app. Your JavaScript and CSS files will be inside the build/static directory. A number of .js files are generated and placed inside the build/static/js directory. These are called chunks.

How to tell ReactJS to build project in Production mode ? - GeeksforGeeks (5)

JS chunks created after production build

Step 5: Running the app in production mode. We will serve the build version with a static server: In production mode the react app will run on port 5000.

serve -s build

How to tell ReactJS to build project in Production mode ? - GeeksforGeeks (6)

App running in production mode

Now let’ see how to know whether the build process was setup correctly

1. We will be using React Developer Tools for Chrome . When this extension is installed and running and we visit a site with react in production mode, the react icon will have dark background.

How to tell ReactJS to build project in Production mode ? - GeeksforGeeks (7)

Production mode

2. If you visit a site with React in development mode, the icon will have a red background:

How to tell ReactJS to build project in Production mode ? - GeeksforGeeks (8)

development mode



Please Login to comment...

How to tell ReactJS to build project in Production mode ? - GeeksforGeeks (2024)
Top Articles
Antero Resources - AR - Stock Price Today
Antero Resources Corp Stock Price and Quote
It’s Time to Answer Your Questions About Super Bowl LVII (Published 2023)
Login Page
Faridpur Govt. Girls' High School, Faridpur Test Examination—2023; English : Paper II
Affidea ExpressCare - Affidea Ireland
Ross Dress For Less Hiring Near Me
Flixtor The Meg
Robinhood Turbotax Discount 2023
Google Jobs Denver
P2P4U Net Soccer
Bluegabe Girlfriend
Calamity Hallowed Ore
Violent Night Showtimes Near Amc Fashion Valley 18
Best Private Elementary Schools In Virginia
Comenity Credit Card Guide 2024: Things To Know And Alternatives
Milk And Mocha GIFs | GIFDB.com
Santa Clara Valley Medical Center Medical Records
Dusk
Aktuelle Fahrzeuge von Autohaus Schlögl GmbH & Co. KG in Traunreut
Bernie Platt, former Cherry Hill mayor and funeral home magnate, has died at 90
2024 Non-Homestead Millage - Clarkston Community Schools
Busted Newspaper S Randolph County Dirt The Press As Pawns
Espn Horse Racing Results
Rondom Ajax: ME grijpt in tijdens protest Ajax-fans bij hoofdbureau politie
Ms Rabbit 305
What Is Vioc On Credit Card Statement
Daytonaskipthegames
Soulstone Survivors Igg
Surplus property Definition: 397 Samples | Law Insider
Bidevv Evansville In Online Liquid
Klsports Complex Belmont Photos
Catchvideo Chrome Extension
Ascensionpress Com Login
Publix Christmas Dinner 2022
Ultra Clear Epoxy Instructions
Where Do They Sell Menudo Near Me
Edict Of Force Poe
AI-Powered Free Online Flashcards for Studying | Kahoot!
Caderno 2 Aulas Medicina - Matemática
Collier Urgent Care Park Shore
More News, Rumors and Opinions Tuesday PM 7-9-2024 — Dinar Recaps
Seminary.churchofjesuschrist.org
Mbfs Com Login
Denise Monello Obituary
My Eschedule Greatpeople Me
Learn4Good Job Posting
Tìm x , y , z :a, \(\frac{x+z+1}{x}=\frac{z+x+2}{y}=\frac{x+y-3}{z}=\)\(\frac{1}{x+y+z}\)b, 10x = 6y và \(2x^2\)\(-\) \(...
Roller Znen ZN50QT-E
Mike De Beer Twitter
Www Extramovies Com
Haunted Mansion Showtimes Near The Grand 14 - Ambassador
Latest Posts
Article information

Author: Francesca Jacobs Ret

Last Updated:

Views: 6301

Rating: 4.8 / 5 (48 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Francesca Jacobs Ret

Birthday: 1996-12-09

Address: Apt. 141 1406 Mitch Summit, New Teganshire, UT 82655-0699

Phone: +2296092334654

Job: Technology Architect

Hobby: Snowboarding, Scouting, Foreign language learning, Dowsing, Baton twirling, Sculpting, Cabaret

Introduction: My name is Francesca Jacobs Ret, I am a innocent, super, beautiful, charming, lucky, gentle, clever person who loves writing and wants to share my knowledge and understanding with you.