Overview
The React Chrome Extension Boilerplate is a useful tool for building Chrome extensions using React and TypeScript. It provides a simple Webpack build process for bundling the files. With this boilerplate, developers can easily create Chrome extensions using the popular React library.
Features
- React integration for building Chrome extensions
- TypeScript support for type safety and improved development experience
- Webpack build process for efficient bundling of files
- Fast development mode for quick iteration
Installation
- Run
npm ito install the necessary dependencies. - Run
npm startto start the fast development mode Webpack build process that bundles files into thedistfolder. - Run
npm i --save-dev <package_name>to install new packages (if needed).
Loading The Chrome Extension
- Open Chrome and navigate to
chrome://extensions/. - Toggle on Developer mode in the top right corner.
- Click “Load unpacked”.
- Select the entire
distfolder.
Production Build
- Run
npm run buildto generate a minimized production build in thedistfolder. - ZIP the entire
distfolder (e.g.dist.zip). - Publish the ZIP file on the Chrome Web Store Developer Dashboard.
Initial Steps
- Run
git initto start a new git repo for tracking your changes. Do an initial base commit with all the default files. - Update
package.json, important fields include author, version, name, and description. - Update
manifest.json, important fields include version, name, and description. - Update
webpack.common.js, the title in thegetHtmlPluginsfunction should be your extension name.
Default Boilerplate Notes
- Folders get flattened, static references to images from HTML do not need to be relative (i.e.
icon.pnginstead of../static/icon.png). - Importing local ts/tsx/css files should be relative, since Webpack will build a dependency graph using these paths.
- Update the manifest file as per usual for chrome-related permissions. References to files in here should also be flattened and not be relative.
Summary
The React Chrome Extension Boilerplate is a valuable resource for developers looking to build Chrome extensions using React and TypeScript. It offers a convenient Webpack build process and provides guidelines for installation and usage. With its support for React and TypeScript, developers can benefit from the advantages of these technologies while building Chrome extensions.