Melkeydev / go-blueprint

Go-blueprint allows users to spin up a quick Go project using a popular framework
https://docs.go-blueprint.dev/
MIT License
5.89k stars 333 forks source link

[Bug] Using Air and templ (hot/live-reloading doesn't work) #171

Closed Saveljeffjonatan closed 10 months ago

Saveljeffjonatan commented 10 months ago

What is the problem?

So I went with a go-blueprint using Chi and then standard setup using templ files. When I try to execute anything with Air my Go code reruns but either it crashes my servers (it stops going to run step), doesn't reload my templ files or keeps reloading out of control.

Operating System

MacOs

Architecture Version (x86, x64, arm, etc)

m1

Steps to reproduce

  1. go-blueprint create --advanced
  2. [x] chi
  3. [x] postgres
  4. [x] HTMX/templ files

Relevant log output

No response

Saveljeffjonatan commented 10 months ago

Something that seems to have fixed it, need to test it further but it worked as expected (if I manually refreshed the page) -> Changed .air.toml settings:

Key changes: cmd = "templ generate && go build -o ./tmp/main ./cmd/api" excluded_regex = ["_test.go", ".*_templ.go"] included_ext = ["go", "tpl", "tmpl", "templ", "html"]

root = "."
testdata_dir = "testdata"
tmp_dir = "tmp"

[build]
  args_bin = []
  bin = "./tmp/main"
  cmd = "templ generate && go build -o ./tmp/main ./cmd/api"
  delay = 1000
  exclude_dir = ["assets", "tmp", "vendor", "testdata"]
  exclude_file = []
  exclude_regex = ["_test.go", ".*_templ.go"]
  exclude_unchanged = false
  follow_symlink = false
  full_bin = ""
  include_dir = []
  include_ext = ["go", "tpl", "tmpl", "templ", "html"]
  include_file = []
  kill_delay = "0s"
  log = "build-errors.log"
  poll = false
  poll_interval = 0
  post_cmd = []
  pre_cmd = []
  rerun = false
  rerun_delay = 500
  send_interrupt = false
  stop_on_error = false

[color]
  app = ""
  build = "yellow"
  main = "magenta"
  runner = "green"
  watcher = "cyan"

[log]
  main_only = false
  time = false

[misc]
  clean_on_exit = false

[screen]
  clear_on_rebuild = false
  keep_scroll = true