svelte-chrome-extension-starter Svelte Themes

Svelte Chrome Extension Starter

Svelte + Nx + Tailwindcss + ShadCN + Web Components Chrome Extension Starter Project

The purpose of this project is to create an efficient Svelte Monorepo structure to develop complex Chrome Extensions that demand constant maintaining and improvement. I specifically chose Svelte over React or Angular as lack of Virtual DOM overhead when injecting custom components into web-pages makes a lot of sense to me. Svelte is just simple enough to minimize conflicts on arbitrary web pages while also being functional enough to make maintaining a large codebase easier.

šŸ“– Table of Contents

āœØ Features

āœ… Nx Workspace

āœ… Svelte 5

āœ… Typescript

āœ… Chrome Types

āœ… Live Reload

āœ… Very Fast Build

āœ… All In One Command

āœ… Support Manifest V3

āœ… Popup Page

āœ… Options Page

āœ… Devtools Panel

āœ… Background Script

āœ… Content Script

āœ… ShadCN-Svelte

āœ… Web Components (via Svelte Custom Elements and Lit)

āœ… Custom Elements Use Compiled Tailwind Styles

āœ… Injected Tailwind Styles Replace rem with em to ignore the page root styles

āœ… Husky

āœ… Commitlint

āœ… Github Actions

āœ… Commitizen

āœ… Dark Mode

šŸŽÆ Prerequisites

šŸš€ Getting Started

  1. Install dependencies
pnpm install
  1. Run Live Reload
pnpm dev:all
  1. Open Chrome browser
  2. Go to this url: chrome://extensions
  3. Click on "Developer mode"
  4. Click on "Load unpacked"
  5. Choose the extension directory from this root directory

ā„¹ļø More info about developing Chrome extension can be found here

šŸ— Project Structure

Nx Workspace contributes significantly to clear project structure in this repository. There are 5 projects that are compiled to separate folders.

  1. Popup (apps/popup) - used for the upper popup
  2. Options (apps/options) - used for the options page
  3. DevTools Panel (apps/devtools-panel) - used for the devtools panel
  4. Background Script (apps/scripts/background) - used for tracking page updates and communicating with other parts of the application via Chrome message system
  5. Content Script (apps/scripts/content) - used for monitoring of opened web-pages and injection of WebComponents.

All the applications have already the Chrome types so can just use chrome and the editor will recognize it.

šŸ§© Web Components (Svelte Custom Elements)

The most important part of this project is the injection of Svelte-compiled web components into web pages, contained within /libs/custom-elements. I decided to use ShadCN to create reusable custom-elements. Injecting isolated, compiled Tailwind styles into the WebComponents (without breaking websites that use Tailwind) and getting development workflow with them to an acceptable level took most of development time.

It is also a part which I am least confident in, so any contribution would be appreciated.

šŸ•¹ Commands

Start with development configuration

pnpm dev:all

Start with production configuration.

pnpm prod:all

Build with development configuration.

npm run build:dev

Build with production configuration.

npm run build:prod

šŸ“œ License

MIT

ā¤ļø Special thanks to

freeCodeCamp.org - for providing the idea for a bookmark app which organically touches on all aspects of Chrome Extension Development

Aviv Haruzi - For an example of a Chrome Extension project with Nx Workspace and providing the template for this README.

Top categories

Loading Svelte Themes