Skip to content

Add support for js snippets #527

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

Merged
merged 2 commits into from
Jul 25, 2025
Merged

Conversation

kristoff3r
Copy link
Contributor

wasm-bindgen has a feature called js snippets, see https://rustwasm.github.io/wasm-bindgen/reference/js-snippets.html. This PR makes bevy cli take these files into account both when serving and bundling.

@TimJentzsch TimJentzsch self-requested a review July 21, 2025 05:58
@DaAlbrecht DaAlbrecht added C-Feature Make something new possible A-Web Building or running Bevy apps targeting the browser D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review The PR needs to be reviewed before it can be merged labels Jul 21, 2025
Copy link
Collaborator

@TimJentzsch TimJentzsch left a comment

Choose a reason for hiding this comment

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

Very cool, didn't know this feature existed! Thanks for working on this.

I created a test package and it works as expected.

Just have one suggestion, but otherwise it's good to go :)

&format!("/build/{}", wasm_file_name.to_str().unwrap()),
ServeFile::new(build_artifact_path.join(wasm_file_name)),
)
.nest_service("/build", ServeDir::new(build_artifact_path))
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure if it's a good idea to include the entire build artifact folder here. It can contain a lot of different files from many different binaries.
While this is for dev only, I think it would be best if we emulated the same environment as the packaged bundle, which wouldn't include the entire build folder

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't see it as a problem, it just means that we correctly route to any file that is needed in the folder. This makes us more robust to potential changes in the file layout.

The main reason I did it this way is that we don't know up front which snippets are included by wasm-bindgen, and that the snippet directories include the hash of the files. I think it would be quite complicated to get that information, for very little gain.

@TimJentzsch
Copy link
Collaborator

Oh, can you also add an entry to the CHANGELOG.md if you have the time?
Thank you!

Copy link
Collaborator

@TimJentzsch TimJentzsch left a comment

Choose a reason for hiding this comment

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

Thank you!

@TimJentzsch TimJentzsch merged commit 20dd84f into TheBevyFlock:main Jul 25, 2025
10 checks passed
@kristoff3r kristoff3r deleted the js-snippets branch July 25, 2025 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Web Building or running Bevy apps targeting the browser C-Feature Make something new possible D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review The PR needs to be reviewed before it can be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants