crx() function in your vite.config.ts.
Basic Usage
Configuration Options
manifest
Your Chrome Extension manifest. Can be a manifest object, a function that returns a manifest, or imported from a JSON file.
contentScripts
Configuration options specific to content scripts behavior.
contentScripts.preambleCode
Code to inject before content scripts run. Set to
false to disable. Automatically configured for React projects using @vitejs/plugin-react.Default: Automatically detected for React, otherwise undefinedFor React projects, CRXJS automatically uses
@vitejs/plugin-react’s preamble code to ensure Fast Refresh works correctly in content scripts.contentScripts.hmrTimeout
Timeout in milliseconds for Hot Module Replacement (HMR) connections in content scripts.Default:
5000 (5 seconds)contentScripts.injectCss
Whether to automatically inject CSS imported by content scripts into the page. When
true, CSS is injected via JavaScript. When false, CSS files are included in web_accessible_resources.Default: truebrowser
Target browser for the extension. Affects manifest generation and browser-specific optimizations.Default:
'chrome'- Chrome: Uses
service_workerfor background scripts, supportsuse_dynamic_urlin web_accessible_resources - Firefox: Uses
scriptsarray for background scripts, omitsuse_dynamic_url(Firefox handles this automatically)
fastGlobOptions
Options passed to fast-glob when scanning for files referenced in the manifest (icons, locales, rulesets, etc.).
Complete Example
Type Definitions
The full TypeScript interface forCrxOptions is defined in @crxjs/vite-plugin:
See Also
- Vite Configuration - Recommended Vite settings
- Content Script Options - Deep dive into content script configuration
- Browser Support - Chrome vs Firefox differences