-
-
Notifications
You must be signed in to change notification settings - Fork 730
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
asset integration with elements + hotreloading #1955
Comments
APIIt might make sense to build this functionality into the rsx macro. We could use some of the information from It would be nice to map paths in dioxus web for a few different reasons:
mg currently supports all three of the above. We could expand: rsx! {
style { src: "./local_src.css" }
} into: rsx! {
style { src: mg!("./local_src.css") }
} Then we could reuse the existing bundling and optimization system. Hot reloadingIf we map asset paths and include a hash of the last modified date in the output path (like mg currently does), then we don't need anything special in the renderers for hot reloading. We could just update the source attribute when we notice that asset was changed. (There is also some overlap with the asset hot reloading api we expose to plugins in #1673) DX concernsIf this is built into the elements, it could be surprising that using a dynamic source or const value breaks the asset. The current template optimizations we do only improve performance if we have enough information to know an attribute/element is static at compile time, this new API would change behavior. If I change this code in dioxus web: style { src: "./local_src.css" } To this code with a constant: const MY_CSS_FILE: &str = "./local_src.css";
rsx! {
style { src: MY_CSS_FILE }
} Then the path to my local file no longer works. We could make sources accept a special type that is either const (inline or with the mg! macro) or dynamic with a special constructor: // This can be used with any String-like value which may be generated at runtime, but paths are not mapped and optimizations are not applied. You also need to manually add it to the list of bundled and watched assets
const MY_CSS_FILE: Asset = Asset::raw("./local_src.css");
rsx! {
style { src: MY_CSS_FILE }
}
// This works exactly like an inline string. It is automatically optimized, bundled and watched
// This API is nice if I want to store a list of assets like in a carousel while still linking to assets in a cross platform way and optimizing assets
const MY_CSS_FILE: Asset = mg!(file("./local_src.css"));
rsx! {
style { src: MY_CSS_FILE }
}
// The macro converts literal strings for attributes that accept assets into the static optimized version of the asset
rsx! {
style { src: "./local_src.css" }
} |
Specific Demand
I would love to see that somehow our
style
elements could integrate with bundling to allow hotreloading of CSS just by adding the relevant style tag:This is definitely doable but would require some plumbing. If we could somehow extend regular elements, the asset configuration of images, videos, and more could be done at compile time:
This is definitely feasible but would require some brainstorming in a good design + architecture.
If I had to design this, I would experiment with dumping all template data into the target dir and then the
dx
CLI would watch this for updates and run its own asset system against it.Ideally the asset system would be integrated into the
LaunchBuilder
- so any library that uses the launch builder could easily tap into assets just by implementing the regular mutation API. We'd have to expose some way of driving updates to the asset (maybe by updating an associated data-dioxus-hash attribute).The text was updated successfully, but these errors were encountered: