Set an environment variable with the JS file that needs to be loaded for workers
Trunk supports web workers as assets and can generate a loader shim:
<link data-trunk rel="rust" href="Cargo.toml" data-bin="worker" data-type="worker" data-weak-refs data-loader-shim />
When using these workers, it is mandatory to know the path. For example, with gloo-worker:
let mut bridge = MarkdownWorker::spawner().spawn_with_loader("/example_markdown_worker_loader.js");
This can be solved by trunk if an environment variable is set which names the loader file. That would make the loading:
let mut bridge = MarkdownWorker::spawner().spawn_with_loader(env!("WORKER_LOADER"));
The name of the environment variable will be inferred by the asset configuration. It will also be possible to override the environment variable name
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
This issue was closed because it has been stalled for 5 days with no activity.
Can this be reopened?
Example project: https://github.com/rustwasm/gloo/tree/master/examples/markdown
I've started to take a look at this. Here's a thing:
- The env-var value (and name) is required during the compilation of the wasm code
- If the env-var value should be hashed (see #405) it's hash value would need to be known upfront
This would mean two things: a) it cannot be processes in parallel (which it might likely can't anyway because of cargo build locks) and b) there must be an order of imports (worker first, then main), which might get tricky and problematic if there's a circular dependency situation (not sure that worth supporting).
We would resolve this by having fixed shim names, and then fetching with no-cache, as suggested here: https://github.com/trunk-rs/trunk/issues/405#issuecomment-1237042106
That would of course mean that shim loaders would because a requirement for solving #405.