1. Traditional Method - importScripts
Because service worker is a worker, you can use importScripts(). For example:
// in manifest.json
"background": {
"service_worker": "sw.js"
}
// in sw.js
importScripts('path/a.js');
importScripts('path/b.js');
importScripts('path/c.js');
2. ES Module - import
// in manifest.json
"background": {
"service_worker": "sw.js",
"type": "module"
}
// in sw.js
import * as myModule from "path/module-name.js";
3. Use any package tools, package multiple js files into one bundle file
For example,
// in manifest.json
"background": {
"service_worker": "sw.js"
}
// command line
cat a.js b.js c.js > sw.js