TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/crxjs/chrome-extension-tools/llms.txt
Use this file to discover all available pages before exploring further.
CrxPlugin interface extends Vite’s standard plugin interface with additional hooks specific to Chrome extension development. This allows you to customize manifest processing and script output during both build and development.
Interface Definition
Hooks
transformCrxManifest
Runs during the transform hook for the manifest. Use this to modify the manifest before it’s processed by CRXJS.The manifest object with input filenames (not yet processed by bundler)
Return the transformed manifest, or
null/undefined to skip transformationContext
- When: During Vite’s transform phase
- Filenames: Use input filenames (source paths)
- Use case: Modify manifest before bundling (e.g., add/remove entries, validate structure)
renderCrxManifest
Runs duringgenerateBundle, before the manifest is written to the output directory. Use this to modify the manifest with final output filenames.
The manifest object with output filenames (after bundling)
Rollup’s output bundle containing all generated files
Return the transformed manifest, or
null/undefined to skip transformationContext
- When: During Rollup’s
generateBundlephase, before manifest output - Filenames: Use output filenames (final bundled paths)
- Use case: Final manifest modifications with knowledge of all output files
renderCrxDevScript
Runs in the file writer for content scripts during development mode. Use this to transform script code before it’s written to disk.The transformed script code from Vite
Return the transformed code, or
null/undefined to skip transformationContext
- When: During development, before scripts are written to disk
- Filenames: Script ID uses Vite URL format
- Use case: Inject code into content scripts, add runtime helpers, transform syntax
Complete Example
Here’s a complete example combining all hooks:Usage
Add your plugin to the Vite config:Best Practices
Return null or undefined to skip transformation
Return null or undefined to skip transformation
If your hook doesn’t need to modify the input, return
null, undefined, or simply don’t return anything. This signals that no transformation occurred.Be mindful of hook execution order
Be mindful of hook execution order
transformCrxManifestruns before bundlingrenderCrxManifestruns after bundling- Multiple plugins execute in the order they’re defined in the config
Don't mutate the original manifest
Don't mutate the original manifest
Always create a new manifest object or clone the existing one to avoid side effects:
Use type guards for safety
Use type guards for safety
Check for undefined values before accessing nested properties: