In Yew, how is it possible to locate index.html in a static/ directory?

458 views Asked by At

I have something going wrong with my Yew App. I try to locate index.html inside the static/ and, I have this in my Trunk.toml file:

[build]
target = "./static/index.html"

And ultimately, my app compiles with a warning which is "no rust project found":

[DrShahinstein@Arch ui]$ trunk serve
2023-07-21T16:49:26.731162Z  INFO  starting build
2023-07-21T16:49:26.732863Z  INFO spawning asset pipelines
2023-07-21T16:49:26.825023Z  WARN no rust project found
2023-07-21T16:49:26.825263Z  INFO applying new distribution
2023-07-21T16:49:26.825922Z  INFO ✅ success
2023-07-21T16:49:26.826155Z  INFO  serving static assets at -> /
2023-07-21T16:49:26.826182Z  INFO  server listening at http://127.0.0.1:8080

Before I tried to locate index.html in static/ directory, I had been able to see my little counter component (which is the same in the docs). However, when I arrange static folder for my index.html and try serving my app, there's nothing but an empty page. There's literally nothing informative on the web nor Chatgpt. Anyone know about that issue?

This is how my project structure looks like:

- rust-todo/
 - server/
 - ui/
  - src/
   - main.rs # which is the same in the docs
  - static/
   - index.html
  -Trunk.toml
  ...

The only thing that I could discover was to configurate a Trunk.toml file for the app but it remains insufficient as there are still things going awkward. I've spent at least 3 hours juggling on the internet searching about this issue but there's literally nothing helpful. As a result, my yew app compiles with an annoying line of warning and doesn't even show up my counter component when I try to put index.html anywhere else other than the root of the project.

1

There are 1 answers

0
Chaong On BEST ANSWER

I think this is a bug in Trunk. Trunk looks for Cargo.toml in the same directory as index.html, which causes the warning "no rust project found".

The solution is to specify the path to Cargo.toml in index.html. For example

 <link data-trunk rel="rust" href="../Cargo.toml">

For more information, see this issue: https://github.com/trunk-rs/trunk/issues/610.