Building a react boilerplate from scratch without using create-react-app
Last Updated :
25 Jul, 2024
In this article, we are going to build a basic boilerplate for a React project from scratch without using the create-react-app or any other predefined boilerplate. This is a great experience for any react developer to look into what is happening behind the scenes.
The file structure for our project will be looking like the following. You will understand how this project structure is created while going through the below steps.

Below is the step-by-step procedure that we will be going to follow.
Step 1: Create an empty new directory and name it according to your choice. Open up the terminal inside that directory and initialize the package.json file by writing the following command:
npm init -y
Here, -y is a flag that creates a new package.json file with default configurations. You can change these default configurations anytime in the package.json file. Package.json contains all dependencies and devDependencies.

A package.json file is created with default configurations
Also, initialize git in your project if you want. Run the following command on the terminal:
git init
Add a .gitignore file in the root directory and add node_modules in it because node_modules contains all dependency folders and files so the folder becomes too big. Hence, it is not recommended to add it in git.
Step 2: Â Make two directories named “public” and “src” inside the root directory ( “/”). “public” folder contains all static assets like images, svgs, etc. and an index.html file where the react will render our app while “src” folder contains the whole source code.
Inside the public folder, make a file named index.html.
Filename: index.html
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content=
"width=device-width, initial-scale=1.0">
<title>Basic Boilerplate of React</title>
</head>
<body>
<!-- This is the div where React
will render our app -->
<div id="root"></div>
<noscript>
Please enable javascript to view this site.
</noscript>
<script src="../dist/bundle.js"></script>
</body>
</html>
Step 3: We will write our code in modern ES6 syntax but many browsers do not support it. So, we install Babel that performs the following things:
- Converts new ES6 syntaxes into browser compatible syntaxes so that old versions of browsers can also support our code.
- Converts JSX (JavaScript XML) into vanilla javascript.
To install Babel, run the following command on the terminal:
npm install --save-dev @babel/core @babel/cli @babel/preset-env @babel/preset-react
Here,Â
- –save-dev means save all above installed modules in devDependencies in package.json file,
- @babel/core is a module that contains the main functionality of Babel,
- @babel/cli is a module that allows us to use babel from the terminal,
- @babel/preset-env is preset that handles the transformation of ES6 syntax into common javascript,
- @babel/preset-react is preset which deals with JSX and converts it into vanilla javascript.
Now, create a file “.babelrc” in the root directory. This file will tell babel transpiler what presets and plugins to use to transpile the code. Add the following JSON code:
{
"presets": ["@babel/preset-env","@babel/preset-react"]
}
Step 4: Â Install React and React DOM by running the following command on the terminal:
npm i react react-dom

present inside package.json file.
Step 5: Â Now, create three files inside “src” directory named as ‘App.js’, ‘index.js’, ‘App.css’. These files contain the actual code.
App.js: A component of React.
JavaScript
import React from "react";
import "./App.css";
const App = () => {
return (
<div>
<h1 className="heading">GeeksForGeeks</h1>
<h4 className="sub-heading">
A computer science portal for geeks
</h4>
</div>
);
};
export default App;
App.css: Provides stylings for App component.
CSS
/* stylings for App component */
.heading,.sub-heading{
color:green;
text-align: center;
}
index.js: Renders the components on the browser.
JavaScript
import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
ReactDOM.render(<App/>,document.getElementById("root"));
Note: You can make as many components as you want in your react project inside the src folder.
Step 6: Â Install the webpack. The webpack is a static module bundler. It works well with babel. It creates a local development server for our project. The webpack collects all the modules (either custom that we created or installed through NPM ) and bundles them up together in a single file or more files (static assets). To install webpack, run the following command on the terminal:
npm install --save-dev webpack webpack-cli webpack-dev-server
Here,
- –save-dev is the same as discussed above,
- webpack is a modular bundler,
- webpack-cli allows us to use webpack from the terminal by running a set of commands,
- webpack-dev-server provides a development server with live reloading i.e. you do not need to refresh the page manually.
The webpack takes code from the src directory and perform required operations like bundling of code, conversion of ES6 syntax and JSX syntax into common javascript etc. and host the public directory so that we can view our app in the browser.
Step 7: Â Webpack can understand JavaScript and JSON files only. So, to use webpack functionality in other files like .css, babel files, etc., we have to install some loaders in the project by writing the following command on the terminal:
npm i --save-dev style-loader css-loader babel-loader
Here,
- css-loader collects CSS from all the CSS files in the app and bundle it into one file,
- style-loader puts all stylings inside <style> tag in index.html file present in the public folder,
- babel-loader is a package that allows the transpiling of javascript files using babel and webpack.
Step 8: Â Create a webpack.config.js file in the root directory that helps us to define what exactly the webpack should do with our source code. We will specify the entry point from where the webpack should start bundling, the output point that is where it should output the bundles and assets, plugins, etc.
webpack.config.js
JavaScript
const path = require("path");
module.exports = {
// Entry point that indicates where
// should the webpack starts bundling
entry: "./src/index.js",
mode: "development",
module: {
rules: [
{
test: /\.(js|jsx)$/, // checks for .js or .jsx files
exclude: /(node_modules)/,
loader: "babel-loader",
options: { presets: ["@babel/env"] },
},
{
test: /\.css$/, //checks for .css files
use: ["style-loader", "css-loader"],
},
],
},
// Options for resolving module requests
// extensions that are used
resolve: { extensions: ["*", ".js", ".jsx"] },
// Output point is where webpack should
// output the bundles and assets
output: {
path: path.resolve(__dirname, "dist/"),
publicPath: "/dist/",
filename: "bundle.js",
},
};
Step 9: Â Now, add some scripts in the package.json file to run and build the project.
"scripts": {
"start":"npx webpack-dev-server --mode development --open --hot",
"build":"npx webpack --mode production",
}
Here,Â
- –open flag tells the webpack-dev-server to open the browser instantly after the server had been started.
- –hot flag enables webpack’s Hot Module Replacement feature. It only updates what’s changed in the code, so does not update the whole code, again and again, that’s why it saves precious development time.
Step to run the application: Run the command following on the terminal to run the project in development mode.
npm start
Output:
Run command “npm run build” to run the project in production mode.Â
Note:Â When we are running our webpack server, there isn’t a dist folder. This is because what webpack server does is holds this dist folder in the memory and serves it, and deletes it when we stop the server. If you actually want to build the react app so that we can see that dist folder, run the command “npm run build”. Now, you can see the dist folder in the root directory.

