Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

community creator

How to create a React app without using Create-React-App CLI

Josias Aurel

In this post, I am going to show you how to create a react app without Create-React-App CLI.

First of all, you need to create a folder to contain your project:

mkdir my-react-app

Then, you will have to enter that folder and initialize a new node project:

npm init -y #skip the questions

After creating the project, you will need to install parcel, react, and react-dom dependencies:

npm install parcel-bundler react react-dom

This code will install parcel (which is a simpler alternative to webpack) along with react and react-dom.

Now that you have the dependencies installed, create an HTML file. This file will serve as your template. Let’s call it index.html:

<!DOCTYPE html>
<html lang="en">
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=Edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <!-- HTML -->

  <!-- Custom Styles -->
  <link rel="stylesheet" href="style.css">

  <div id="root">
  <script src="main.js"></script>

Now we need to create our main.js file. Add the following code in the main.js file.

// import dependencies

import React from "react"
import ReactDOM from "react-dom"

// A simple react component
const Hello = () => {
	return (
		 <h1> Hello World </h1>

ReactDOM.render(<Hello />, document.getElementById("root")) // render element on div with ID of 'root'

Now we have a basic react component that shows Hello World to the DOM, but we need to compile it to actually see the result. You need to run:

parcel index.html #or whatever name you gave to your HTML file

parcel will take care of the rest, that is, compiling your JSX component to HTML and bundling it. It will then start up a local server that you can visit to view your app – it will automatically reload when any change is made. That’s it – now you can create a react app without the default CLI. You can run the following command to build your React app for production:

parcel build index.html

Note: you can write your React components in separate files just like you do with the create-react-app project.


community creator

View all Courses

Keep Exploring