dioxus icon indicating copy to clipboard operation
dioxus copied to clipboard

Allow specifying type for `web.resource` scripts in config

Open jmetz opened this issue 2 years ago • 2 comments

Specific Demand

At the moment the scripts section of the config allows specifying only the src values of script to inject.

It would be great to also be able to (optionally) specify the type (and other attributes?). My particular use-case is "module" type scripts.

Implement Suggestion

Guess we would need to allow more complex entries in the scripts parts of the config rather than just PathBufs: https://github.com/DioxusLabs/dioxus/blob/a3e6d0adcaee49495db5c324dbf9f20d5ec529ed/packages/cli/src/config.rs#L178-L182

to be injected here : https://github.com/DioxusLabs/dioxus/blob/a3e6d0adcaee49495db5c324dbf9f20d5ec529ed/packages/cli/src/builder.rs#L477-L483

jmetz avatar Nov 03 '23 18:11 jmetz

This would be a great addition! We need a way to set the type of script to include. We could make a new struct that handles the script with path and options. As long as that struct implements serialize and deserialize, it will work with the toml format.

In the longer term, it could make sense to include assets in rust code instead of in the Dioxus.toml (https://github.com/DioxusLabs/dioxus/issues/1283)

ealmloff avatar Nov 04 '23 02:11 ealmloff

Edit: This works only when using Dioxus Web, not in WebView (i.e. Desktop)

For a workaround following code seems to work, if you include it in your rsx! macro:

script {
    "type": "module",
    src: "https://cdn.example.com/your-module.js"
},

boris-schwarz avatar Jun 05 '24 21:06 boris-schwarz

We dropped the resource dir in favor of magnanis in 0.6, so this is no long relevant. You can use head::Link head::Title, head:: etc to specify the type of asset in your code.

Linked: #2635 #2642

jkelleyrtp avatar Jul 25 '24 01:07 jkelleyrtp