That’s all! We are equipped with our own react boilerplate and ready to make some amazing and cool projects.
Similar Reads
What are the advantages of using create-react-app CLI ?
Introduction: To get started with any framework you need to understand what all files you need to install. With React you don't need to worry about this. React will install all the files required for you to get started with a single command. It will have all the necessary packages installed and you
3 min read
How To Test React App With Jest and React Testing Library?
Jest is a JavaScript testing framework maintained by Facebook, designed with a focus on simplicity and support for large JavaScript applications, especially React. It offers built-in utilities like test runners, mocking, snapshot testing, and code coverage reporting. React Testing Library (RTL) is a
3 min read
How re-render a component without using setState() method in ReactJS ?
In React, to re-render a class-based component with an updated state we generally use the setState() method. But instead, we can use other methods to re-render a component without using setState(). Prerequisites: NPM & Node.jsReact JSReactJS propsReactJS forceUpdate() methodApproaches to re-rend
3 min read
Create a Community Marketplace App using React
In this article, we will explore the process of developing a Community Marketplace application using React, that offers a seamless and user-friendly experience for users. The Community Marketplace App is a platform where users can buy and sell goods. It provides a convenient way for community member
8 min read
Build a Portfolio Website Using React and Bootstrap
Building a portfolio website using React and Bootstrap is an excellent project for showcasing your skills and creating a professional online presence. In this article, we will guide you through the process of building a responsive and visually appealing portfolio website using React for the front en
12 min read
Create a Real-Time Weather Forecast App with React
Real-time weather forecast app with React involves integrating with a weather API to fetch weather data and display it in the UI. Individuals can use the app to check the current weather conditions, temperature, humidity, and other relevant weather data for their location or any city they are intere
5 min read
Create a Food Reciepe App using React-Native
In this React-Native article, we will be developing an interactive Food Recipe Application. In this application, the users can be able to search for any food recipe in the search box. Then, according to the search query, the results will be fetched through an API and will be displayed in the applica
5 min read
How to create a food recipe app using ReactJS ?
We are going to make a food recipe app using React.js. Pre-requisite:React hooksReact componentsJavaScript ES6APIÂ CSSApproach: Here in this app we should have a component where we are going to show our food recipes. And we need to fetch all the required food recipes using a food recipe API. We will
4 min read
Create A Real Estate Website Using React and Tailwind CSS
A Real Estate Website built with React JS and Tailwind CSS is a modern and responsive web application that is designed to showcase real estate listings. It typically includes features such as OnSale property, a Features section, and a Contact Us section. The website is created using React JS, which
9 min read
How to import from React-Select CDN with React and Babel ?
In ReactJS, import from React-Select CDN is not done in a simple way as we do with the npm packages. To use them we need to use directly them in the HTML file. It does not work with the project set-up by creating a react app. Prerequisites:React JSHTML, CSS, JavaScriptSteps to Import React-Select CD
2 min read