Vite 中文文档 Vite 中文文档
指南
GitHub (opens new window)
指南
GitHub (opens new window)
  • vite

    • 指引
    • 为什么选 Vite
    • 开始
    • 功能
    • 命令行界面
    • 使用插件
    • 依赖预构建
    • 静态资源处理
    • 构建生产版本
    • 部署静态站点
    • 环境变量和模式
    • 服务端渲染
    • 后端集成
    • 与其他工具比较
    • 故障排除
    • 从 v3 迁移
  • API

  • 配置参考

  • vite

  • API

  • 配置参考

logo #  Chrome Extension Boilerplate withReact + Vite + TypeScript + TailwindCSS

This is a side product of my Chrome Extension Supatabs.
Supatabs is a 🔥🔥 BLAZINGLY FAST 🔥🔥 free alternative to OneTab with support for chrome tab groups and searching through tabs.

If you tend to have thousands of tabs open, are a OneTab user, or use any other tab manager
make sure to check it out here!

Table of Contents


Intro
Why another boilerplate?
Features
Usage
Setup

Tech Docs
Credit
Contributing

Intro


This boilerplate is meant to be a quick start for creating chrome extensions using React, Typescript and Tailwind CSS.

Built for:

For improved DX and rapid building vite and nodemon are used.


Chrome does not accept manifest v2 extensions since Jan 2022, therefore this template uses manifest v3.


Firefox + other browsers don't yet support manifest v3, so cross browser usage is not encouraged.


Read more about Chrome manifest v2 support here.
Read more about Firefox Manifest v3 support here.

As soon as Firefox supports manifest v3, support will be added in this repo as well.

Oh by the way ... I also implemented a chrome local/sync storage hook for react, which works well with this template. Check it out here.

Why another boilerplate?


I have used webpack react boilerplates and found it too hard to configure.

Vite is actually mega easy to understand, which makes it easier to get into and to maintain for others.

I couldn't find a boilerplate for React, TypeScript and Tailwind CSS. So here it is.

Features


React 18
TypeScript
Vite
Tailwind CSS
ESLint
Chrome Extension Manifest Version 3

Usage


Setup


Clone this repository.
Change name and description in package.json => Auto synchronize with manifest
Run yarn or npm i (check your node version >= 16)
Run yarn dev or npm run dev
Load Extension on Chrome
Open - Chrome browser
Access - chrome://extensions
Check - Developer mode
Find - Load unpacked extension
Select - dist folder in this project (after dev or build)

If you want to build in production, Just run yarn build or npm run build.

Customization


As the template has allof the potential Chrome extension pages implemented, you likely have to customize it to fit your needs.

E.g. you don't want the newtab page to activate whenever you open a new tab:

remove the directory newtab and its contents in src/pages
remove the newtab rollup input in the vite.config.ts

  1. ``` ts
  2. //...
  3. build: {
  4.     outDir,
  5.     rollupOptions: {
  6.       input: {
  7.         devtools: resolve(pagesDir, 'devtools', 'index.html'),
  8.         panel: resolve(pagesDir, 'panel', 'index.html'),
  9.         content: resolve(pagesDir, 'content', 'index.ts'),
  10.         background: resolve(pagesDir, 'background', 'index.ts'),
  11.         popup: resolve(pagesDir, 'popup', 'index.html'),
  12.         newtab: resolve(pagesDir, 'newtab', 'index.html'),  // <--- REMOVE THIS LINE
  13.         options: resolve(pagesDir, 'options', 'index.html'),
  14.       },
  15.       output: {
  16.         entryFileNames: (chunk) => `src/pages/${chunk.name}/index.js`,
  17.       },
  18.     },
  19.   },
  20. /...
  21. ```

CSS files in the `src/pages/` directories are not necessary. They are left in there in case you want to use it in combination with Tailwind CSS. Feel free to delete them*.

Tailwind can be configured as usual in the tailwind.config.cjs file. See doc link below.

Tech Docs


Vite Plugin
Chrome Extension with manifest 3
Rollup
Rollup-plugin-chrome-extension
Tailwind CSS

Credit


Heavily inspired by Jonghakseo's vite chrome extension boilerplate. It uses SASS instead of TailwindCSS if you want to check it out.

Contributing


Feel free to open PRs or raise issues!
Last Updated: 2023-05-23 11:11:51