nx-plugins icon indicating copy to clipboard operation
nx-plugins copied to clipboard

Support watch mode when running esbuild via js

Open oddnugget opened this issue 1 year ago • 3 comments

Currently, watch: true on this plugin states that it needs build({wach: true}) however watch: true is not an option when using the js api. instead one must do:

  esbuild
    .context(opts)
    .then((ctx) => {
      ctx.watch();
    })

however when doing it this way the plugin complains that watch is not true

oddnugget avatar Jul 02 '24 14:07 oddnugget

This is an incompatibility caused by esbuild version upgrade (>= 0.17). If the context API is used, the watch mode will be difficult to identify, and a new identification logic that does not rely on build.initialOptions.watch is required. See also https://github.com/evanw/esbuild/issues/2823

jerrychan7 avatar Aug 28 '24 10:08 jerrychan7

+1 for this to be fixed.

Could it just be a simple flag in the mean time or just don't do the check? I mean if we use our own method to set watch to true/false, is there any reason it needs to second guess what we want by checking esbuild config as well?

fridaystreet avatar Nov 07 '24 21:11 fridaystreet

FWIW, for now you can enable watching per asset pair using the assets.watch key, e.g.

copy({
    assets: {
      from: [`./src/foo/*`],
      to: [`./foo/*`],
      watch: true,
    },
  })

jesseditson avatar Nov 05 '25 18:11 jesseditson