๐ 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-app
andVite
.
๐ก Pro tip: Once youโre comfortable with this, you can explore advanced Webpack loaders, plugins, and optimizations.
Top comments (0)