rollup-plugin-chrome-extension (RPCE) is a Rollup plugin designed to simplify the development and bundling of Chrome Extensions. It functions by using the `manifest.json` file as its primary input, automatically processing and bundling all declared assets into the output directory. As of version 3.6.15, the plugin is actively maintained within the `crxjs` monorepo, which also includes a `vite-plugin-chrome-extension`. RPCE provides crucial features like Hot Module Replacement (HMR) for a rapid development cycle, seamless integration with Manifest V3, and automatic handling of web-accessible resources. Its key differentiators include the manifest-first configuration approach, which abstracts away complex build setups, and its ability to bring modern bundler features to the extension development environment. It receives regular updates, mostly patch releases, and provides boilerplates for popular frameworks like React and Svelte.
npm install rollup-plugin-chrome-extensionVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates a basic `rollup.config.ts` setup for building a Chrome Extension using `rollup-plugin-chrome-extension`. It imports the plugin, uses a `manifest.json` as input, and includes common Rollup plugins for TypeScript, CommonJS, and Node module resolution. The `output.format` is set to ESM, which is recommended for Manifest V3 extensions.
Review Chrome's Manifest V3 migration guide. Ensure all code is bundled within the extension, refactor `webRequest` API usage, and update content security policies (CSP) in `manifest.json`.
Ensure all Rollup plugins used in conjunction with `rollup-plugin-chrome-extension` are compatible with Rollup v3 or later. Update or replace outdated plugins as necessary. The `crxjs` monorepo generally keeps its plugins up-to-date with current Rollup versions.
For scripts requiring frequent HMR, consider alternative injection methods or accept that main world content scripts might need manual reloading. The plugin provides warnings during development for detected main world scripts.
Always set `output.format: 'esm'` in your `rollup.config.js`. Ensure all your source code and dependencies are compatible with ESM, and use `import` statements over `require()`.
Remove all inline scripts (e.g., `<script>alert('hi')</script>`). Move script logic to external `.js` files. Update `manifest.json` to define a strict `content_security_policy` without `'unsafe-inline'`.In `rollup.config.js`, set `output.format: 'esm'`. Ensure your Rollup configuration file itself is treated as an ES Module (e.g., `.mjs` extension or `"type": "module"` in `package.json`).
Ensure `input` in `rollup.config.js` is set to your primary application entry (e.g., `src/popup/index.ts`) or `src/index.ts`, and that the `chromeExtension` plugin is correctly configured with `manifest: require('./manifest.json')` or `manifest: manifest` if imported.