Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Worker Loader #349

Merged
merged 5 commits into from
Jul 30, 2023
Merged

Add Worker Loader #349

merged 5 commits into from
Jul 30, 2023

Conversation

futursolo
Copy link
Collaborator

@futursolo futursolo commented Jun 5, 2023

This pull request implements the loader shim mode that is coming in the next trunk version.

This mode no longer uses inline scripts to load workers.
Trunk is responsible to create a loader script to initialise the worker.

@futursolo futursolo marked this pull request as ready for review July 29, 2023 13:44
@futursolo futursolo requested a review from ranile July 29, 2023 13:44
@futursolo
Copy link
Collaborator Author

Trunk v0.17 has been released so we can release this gloo worker mode as well.

@ranile
Copy link
Collaborator

ranile commented Jul 29, 2023

Can you please also update the chnagelog?

Also, I would like to keep the ability to build workers without using trunk. That is kept intact, right? I use it to build workers that are called from a JS (SvelteKit) application so that is pretty important to have

@futursolo
Copy link
Collaborator Author

Can you please also update the chnagelog?

This is done.

Also, I would like to keep the ability to build workers without using trunk. That is kept intact, right? I use it to build workers that are called from a JS (SvelteKit) application so that is pretty important to have

This pull request adds a spawn_with_loader() function, which can be used with the loader shim created by trunk when data-loader-shim option is specified in index.html.

Existing worker users can continue using the spawn() function or create the loader shim manually.

e.g: The markdown example create the following loader shim:

importScripts("./example_markdown_worker.js");wasm_bindgen("./example_markdown_worker_bg.wasm");

Copy link
Collaborator

@ranile ranile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@@ -22,7 +22,8 @@ fn main() {
.flatten()
.expect_throw("failed to query root element");

let mut bridge = MarkdownWorker::spawner().spawn("/example_markdown_worker.js");
let mut bridge =
MarkdownWorker::spawner().spawn_with_loader("/example_markdown_worker_loader.js");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder if trunk can set a build-time env so this path doesn't need to be hard coded

@ranile ranile merged commit 26caf55 into rustwasm:master Jul 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants