a-h / templ

A language for writing HTML user interfaces in Go.
https://templ.guide/
MIT License
8.4k stars 277 forks source link

Watch flag for the `generate` command #983

Closed lorypelli closed 2 weeks ago

lorypelli commented 4 weeks ago

Add it or make the command automatically run on every go run

lorypelli commented 4 weeks ago

image I added this to the Makefile and now it works, but the thing I hate is that since it's a CLI command, I need to install it globally with go install github.com/a-h/templ/cmd/templ

pharrisee commented 4 weeks ago

No need to install (although I would), you can always use something like:

go run github.com/a-h/templ/cmd/templ@latest generate

If you use VSCode it may be worth you looking into devcontainers as you can encapsulate the dev environment per project.

https://containers.dev/ https://code.visualstudio.com/docs/devcontainers/containers

Here's an example devcontainer config you might use for dev purposes with templ:

{
        "name": "Go",
        "image": "mcr.microsoft.com/devcontainers/go:1-1-bookworm",
        "features": {
                "ghcr.io/jungaretti/features/make:1": {},
                "ghcr.io/devcontainers-extra/features/go-task:1": {},
                "ghcr.io/devcontainers-extra/features/temporal-cli:1": {}
        }
}

The config adds 3 'features' for templ, task and make and installs them ready to use within the container. The base container already contains go and you could easily add tailwind as another feature if required.

a-h commented 2 weeks ago

templ generate already has a --watch flag to watch for changes to templ files, and a --cmd flag to run afterwards.

Perhaps you could clarify what you're looking for?