JavaScript files power multiple aspects of an extension's functionality. User scripts, background processes, content scripts, and service workers all leverage JavaScript to deliver dynamic behavior and respond to user interactions. Extension.js ensures that JavaScript and TypeScript files defined in the manifest.json are correctly processed, with full support for hot-module replacement (HMR) and other development tools.
Extension.js handles the following for script resources:
dist output directory.manifest.json are flagged during the build to prevent runtime issues.| Manifest Field | File Type Expected | HMR Support |
|---|---|---|
background.service_worker |
.js, .ts, .mjs, .tsx |
No |
background.scripts |
.js, .ts, .mjs, .tsx |
Yes |
content_scripts.js |
.js, .ts, .mjs, .tsx |
Yes |
content_scripts.css |
.css, .scss, .less, .sass |
Yes |
user_scripts.api_script |
.js, .ts, .mjs, .tsx |
Yes |
manifest.jsonHere's an example of defining JavaScript files in manifest.json:
You should be able to manage y
Extension.js processes additional JavaScript files that provide auxiliary functions, like utilities or helper functions, even if they're not defined in the manifest. Place these scripts in the /scripts folder for automatic inclusion in the build.
Add utility scripts or other JavaScript resources to /scripts:
Script output paths are structured according to their context within the manifest:
The plugin for script file support in Extension.js ensures the following during compilation:
/scripts folder are included in the build process.content_scripts are dynamically injected to support HMR./scripts Folder: Place all utility and helper scripts that aren't declared in manifest.json here.