A modern React Chrome extension template built with TypeScript, Vite, and Vitest. Pre-configured with Prettier, ESLint, and Tailwind CSS for clean, maintainable, and stylish code. This template includes two powerful scripts—build.cjs and publish.cjs—to streamline the development, building, and publishing process for Chrome extensions.
- React: Build dynamic UIs with component-based architecture.
- TypeScript: Write type-safe JavaScript with modern ECMAScript features.
- Vitest: Fast and lightweight unit testing framework for reliable code quality.
- Vite: Lightning-fast bundling and development server with HMR support.
- Tailwind CSS: Utility-first CSS framework for rapid and customizable styling.
- Prettier & ESLint: Enforces consistent code style and catches potential errors.
- Build Script: Automates manifest validation, version synchronization, Vite bundling, and ZIP packaging.
- Publish Script: Simplifies uploading your extension to the Chrome Web Store using OAuth 2.0.
- Node.js (v16 or higher recommended)
- npm (comes with Node.js)
- A Chrome Web Store Developer account (for publishing)
-
Clone the Repository
git clone https://github.com/ganemedelabs/react-chrome-extension-template.git cd react-chrome-extension-template -
Install Dependencies
npm install
-
Customize Your Extension
- Update
manifest.jsonwith your extension's details (e.g.,name,description,icons). - Modify
src/files to implement your extension's functionality.
- Update
-
Configure Environment (for Publishing)
- Create a
.envfile in the root directory (see Publish Script for details).
- Create a
The build.cjs script handles the production bundling and packaging of your Chrome extension.
- Validates
manifest.jsonfor required fields (e.g.,manifest_version,name,version). - Synchronizes versions between
package.jsonandmanifest.json. - Runs Vite to bundle your React code into the
dist/directory. - Creates a versioned ZIP file (e.g.,
extension-name-1-0-0.zip) for deployment if no warnings occur.
npm run build
# or
node build.cjs- Errors (e.g., missing required manifest fields) stop the build.
- Warnings (e.g., missing
descriptionoricons) allow the build but prevent ZIP generation. - Adds
manifest_version: 3if missing and usespackage.jsonname as a fallback.
The publish.cjs script uploads a pre-built ZIP file to the Chrome Web Store using OAuth 2.0.
- Verifies the existence of the ZIP file generated by
build.cjs. - Handles OAuth 2.0 authentication (fetches and stores a
REFRESH_TOKENif needed). - Uploads the ZIP to the Chrome Web Store using your
EXTENSION_ID.
- A ZIP file from a prior
build.cjsrun. - A
.envfile with:CLIENT_ID=your_client_id CLIENT_SECRET=your_client_secret EXTENSION_ID=your_extension_id
- See How to Obtain Credentials for setup instructions.
npm run publish
# or
node publish.cjs- The
EXTENSION_IDis available after publishing your extension manually at least once.
- Go to Google Cloud Console and create a project (e.g.,
chrome-webstore-item). - Set up the OAuth consent screen (select "External," add your email as a test user).
- Enable the Chrome Web Store API.
- Create an OAuth client ID (select "Desktop app," name it e.g.,
Chrome Webstore Item). - Save the generated
CLIENT_IDandCLIENT_SECRETto your.envfile.
Feel free to submit issues or pull requests to improve this template!
This project is licensed under the MIT License. See the LICENSE file for details.