Note
This project is listed in the Awesome Vite
Tip
Share storage state between all pages
2024-07-20.12.36.15.mov
- Intro
- Features
- Structure
- Getting started
- Install dependency
- Community
- Reference
- Star History
- Contributors
This boilerplate is made for creating chrome extensions using React and Typescript.
The focus was on improving the build speed and development experience with Vite(Rollup) & Turborepo.
- React18
- TypeScript
- Tailwindcss
- Vite
- Turborepo
- Prettier
- ESLint
- Chrome Extension Manifest Version 3
- Custom I18n Package
- Custom HMR(Hot Module Rebuild) Plugin
- End to End Testing with WebdriverIO
- When you're using Windows run this:
git config --global core.eol lf
git config --global core.autocrlf input
- Clone this repository.
- Change
extensionDescription
andextensionName
inmessages.json
file. - Install pnpm globally:
npm install -g pnpm
(check your node version >= 18.19.1)) - Run
pnpm install
- Run:
- Dev:
pnpm dev
(On windows, you should run as administrator. (Issue#456) - Prod:
pnpm build
- Dev:
- Open in browser -
chrome://extensions
- Check -
Developer mode
- Find and Click -
Load unpacked extension
- Select -
dist
folder at root
- Run:
- Dev:
pnpm dev:firefox
- Prod:
pnpm build:firefox
- Dev:
- Open in browser -
about:debugging#/runtime/this-firefox
- Find and Click -
Load Temporary Add-on...
- Select -
manifest.json
fromdist
folder at root
Remember in firefox you add plugin in temporary mode, that's mean it'll disappear after each browser close.
You have to do it 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. nodemon
module-name
- You can find it inside each package.json
under the key name
, e.g. @extension/content-script
, you can use only content-script
without @extension/
prefix
- Copy
.example.env
and past it as.env
in the same path - Add a new record inside
.env
- Add this key with type for value to
vite-env.d.ts
(root) toImportMetaEnv
- Then you can use it with
import.meta.env.{YOUR_KEY}
like with standard Vite Env
- Create
.env
inside that package - Open related
vite.config.mts
and addenvDir: '.'
at the end of this config - Rest steps like above
Remember you can't use global and local at the same time for the same package(It will be overwritten)
Main app with background script, manifest
manifest.js
- manifest for chrome extensionsrc/background
- background script for chrome extension (background.service_worker
in manifest.json)public/content.css
- content css for user's page injection
Some shared packages
dev-utils
- utils for chrome extension development (manifest-parser, logger)i18n
- custom i18n package for chrome extension. provide i18n function with type safety and other validation.hmr
- custom HMR plugin for vite, injection script for reload/refresh, hmr dev-servershared
- shared code for entire project. (types, constants, custom hooks, components, etc.)storage
- helpers for storage easier integration with, e.g local, session storagestailwind-config
- shared tailwind config for entire projecttsconfig
- shared tsconfig for entire projectui
- here's a function to merge your tailwind config with global one, and you can save components herevite-config
- shared vite config for entire projectzipper
- Bypnpm zip
you can packdist
folder intoextension.zip
inside newly createddist-zip
e2e
- Bypnpm e2e
you can run end to end tests of your zipped extension on different browsers
content
- content script for chrome extension (content_scripts
in manifest.json)content-ui
- content script for render UI in user's page (content_scripts
in manifest.json)content-runtime
- content runtime script this can be inject frompopup
like standardcontent
devtools
- devtools for chrome extension (devtools_page
in manifest.json)devtools-panel
- devtools panel for devtoolsnew-tab
- new tab for chrome extension (chrome_url_overrides.newtab
in manifest.json)options
- options for chrome extension (options_page
in manifest.json)popup
- popup for chrome extension (action.default_popup
in manifest.json)side-panel
- sidepanel(Chrome 114+) for chrome extension (side_panel.default_path
in manifest.json)
To chat with other community members, you can join the Discord 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!
This Boilerplate is made possible thanks to all of its contributors.
Made by Jonghakseo