Live-reload generated site using Trunk

finchie
Apr 23, 2024, 7:38 AM
PVUQYWZEPOUY4VAFP77EFHZ4I6DJ6XXEUT7PNMBUQUIRG54E2P4QC

Dependencies

Change contents

  • replacement in src/visualize/mod.rs at line 37
    [2.1043][2.1043:1098]()
    renderer.save(&chart, "/tmp/chart.html").unwrap();
    [2.1043]
    [2.1098]
    renderer.save(&chart, "target/dist/index.html").unwrap();
  • file addition: Trunk.toml (----------)
    [5.1]
    # Trunk is used to live-reload the generated output
    # This configuration specifies the following steps:
    # 1. Serve the generated `target/dist/index.html`
    # 2. Wait for a file in `src` to change
    # 3. Execute `cargo run` to update the visualization
    # 4. Live-reload the webpage automatically
    [[hooks]]
    stage = "pre_build"
    command = "cargo"
    command_arguments = ["run"]
    [build]
    # TODO: Trunk will not start if this file does not exist, so have to manually bootstrap:
    # mkdir --parents target/dist/; cargo run
    # Tracked at https://github.com/trunk-rs/trunk/issues/172
    target = "target/dist/index.html"
    dist = "target/dist"
    [watch]
    watch = ["src/"]
    [serve]
    open = true