I already have Workers in my Angular app. But I'm trying to create a Shared Worker, and it fails, saying "Failed to fetch a worker script." in the console.
const worker = new SharedWorker('../../../workers/my.shared.worker', { name: 'mySharedWorker', type: 'module' });
If I replace SharedWorker with Worker - it works perfectly.
Of course, I made everything as needed. Created an additional .tsconfig file:
/// tsconfig.worker.json
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./out-tsc/worker",
"lib": [
"es2018",
"webworker"
]
},
"include": [
"src/workers/*.worker.ts"
]
}
And added webWorkerTsConfig to angular.json config:
projects.myProject.architect.build.options.webWorkerTsConfig: "tsconfig.worker.json"
I found this article by Nikita Barsukov but it works only if your Worker is stored as a single file in the assets folder. But my SharedWorker contains dozen of .ts files, that should be bundled just like an ordinary Worker.