π Create React App Manually (Without CRA or Vite)
Hey developers π,
In this post, Iβll show you how to create a React app manually from scratch without using create-react-app or Vite. This will help you understand the building blocks of React projects β what happens under the hood.
π Full code is available on my GitHub: manualreact
1. Create a folder and initialize the project
mkdir manualreact
cd manualreact
npm init -y
The -y flag accepts all defaults, so it quickly generates a package.json.
2. Install React and ReactDOM
npm install react react-dom
- react β Core library for writing components, managing state, and using hooks.
- react-dom β Used to render React components into the actual DOM (browser).
Example:
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App";
const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(<App />);
3. But waitβ¦ browsers donβt understand JSX directly β οΈ
Up to this point, we have written React code.
But browsers only understand plain JavaScript, HTML, and CSS.
So we need tools that bundle and transpile our code:
πΉ Webpack (Bundler)
- Takes all your files (
.js,.css,.jpg, etc.) - Combines them into a single optimized bundle (
bundle.js) - Browser can then load it efficiently.
πΉ Babel (Transpiler)
- Converts modern ES6+ and JSX code into older JavaScript that browsers understand.
Examples:
JSX β React.createElement
// ES6/JSX
const element = <h1>Hello React</h1>;
Babel output:
const element = React.createElement("h1", null, "Hello React");
Arrow function β ES5 function
// ES6
const sum = (a, b) => a + b;
Babel output:
var sum = function(a, b) {
return a + b;
};
4. File Structure and Configurations
Iβve set up all necessary files (index.html, webpack.config.js, babel.config.js, entry point, etc.) in my repo.
π You can check it out here: manualreact on GitHub
β Conclusion
By setting up React manually:
- You understand how bundlers and transpilers work.
- You gain full control over project configuration.
- Itβs a great way to learn the internals behind
create-react-appandVite.
π‘ Pro tip: Once youβre comfortable with this, you can explore advanced Webpack loaders, plugins, and optimizations.
Top comments (0)