swc transform plugin for `@shopify/web-worker`
npm install @shopify/web-worker-swc-pluginPlugin for @shopify/web-worker.
A swc plugin that identifies uses of createWorkerFactory that need to be processed.
We do _not_ recommend including the plugin for the test environments. When the swc plugin is omitted, Factory will know to access your module asynchronously, and will proxy all method calls to it. When in this mode, the function returned from createWorkerFactory _will not_ actually construct a Worker for your code. As a result, this will only work if your worker code is written such that it will also execute successfully on the "main" thread. If you do use features in the worker that make it incompatible to run alongside the browser code, we recommend mocking the "worker" module (using jest.mock(), for example).
To load plugins, you may use swcrc's jsc.experimental configs:
``pluginname
{
jsc: {
...
experimental: {
...
cache_root: String // optional, specify where swc will create wasm bytecode cache
// list of plugins. If is resolvable to npm package, it'll try to load from installed npm packages.``
// or it can be an absolute path to the .wasm binary
plugins: [
[
'@shopify/web-worker-swc-plugin',
{
"webpackLoader": path.resolve('@shopify/web-worker/build/cjs/webpack-parts/loader.js'),
"packages": {
"@shopify/web-worker": [
{
"name": "createPlainWorkerFactory"
},
{
"name": "createWorkerFactory",
wrapperModule: path.resolve('@shopify/web-worker/build/cjs/wrappers/expose.js.raw'),
}
]
}
}
]
]
}
}