trunk-rs / trunk

Build, bundle & ship your Rust WASM application to the web.
https://trunkrs.dev/
Apache License 2.0
3.44k stars 251 forks source link

Feature Request: <link data-trunk> dependency on other <link data-trunk rel=rust> #878

Open LumaKernel opened 5 days ago

LumaKernel commented 5 days ago

Description

<link data-trunk> is fetching the data which is existing before building of Rust resources. If Rust compilation creates the assets like stylesheet (for example, this is done by stylers, which is static stylesheet generator), they are not correctly loaded by Trunk as non-existent file, or fetching old one which is made by the last build, which cause the version mismatch.

error from build pipeline

Caused by:
    0: error getting canonical path for "/the-proj-dir/target/stylers/main.css"
    1: No such file or directory (os error 2)

Stylers officially offers the way for this by adding following post_build script, but this is intended for <link rel=stylesheet> without data-trunk, which is not tracked by Trunk and loaded dynamically. It's problematic. Cache wouldn't be busted in local development/production, and optimization is not done by Trunk.

[[hooks]]
stage = "post_build"
command = "sh"
command_arguments = ["-c", "cp ./target/stylers/main.css $TRUNK_STAGING_DIR/"]

The full entrypoint html is like following:

<!DOCTYPE html>
<html>
  <head>
    <link data-trunk rel="rust" data-bin="leptos" />
    <link data-trunk rel="css" href="target/stylers/main.css" />
  </head>
  <body></body>
</html>

Expected feature

I want the feature to specify the dependency of them, or just wait all asset fetching after Rust resources' builds.

First idea would look like following:

<!DOCTYPE html>
<html>
  <head>
    <link data-trunk rel="rust" data-bin="leptos" id="main" />
    <link data-trunk rel="css" href="target/stylers/main.css" data-depends="main" />
  </head>
  <body></body>
</html>

Not sure how can we treat that if there're multiple dependencies.

Second idea is simple, but not extensible.

ctron commented 4 days ago

I agree that having a chain of internal build dependencies makes sense. However, this will be a bigger task, as trunk currently has no idea, other than the hard coded order of running processors.

I think it makes sense adding this to a more long-term roadmap. And I think the idea to represent this with the link element makes sense. I'd definitely like to consider this for a post 0.21.x release.