Building and Packaging
Relevant source files
The following files were used as context for generating this wiki page:
The build and packaging process for the Read Frog extension is managed by a combination of modern web development tools. The core of the system is the WXT framework, which is specifically designed for building browser extensions. It handles the complexities of manifest generation, entrypoint bundling, and packaging for different browsers.
This process is orchestrated through pnpm scripts, which in turn leverage Nx for task running and caching. Nx optimizes the build process by caching outputs of tasks like building, testing, and linting, which significantly speeds up development workflows. The entire system is configured to produce optimized builds for various target browsers like Chrome, Firefox, and Edge, and to create distributable ZIP archives for submission to browser stores.
Sources: CLAUDE.md, package.json, nx.json
Core Tooling
The project relies on a set of key tools to manage dependencies, run tasks, and build the extension.
| Tool | Purpose | Source File |
|---|---|---|
| WXT | A Vite-based framework for building browser extensions. It handles manifest generation, entrypoints, and cross-browser builds. | package.json:151, wxt.config.ts:4 |
| pnpm | The package manager used for the project, specified in the packageManager field. | package.json:6 |
| Nx | A smart build system that provides task running and computation caching. It's used to execute build, test, and lint commands. | package.json:144, nx.json |
| Vite | The underlying bundler used by WXT to compile and bundle the TypeScript and React source code. | CLAUDE.md:100 |
| TypeScript | The primary programming language for the project. | package.json:150 |
| React | The UI library used for creating the extension's components. WXT integrates it via the @wxt-dev/module-react module. | package.json:148, wxt.config.ts:9 |
Sources: package.json, wxt.config.ts, CLAUDE.md, nx.json
Build and Development Scripts
The package.json file defines a series of scripts for development, building, testing, and packaging. These scripts are the primary interface for developers to interact with the build system.
This diagram shows the flow from a developer running a pnpm script to the final build output.
Sources: package.json:8-23, nx.json:44-50
Key Scripts
| Script | Description |
|---|---|
pnpm dev | Starts the development server for Chrome using WXT. Enables hot-reloading. |
pnpm dev:firefox | Starts the development server specifically for the Firefox browser. |
pnpm build | Creates a production build of the extension for Chrome in the .output directory. |
pnpm build:firefox | Creates a production build for Firefox. |
pnpm build:analyze | Creates a production build and opens a bundle analysis tool to inspect bundle sizes. |
pnpm zip | Creates a distributable ZIP file for the Chrome version of the extension. |
pnpm zip:firefox | Creates a distributable ZIP file for the Firefox version. |
pnpm test | Runs the test suite once using Vitest. |
pnpm lint | Lints the codebase using ESLint. |
pnpm type-check | Performs a static type check using TypeScript. |
pnpm release | Creates a Changesets tag and pushes it to origin, part of the release process. |
Sources: package.json:8-23
Build Configuration (wxt.config.ts)
The primary build configuration is located in wxt.config.ts. This file instructs WXT on how to construct the extension, generate the manifest, and handle different build environments.
Manifest Generation
The manifest property is a function that dynamically generates the manifest.json file based on the build mode (development or production) and browser.
This diagram illustrates the conditional logic within the manifest generation.
Sources: wxt.config.ts:18-56
Key manifest configurations include:
name&description: Pulled from i18n locale files (__MSG_extName__).permissions: Requests necessary browser permissions likestorage,tabs, andidentity.host_permissions: Dynamically set based on the environment. In development, it includeslocalhostfor local backend testing. In production, it's restricted to*.readfrog.appand Google APIs.oauth2: Configured for Google Drive integration, using an environment variable for theclient_id.key: A fixed extension ID is used in development for Chrome and Edge to ensure a consistent ID between rebuilds.browser_specific_settings: For Firefox, it specifies the Gecko extension ID and minimum version.
Sources: wxt.config.ts:18-56
Modules and Aliases
WXT's functionality is extended through modules. This project uses:
@wxt-dev/module-react: To enable React support.@wxt-dev/i18n/module: For internationalization support.
Path aliases are also configured to simplify imports, especially for local monorepo development when WXT_USE_LOCAL_PACKAGES is true.
Sources: wxt.config.ts:9-16
Nx Caching and Task Execution (nx.json)
Nx is configured in nx.json to optimize the build and test processes. It defines targetDefaults which specify caching strategies for different tasks.
Target Caching
For targets like build, test, and lint, Nx is configured to cache the results. The cache is invalidated only when the specified inputs change.
inputs: Define the files and configurations that affect the output of a task. For thebuildtarget, this includes all source files, public assets, and configuration files likewxt.config.ts,package.json, andtsconfig.json.outputs: Specify the directories or files that are generated by a task. For thebuildtarget, this is the.outputand.wxtdirectories. Fortest:cov, it's thecoveragedirectory.
This configuration ensures that if no relevant source files have changed, Nx can restore the output from its cache instead of re-running the entire build process.
// nx.json
"targetDefaults": {
"build": {
"cache": true,
"inputs": [
"{projectRoot}/src/**/*",
"{projectRoot}/public/**/*",
"{projectRoot}/wxt.config.ts",
"{projectRoot}/package.json",
// ...
],
"outputs": ["{projectRoot}/.output", "{projectRoot}/.wxt"]
},
// ...
}
Sources: nx.json:3-20
Nx Targets in package.json
The pnpm scripts are mapped to Nx's task runner via the nx property in package.json. Each target uses the nx:run-commands executor to simply run the corresponding command-line instruction, allowing Nx to wrap the execution with its caching and orchestration logic.
// package.json
"nx": {
"targets": {
"build": {
"executor": "nx:run-commands",
"options": {
"command": "wxt build"
}
},
"test": {
"executor": "nx:run-commands",
"options": {
"command": "vitest run"
}
},
// ...
}
}
Sources: package.json:153-197
Packaging for Distribution
The final step for a release is creating a ZIP file that can be uploaded to browser web stores. The zip and zip:firefox scripts handle this.
pnpm zip: Executeswxt zip, which takes the output from the standard build and packages it into a ZIP file suitable for the Chrome Web Store.pnpm zip:firefox: Executeswxt zip -b firefox, which creates a ZIP file specifically for the Mozilla Add-ons store, incorporating any Firefox-specific manifest settings.
The version number for the package is managed in package.json and is used by WXT to version the extension build and the resulting ZIP file. The extension-release-shield in the README.md file reflects this version.
Sources: package.json:8, 21-22, README.md:12