smoogipoo / osu-native

2 stars 2 forks source link

Generated sources in `_framework` directory are not bundler friendly #26

Open minetoblend opened 1 month ago

minetoblend commented 1 month ago

The generated dotnet.js in the _framework folder uses fetch calls with static paths to load the blazor.json file which the contains the required paths for all .wasm files. This makes it impossible for bundlers to pick up that these files are used, leading to the being excluded when building a project using the library.

From what I can tell, the correct bundler-friendly syntax to import assets would either be along the lines of:

import blazorBootJson from './blazor.boot.json?url'
...
await fetch(blazorBootJson)

or

await fetch(new URL('./blazor.boot.json', import.meta.url).href)

This is mostly an upstream issue, and looks like asp.net core will switch to rollup for bundling which should eventually fix this, however I think I could try to hack together a little vite plugin that'll rewrite the output a bit to make sure there are bundler-friendly references in to the generated files. The files are unfortunately minified, if there was a way to disable minification (or output source maps) that would make things a lot easier.

smoogipoo commented 1 month ago

Since that PR is merged, if it's a matter of using the .NET 9 preview SDK then I can look into doing that (I actually have an in-progress branch doing this already). The desktop native project is already built using both SDKs, though there's still some work to be done.

Anyway, I've compiled it with NET9 locally, can you check if these _framework files are bundler friendly?

_framework.zip

smoogipoo commented 1 month ago

Uh, sorry, this one (trimmed/minified):

_framework.zip

minetoblend commented 1 month ago

Hmm, I took a quick peek on the phone and it looks about the same as before, I'll have to take a closer look at home though

smoogipoo commented 1 month ago

For future reference, my work on this is here: https://github.com/smoogipoo/osu-native/tree/net9-toolset

I'll hold off on it for now because it doesn't really look like dotnet has addressed this issue themselves, from going through their issues/PRs...