In an extension, JavaScript files empower background processes, content scripts, user scripts, and service workers. 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 offers comprehensive support for script files, ensuring HMR where applicable. It handles entry point injection for JavaScript, TypeScript, and CSS in content scripts, service workers, and background scripts.
The following manifest fields are supported for JavaScript and related files:
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 |
Hereβs a basic example of defining scripts in the manifest.json
:
For scripts that are not declared in manifest.json
, such as utility scripts or other JavaScript files that provide additional functionality, place them in the /scripts
folder. This folder is automatically processed by Extension.js to ensure all scripts are included in the build.
Example Usage:
Add your additional script files to the /scripts
folder:
For more information on organizing these files, refer to the Special Folders documentation.
The output path for scripts is the following:
The plugin for script file support in Extension.js ensures the following steps occur during compilation:
/scripts
folder are added to the compilation process.content_scripts
are injected dynamically for HMR support./scripts
folder for additional JavaScript files that are not defined in manifest.json
.