phoenixframework / esbuild

An installer for esbuild
MIT License
271 stars 38 forks source link

watch multiple locations in multi-phoenix umbrella application #34

Closed ericdude4 closed 2 years ago

ericdude4 commented 2 years ago

Not exactly an issue, so apologize for using this as a forum for a question - but I came to the issues section of this repo to find an answer, so perhaps other will as well.

Is it possible to configure :esbuild such that it will watch assets in multiple phoenix umbrella apps? Right now I'm defining multiple profiles such like:

config :esbuild,
  version: "0.12.18",
  app_one: [
    args:
      ~w(js/app.js --bundle --target=es2016 --outdir=../priv/static/assets --external:/fonts/* --external:/images/*),
    cd: Path.expand("../apps/app_one_web/assets", __DIR__),
    env: %{"NODE_PATH" => Path.expand("../deps", __DIR__)}
  ],
  app_two: [
    args:
      ~w(js/app.js --bundle --target=es2016 --outdir=../priv/static/assets --external:/fonts/* --external:/images/*),
    cd: Path.expand("../apps/app_two_web/assets", __DIR__),
    env: %{"NODE_PATH" => Path.expand("../deps", __DIR__)}
  ]

Then I am adding to my Endpoint configurations like:

config :app_one_web, AppOneWeb.Endpoint,
  # ...
  watchers: [
    esbuild: {Esbuild, :install_and_run, [:app_one, ~w(--sourcemap=inline --watch)]}
  ]

config :app_two_web, AppTwoWeb.Endpoint,
  # ...
  watchers: [
    esbuild: {Esbuild, :install_and_run, [:app_two, ~w(--sourcemap=inline --watch)]}
  ]

Running mix phx.server doesn't seem to start these watchers.

It's also worth noting that the Endpoint configs for both of these Phoenix applications have server: false since I am using :master_proxy to route requests to the appropriate endpoint in my umbrella application.

josevalim commented 2 years ago

You could send a pull request to Phoenix that adds :force_watchers which we can fallback to before we read config[:server], this way you can have server: false and force the watchers to run. If you want to use a single executable, then that's more a question for esbuild CLI. :) Closing this for now, feel free to PR phoenix. :)

ericdude4 commented 2 years ago

@josevalim I've opened the :force_watchers PR for when you have a moment. https://github.com/phoenixframework/phoenix/pull/4614