GitHunt
SH

shekhardtu/create-browser-extension-cli

Just like create react app, a CLI to generate boilerplate for either Google Chrome or Mozilla Firefox extension. Get a head start of un-opinionated project structure with prebuilt templates

๐Ÿš€ create-browser-extension-cli

A simple CLI tool to quickly scaffold boilerplate for Chrome and Firefox extensions, similar to create-react-app. Get a head start with an un-opinionated project structure and prebuilt templates for cross-browser support.

โœจ Features

  • โšก Generate boilerplate code for Chrome and Firefox extensions
  • ๐Ÿ”„ Hot Module Replacement (HMR) for Chrome extensions, ensuring smooth development
  • ๐Ÿ–ฅ๏ธ Single codebase for multiple browsers
  • ๐Ÿ“ฆ Preconfigured Webpack setup for both development and production environments
  • ๐Ÿ› ๏ธ Extendable and flexible project structure

๐Ÿ“ฅ Installation

To install the CLI globally, run:

npm install -g create-browser-extension-cli

๐Ÿ› ๏ธ Usage

To create a new browser extension project, run the following command:

create-browser-extension <project-name>

You will be prompted to choose the browsers you wish to support (Chrome, Firefox, or both).

Example

create-browser-extension my-extension

This will generate a project in the my-extension folder.

๐Ÿ—‚๏ธ Project Structure

Once generated, your project will have the following structure:

<project-name>/
  โ”œโ”€โ”€ config/
  โ”‚   โ”œโ”€โ”€ manifest-chrome.json       # Chrome-specific manifest file
  โ”‚   โ””โ”€โ”€ manifest-firefox.json      # Firefox-specific manifest file
  โ”œโ”€โ”€ src/
  โ”‚   โ”œโ”€โ”€ background.js              # Background script for the extension
  โ”‚   โ””โ”€โ”€ popup/
  โ”‚       โ””โ”€โ”€ popup.js               # Popup script
  โ”œโ”€โ”€ webpack/
  โ”‚   โ”œโ”€โ”€ webpack.common.js          # Shared Webpack configuration
  โ”‚   โ”œโ”€โ”€ webpack.dev.js             # Development-specific Webpack configuration
  โ”‚   โ””โ”€โ”€ webpack.prod.js            # Production-specific Webpack configuration
  โ”œโ”€โ”€ package.json
  โ””โ”€โ”€ README.md                      # Project documentation

๐Ÿ“œ Available Scripts

The following scripts are preconfigured in the generated package.json:

  • dev:chrome: Starts the development server with HMR for Chrome ๐Ÿ”„
  • build:chrome: Builds the extension for Chrome ๐Ÿ—๏ธ
  • build:firefox: Builds the extension for Firefox ๐ŸฆŠ

Running Scripts

To run the available scripts, navigate to your project directory and use npm run followed by the script name. For example, to start the development server for Chrome:

cd my-extension
npm run dev:chrome

๐Ÿ› ๏ธ Development

During development, you can use the following command to start the development server with Hot Module Replacement (HMR) for Chrome:

npm run dev:chrome

This uses the configuration from webpack/webpack.dev.js to enable rapid development by automatically reloading code changes without manually refreshing the extension.

๐Ÿ—๏ธ Building

To create production-ready builds, use the following commands:

  • Build for Chrome:

    npm run build:chrome
  • Build for Firefox:

    npm run build:firefox

These commands will use the configuration from webpack/webpack.prod.js to create optimized builds for the respective browsers.

๐ŸŒ Browser Compatibility

The CLI supports both Chrome and Firefox, and the generated project structure allows you to share a common codebase for both browsers. You can still customize specific features by modifying the respective manifest-chrome.json and manifest-firefox.json files.

๐Ÿค Contributing

Contributions are welcome! If you'd like to improve this CLI or fix any issues, feel free to submit a pull request or open an issue. Let's build together! ๐Ÿ’ช

๐Ÿ“„ License

This project is licensed under the MIT License. See the LICENSE file for more details.


Happy coding! ๐Ÿš€๐ŸŽ‰

shekhardtu/create-browser-extension-cli | GitHunt