excid3 / esbuild-rails

Esbuild Rails plugin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

esbuild 0.17 - Does not support `watch` as argument to `build`

davidwessman opened this issue · comments

https://github.com/evanw/esbuild/blob/main/CHANGELOG.md#0170

I cannot figure out how to rewrite the esbuild.config.js to match the new syntax.

I got

const path = require("path");
const rails = require("esbuild-rails");
const esbuild = require("esbuild");

esbuild.context({
  entryPoints: ["application.js"],
  bundle: true,
  outdir: path.join(process.cwd(), "app/assets/builds"),
  absWorkingDir: path.join(process.cwd(), "app/javascript"),
  plugins: [rails()],
}).then (context => {
  context.watch().then((context) => {
  })

  context.dispose();
})

But it will not watch, it will only run once.

I randomly saw this issue so I figured I'd write a comment. dispose() deletes the context so you're immediately deleting the context. You need to not delete the context if you want watch mode to persist. You only want to call dispose() if you need watch mode to stop for some reason.

I randomly saw this issue so I figured I'd write a comment. dispose() deletes the context so you're immediately deleting the context. You need to not delete the context if you want watch mode to persist. You only want to call dispose() if you need watch mode to stop for some reason.

That makes sense, and thank you for looking around and all the work you do on esbuild! 🙂

Yes, thanks for everything @evanw! esbuild has really improved our Rails development workflow. 💖

I just saw the updated example-commit, but the README still contains an old example.
Should the README just include a link instead?

Ah, now see that you removed the watch example completely from README. 🤦🏻
Thanks! 🙂

Yep! I also added an examples directory with a regular build, watch, and reload config all in one.

@evanw if you get a second, could you check out this example? I ran into an issue with 0.17 that esbuild cannot find application.js when we run context.rebuild(). Happens maybe 20% of the time. Adding a 20ms delay fixes it. Didn't have an issue with this in 0.16 or earlier.

https://github.com/excid3/esbuild-rails/blob/main/examples/esbuild.config.mjs#L77