a-h / templ

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

Watch flag for the `generate` command #983

Open lorypelli opened 2 hours ago

lorypelli commented 2 hours ago

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

lorypelli commented 2 hours 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 1 hour 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.