cloudflare / workers-rs

Write Cloudflare Workers in 100% Rust via WebAssembly
Apache License 2.0
2.53k stars 269 forks source link

[Feature] Access bundled files #596

Closed lemmih closed 2 months ago

lemmih commented 2 months ago

Is there an existing issue for this?

Description

Is there a way to access the files bundled with a worker?

The documentation says the files can be accessed via import in JS, but I'm unsure how that translates to Rust.

Documentation: https://developers.cloudflare.com/workers/wrangler/bundling/

kflansburg commented 2 months ago

I think you would need to modify the JS shim that is used, import the assets in JavaScript and then supply them to the WebAssembly invocation.

lemmih commented 2 months ago

Thanks.

spigaz commented 2 months ago

I'm not sure what you are up to, but there are alternative ways to include the content of files inside the assembly, for instance:

They end up being loaded as constants that you can reference.

lemmih commented 2 months ago

Yeah, I used include_dir! and wrote some wrapper code to serve those files.