@shopify/web-worker-swc-plugin v0.6.1
shopify_web_worker_swc_plugin
Plugin for @shopify/web-worker
.
A swc plugin that identifies uses of createWorkerFactory that need to be processed.
Tests
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).
Usage
To load plugins, you may use swcrc
's jsc.experimental
configs:
{
jsc: {
...
experimental: {
...
cache_root: String // optional, specify where swc will create wasm bytecode cache
// list of plugins. If `pluginname` 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'),
}
]
}
}
]
]
}
}