3

I have this script that runs when running Rails 7 with esbuild build, this is inside package.json in the scripts attribute, it's ran from the Rails procfile:

esbuild app/javascript/*.* --bundle --sourcemap --outdir=app/assets/builds

however I often find myself with errors with file configs, however the website I'm working on does not show any errors because the last build was there and working.

I'd like the webpage to bread if there's an esbuild error.

I was wondering how do I run another script that deleted the previous build, I tried this:

esbuild app/javascript/*.* --bundle --sourcemap --outdir=app/assets/builds --onFailure \"rm ./app/assets/builds/application.js && rm ./app/assets/builds/application.js.map\"

However it's saying onFailure is an invalid flag.

Is there a way to make esbuild show the error on the site, or just show any error if the build fails?

CafeHey
  • 5,699
  • 19
  • 82
  • 145
  • Depending on your use case you could use bash's logical OR condition which short-curcuits. Essentially running: `esbuild [--args] || echo "esbuild did not run successful"`. Do note that this will also fail (i.e. call the echo) if any issue occurs, not directly related to build issues (i.e. if esbuild is missing on your system or your command arguments were not correct) – posixpascal Sep 16 '22 at 08:01

0 Answers0