Building a Chrome extension with a React app developed using TypeScript and bundled with Webpack offers a modern approach to browser extension development. In this blog, I will guide you through the process of creating a Chrome extension with the npx create-react-app template in TypeScript and bundling the app with Webpack. Additionally, we will utilize the latest version of the Chrome extension manifest, Manifest V3.
Prerequisites
Before we dive into the development process, ensure you have a basic understanding of React and its core concepts, as well as a fundamental of JavaScript and HTML.
Additionally, you'll need the following tools.
- Google Chrome
- Visual Studio Code
- Node.js and npm (Node Package Manager)
Step 1. Create a React App
To begin, we need to create a new TypeScript React project. Open your terminal or command prompt and run the following command. This will set up a new React project with all the necessary dependencies.
npx create-react-app react-chrome-ext --template typescript

Let's update the App.tsx file to be a basic React component that displays "Hello! This is an article on creating a Chrome Extension with React."
import './App.css';
function App() {
return (
<div className="App">
<div className="">
Hello! This is an article on creating a Chrome Extension with React.
</div>
</div>
);
}
export default App;
Next, update index.tsx to create a root element in the DOM and append our app to it.
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App";
const root = document.createElement("div");
root.className = "container";
document.body.appendChild(root);
const rootDiv = ReactDOM.createRoot(root);
rootDiv.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
Let's add some minimal CSS to App.css.
.App {
color: white;
text-align: center;
}
.container {
width: 25rem;
height: 25rem;
background-color: rgb(107, 0, 128);
}
Step 2. Incorporate Webpack
Next, let's install the required dependencies to bundle our React app. Execute the following commands in your terminal.
npm install --save-dev webpack webpack-cli copy-webpack-plugin css-loader ts-loader html-webpack-plugin ts-node
The command npm install --save-dev webpack webpack-cli copy-webpack-plugin css-loader ts-loader html-webpack-plugin ts-node does several things.
- webpack and webpack-cli: These are the core packages for bundling JavaScript files in your project. webpack-cli provides the command line interface for webpack.
- copy-webpack-plugin: This plugin allows you to copy files and directories during the build process. It's useful for tasks like copying static assets (images, fonts, etc.) into the build directory.
- CSS-loader: This webpack loader allows you to import CSS files into your JavaScript files. It enables webpack to understand and process CSS files.
- ts-loader: This loader allows webpack to compile TypeScript files (*.ts and *.tsx) into JavaScript.
- html-webpack-plugin: This plugin simplifies the process of creating HTML files to serve your webpack bundles. It generates an HTML file with references to your bundled JavaScript files.
- ts-node: This is a TypeScript execution and REPL for Node.js, allowing you to execute TypeScript code directly without prior compilation.
By installing these dependencies, you're setting up your project to use webpack for bundling, along with loaders and plugins necessary for handling TypeScript, CSS, and HTML files.







Join the conversation! Your thoughts help the community grow.