Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork632
Chrome Extension Boilerplate with React + Vite + Typescript
License
Jonghakseo/chrome-extension-boilerplate-react-vite
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Note
This project is listed in theAwesome Vite
Tip
Share storage state between all pages
2024-07-20.12.36.15.mov
- Intro
- Features
- Structure
- Installation
- Install dependency
- Environment variables
- Troubleshooting
- Community
- Debugging
- Reference
- Star History
- Contributors
This boilerplate helps you create Chrome/Firefox extensions using React and Typescript. It improvesthe build speed and development experience by using Vite and Turborepo.
- React
- TypeScript
- Tailwindcss
- Vite withRollup
- Turborepo
- Prettier
- ESLint
- Chrome Extensions Manifest Version 3
- Custom i18n package
- Custom HMR (Hot Module Rebuild) plugin
- End-to-end testing with WebdriverIO
- Clone this repository.(
git clone https://github.com/Jonghakseo/chrome-extension-boilerplate-react-vite) - Ensure your node version is >= than in
.nvmrcfile, recommend to usenvm - Edit
/packages/i18n/locales/{your locale(s)}/messages.json - In the objects
extensionDescriptionandextensionName, change themessagefields (leavedescriptionalone) - Install pnpm globally:
npm install -g pnpm - Run
pnpm install - Check if you have that configuration in your IDE/Editor:
- VS Code:
- InstalledESLint extension
- InstalledPrettier extension
- Enabled
Typescript Workbench versionin settings:- CTRL + SHIFT + P -> Search:
Typescript: Select Typescript version...->Use Workbench version - Read more
- CTRL + SHIFT + P -> Search:
- Optional, for imports to work correctly in WSL, you might need to install theRemote - WSL extension and connect to WSL remotely from VS Code. See overview section in the extension page for more information.
- WebStorm:
- VS Code:
- Run
pnpm update-version <version>for change theversionto the desired version of your extension.
Important
On Windows, make sure you have WSL enabled and Linux distribution (e.g. Ubuntu) installed on WSL.
Then, depending on the target browser:
- Run:
- Dev:
pnpm dev(on Windows, you should run as administrator;seeissue#456) - Prod:
pnpm build
- Dev:
- Open in browser -
chrome://extensions - Check -Developer mode
- Click -Load unpacked in the upper left corner
- Select the
distdirectory from the boilerplate project
- Run:
- Dev:
pnpm dev:firefox - Prod:
pnpm build:firefox
- Dev:
- Open in browser -
about:debugging#/runtime/this-firefox - Click -Load Temporary Add-on... in the upper right corner
- Select the
./dist/manifest.jsonfile from the boilerplate project
Note
In Firefox, you load add-ons in temporary mode. That means they'll disappear after each browser close. You have toload the add-on on every browser launch.
- Run
pnpm i <package> -w
- Run
pnpm i <package> -F <module name>
package - Name of the package you want to install e.g.nodemonmodule-name - You can find it inside eachpackage.json under the keyname, e.g.@extension/content-script, youcan use onlycontent-script without@extension/ prefix
Read:Env Documentation
The extension lives in thechrome-extension directory and includes the following files:
manifest.ts- script that outputs themanifest.jsonsrc/background-background script(background.service_workerin manifest.json)public- icons referenced in the manifest; content CSS for user's page injection
Important
To facilitate development, the boilerplate is configured to "Read and change all your data on all websites".In production, it's best practice to limit the premissions to only the strictly necessary websites. SeeDeclaring permissionsand editmanifest.js accordingly.
Code that is transpiled to be part of the extension lives in thepages directory.
content- Scripts injected into specified pages (You can see it in console)content-ui- React Components injected into specified pages (You can see it at the very bottom of pages)content-runtime-injected content scriptsThis can be injected from e.g.popuplike standardcontentdevtools-extend the browser DevTools(devtools_pagein manifest.json)devtools-panel-DevTools panelfordevtoolsnew-tab-override the default New Tab page(chrome_url_overrides.newtabin manifest.json)options-options page(options_pagein manifest.json)popup-popup shown whenclicking the extension in the toolbar(action.default_popupin manifest.json)side-panel-sidepanel (Chrome 114+)(side_panel.default_pathin manifest.json)
Some shared packages:
dev-utils- utilities for Chrome extension development (manifest-parser, logger)env- exports object which contain all environment variables from.envand dynamically declaredhmr- custom HMR plugin for Vite, injection script for reload/refresh, HMR dev-serveri18n- custom internationalization package; provides i18n function with type safety and other validationshared- shared code for the entire project (types, constants, custom hooks, components etc.)storage- helpers for easier integration withstorage, e.g. local/session storagestailwind-config- shared Tailwind config for entire projecttsconfig- shared tsconfig for the entire projectui- function to merge your Tailwind config with the global one; you can save components herevite-config- shared Vite config for the entire project
Other useful packages:
zipper- runpnpm zipto pack thedistfolder intoextension-YYYYMMDD-HHmmss.zipinside the newly createddist-zipmodule-manager- runpnpm module-managerto enable/disable modulese2e- runpnpm e2efor end-to-end tests of your zipped extension on different browsers
If saving source files doesn't cause the extension HMR code to trigger a reload of the browser page, try this:
- Ctrl+C the development server and restart it (
pnpm run dev) - If you get a
grpcerror,kill theturboprocessand runpnpm devagain.
If you are using WSL and imports are not resolving correctly, ensure that you have connected VS Code to WSL remotely using theRemote - WSL extension.
To chat with other community members, you can join theDiscord server.You can ask questions on that server, and you can also help others.
Also, suggest new features or share any challenges you've faced while developing Chrome extensions!
If you're debugging one, you can useBrie lets you capture screenshots, errors, and network activity, making it easier for us to help.
This Boilerplate is made possible thanks to all of its contributors.
![]() |
|---|
Made byJonghakseo
About
Chrome Extension Boilerplate with React + Vite + Typescript
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
Uh oh!
There was an error while loading.Please reload this page.

