Skip to content

Commit 23a529b

Browse files
Add hooks (#221)
* Add hooks example * Add image for tailwindcss yew example * Fix yew-tailwindcss example README.md * Add changelog entry
1 parent f47e83e commit 23a529b

File tree

23 files changed

+818
-10
lines changed

23 files changed

+818
-10
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ This changelog follows the patterns described here: https://keepachangelog.com/e
55
Subheadings to categorize changes are `added, changed, deprecated, removed, fixed, security`.
66

77
## Unreleased
8+
### added
9+
- Trunk now includes a hooks system. This improves many use cases where another build tool is needed alongside trunk, by allowing trunk to be configured to call them at various stages during the build pipeline. It is configured under `[[hooks]]` in `Trunk.toml`. More information can be found in the [Assets](https://trunkrs.dev/assets/) section of the docs.
810
- Added `trunk serve` autoreload triggered over websocket that reloads the page when a change is detected. The `--no-autoreload` flag disables this feature.
911

1012
## 0.13.1

Trunk.toml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,32 @@ backend = "http://localhost:9000/"
5757
# This proxy specifies only the backend, which is the only required field. In this example,
5858
# request URIs are not modified when proxied.
5959
backend = "http://localhost:9000/api/v2/"
60+
61+
## hooks
62+
# Hooks are optional, and default to `None`.
63+
# Hooks are executed as part of Trunk's main build pipeline, no matter how it is run.
64+
65+
[[hooks]]
66+
# This hook example shows all the current available fields. It will execute the equivalent of
67+
# typing "echo Hello Trunk!" right at the start of the build process (even before the HTML file
68+
# is read). By default, the command is spawned directly and no shell is used.
69+
stage = "pre_build"
70+
command = "echo"
71+
command_arguments = ["Hello", "Trunk!"]
72+
73+
[[hooks]]
74+
# This hook example shows running a command inside a shell. As a result, features such as variable
75+
# interpolation are available. This shows the TRUNK_STAGING_DIR environment variable, one of a set
76+
# of default variables that Trunk inserts into your hook's environment. Additionally, this hook
77+
# uses the build stage, meaning it executes in parallel with all of the existing asset pipelines.
78+
stage = "build"
79+
command = "sh"
80+
command_arguments = ["-c", "echo Staging directory: $TRUNK_STAGING_DIR"]
81+
82+
[[hooks]]
83+
# This hook example shows how command_arguments defaults to an empty list when absent. It also uses
84+
# the post_build stage, meaning it executes after the rest of the build is complete, just before
85+
# the staging directory is copied over the dist directory. This means that it has access to all
86+
# built assets, including the HTML file generated by trunk.
87+
stage = "post_build"
88+
command = "ls"

0 commit comments

Comments
 (0)