You can check the files used for our simple gif-processor worker (packages/gif-processor):
-
Create relevant folder inside
packages/and put a .ts file for the main thread and another .ts for the worker (gif-processor example:processor.tsandworker.ts) -
Copy the tsconfig.json file from
packages/gif-processorinto the new folder, rename and edit its "OutDir" value to point to a new folder inside/static/ -
Duplicate the
targets/engine/gif-processor.jsonfile, rename it and change its "file" value to point to your worker .ts file -
Inside the
Makefilefile create a new path constant (like the one forGIF_PROCESSOR) and set the path to your compiled worker file (the folder you created in step 2 plus 'worker.ts'). Then add that new constant insidebuild-essentialslikeGIF_PROCESSOR -
Inside the
Makefileadd the following 2 lines with your own paths:
static/gif-processor/worker.js: packages/gif-processor/*.ts
@$(COMPILER) targets/engine/gif-processor.json
- You should be able to import your package that uses the Worker anywhere. Beware of the limitations when passing data to/from workers and also consider passing the data as Transferable objects to improve performance.