phoenixframework / phoenix_live_reload

Provides live-reload functionality for Phoenix
MIT License
315 stars 90 forks source link

Need for live reload outside of project root #164

Closed lawik closed 2 months ago

lawik commented 2 months ago

I am trying to improve the use of Phoenix tooling in Nerves projects that use a fairly common, often recommended, project layout called a poncho project.

This issue makes it clear that this is not supported, currently: https://github.com/phoenixframework/phoenix_live_reload/issues/127

A poncho-project is not quite an umbrella, but rather a set of projects considering each other dependencies:

kiosk_ui                  # our Phoenix project
kiosk_firmware     # our Nerves firmware project

kiosk_firmware depends on kiosk_ui through a {:kiosk_ui, path: "../kiosk_ui"} dependency.

All the necessary config is duplicated in kiosk_firmware and a lot of it adapted to point at files in kiosk_ui.

My kiosk project has an example. Just export MIX_TARGET=host and then you should be able to start kiosk_firmware like a regular Phoenix project.

It would be very useful to be able to do this. Umbrellas seem to have a lot of annoyances that the poncho doesn't. And for most projects it is nice to keep the Phoenix and Nerves projects apart.

It is possible to just run kiosk_ui but you lose a lot of the Nerves functionality which you might be developing against.

lawik commented 2 months ago

Actually solved in Phoenix:

config :kiosk_ui, KioskUiWeb.Endpoint,
  code_reloader: true,
  watchers: [
    esbuild: {Esbuild, :install_and_run, [:kiosk_ui, ~w(--sourcemap=inline --watch)]},
    tailwind: {Tailwind, :install_and_run, [:kiosk_ui, ~w(--watch)]}
  ],
  reloadable_apps: [:kiosk_ui]

config :phoenix_live_reload, dirs: [Path.expand("../kiosk_ui")]

config :kiosk_ui, KioskUiWeb.Endpoint,
  live_reload: [
    patterns: [
      ~r"priv/static/(?!uploads/).*(js|css|png|jpeg|jpg|gif|svg)$",
      ~r"priv/gettext/.*(po)$",
      ~r"lib/kiosk_ui_web/(controllers|live|components)/.*(ex|heex)$"
    ]
  ]

I think that's all of it.