Support passing custom profiles to cargo #295
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Checklist
site
content with pertinent info (may not always apply).Reasoning
Rust recently (since 1.56) added support for custom profiles. This is especially convenient in a workspace where for example frontend and backend live together in the same repo as 2 crates of a workspace.
If a crate is part of a workspace it can't define its own profile settings, thus there's only a single global
release
profile. But often you want different profile settings for server and frontend, the server optimized for speed, frontend for binary size. With this new feature, you can define a custom profile optimized for binary size and use it for the frontend only, while setting up the release profile for performance for every other crate.Description
This PR adds support for the cargo flag to Trunk, so you can configure which profile to use. Sadly, we have a few automatic settings that depend on the
release
flag and there is no proper solution when used with a profile.These spots are:
wasm-opt
.compressed
orexpanded
.Currently, this is solved by treating a custom profile the same way as the
release
flag, but I'm sure that isn't what everyone wants. For example, if someone creates a custom profile for debug purposes, they surely don't wantwasm-opt
to be run.Improvements
To solve this issue, it would be best to change Trunk to follow the profile style. Something like:
Trunk.toml
These would be in sync with cargo's profiles, thus activating as follows:
trunk build
ortrunk build --profile debug
->debug
trunk build --release
ortrunk build --profile release
->release
trunk build --profile minified
->minified
Also, for
wasm-opt
we can set the optimization level in the HTML file with<link data-trunk rel="rust" data-wasm-opt="z">
. We might either remove it or keep it and decide what takes precedence. I would personally go with removing it to make the configuration easier and avoid mistakes and surprises. If we decide to keep it, it probably makes sense to choose the HTML setting over Trunk.toml?Further details
I didn't update the changelog and other docs yet, as I feel we have to discuss a bit further about the profiles, and just wanted to get a bit of input on this idea. I believe adding profiles to Trunk directly is very beneficial but would break current setups. Therefore, I didn't add it yet until we make further decisions.