Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Chrome Extension Boilerplate with React + Vite + Typescript

License

NotificationsYou must be signed in to change notification settings

Jonghakseo/chrome-extension-boilerplate-react-vite

Repository files navigation

Logo

GitHub action badgeGitHub action badge

This boilerplatehasLegacy version

Note

This project is listed in theAwesome Vite

Tip

Share storage state between all pages

2024-07-20.12.36.15.mov

Table of Contents

Intro

This boilerplate helps you create Chrome/Firefox extensions using React and Typescript. It improvesthe build speed and development experience by using Vite and Turborepo.

Features

Installation

  1. Clone this repository.(git clone https://github.com/Jonghakseo/chrome-extension-boilerplate-react-vite )
  2. Ensure your node version is >= than in.nvmrc file, recommend to usenvm
  3. Edit/packages/i18n/locales/{your locale(s)}/messages.json
  4. In the objectsextensionDescription andextensionName, change themessage fields (leavedescription alone)
  5. Install pnpm globally:npm install -g pnpm
  6. Runpnpm install
  7. Check if you have that configuration in your IDE/Editor:
    • VS Code:
      • InstalledESLint extension
      • InstalledPrettier extension
      • EnabledTypescript Workbench version in settings:
        • CTRL + SHIFT + P -> Search:Typescript: Select Typescript version... ->Use Workbench version
        • Read more
      • 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:
      • ConfiguredESLint
      • ConfiguredPrettier
      • Optional, but usefulFile | Settings | Tools | Actions on Save
        ->Optimize imports andReformat code
  8. Runpnpm update-version <version> for change theversion to the desired version of your extension.

Important

On Windows, make sure you have WSL enabled and Linux distribution (e.g. Ubuntu) installed on WSL.

Installation Guide

Then, depending on the target browser:

For Chrome:

  1. Run:
    • Dev:pnpm dev (on Windows, you should run as administrator;seeissue#456)
    • Prod:pnpm build
  2. Open in browser -chrome://extensions
  3. Check -Developer mode
  4. Click -Load unpacked in the upper left corner
  5. Select thedist directory from the boilerplate project

For Firefox:

  1. Run:
    • Dev:pnpm dev:firefox
    • Prod:pnpm build:firefox
  2. Open in browser -about:debugging#/runtime/this-firefox
  3. Click -Load Temporary Add-on... in the upper right corner
  4. Select the./dist/manifest.json file 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.

Install dependency for turborepo:

For root:

  1. Runpnpm i <package> -w

For module:

  1. Runpnpm i <package> -F <module name>

package - Name of the package you want to install e.g.nodemon
module-name - You can find it inside eachpackage.json under the keyname, e.g.@extension/content-script, youcan use onlycontent-script without@extension/ prefix

How do I disable modules I'm not using?

Read here

Environment variables

Read:Env Documentation

Boilerplate structure

Chrome extension

The extension lives in thechrome-extension directory and includes the following files:

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.

Pages

Code that is transpiled to be part of the extension lives in thepages directory.

Packages

Some shared packages:

  • dev-utils - utilities for Chrome extension development (manifest-parser, logger)
  • env - exports object which contain all environment variables from.env and dynamically declared
  • hmr - custom HMR plugin for Vite, injection script for reload/refresh, HMR dev-server
  • i18n - custom internationalization package; provides i18n function with type safety and other validation
  • shared - shared code for the entire project (types, constants, custom hooks, components etc.)
  • storage - helpers for easier integration withstorage, e.g. local/session storages
  • tailwind-config - shared Tailwind config for entire project
  • tsconfig - shared tsconfig for the entire project
  • ui - function to merge your Tailwind config with the global one; you can save components here
  • vite-config - shared Vite config for the entire project

Other useful packages:

  • zipper - runpnpm zip to pack thedist folder intoextension-YYYYMMDD-HHmmss.zip inside the newly createddist-zip
  • module-manager - runpnpm module-manager to enable/disable modules
  • e2e - runpnpm e2e for end-to-end tests of your zipped extension on different browsers

Troubleshooting

Hot module reload seems to have frozen

If saving source files doesn't cause the extension HMR code to trigger a reload of the browser page, try this:

  1. Ctrl+C the development server and restart it (pnpm run dev)
  2. If you get agrpc error,kill theturbo processand runpnpm dev again.

Imports not resolving correctly

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.

Community

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!

Debugging

If you're debugging one, you can useBrie lets you capture screenshots, errors, and network activity, making it easier for us to help.

Reference

Star History

Star History Chart

Contributors

This Boilerplate is made possible thanks to all of its contributors.

All Contributors

Special Thanks To

JetBrains Logo (Main) logo.Jackson Hong

Made byJonghakseo

About

Chrome Extension Boilerplate with React + Vite + Typescript

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp