Skip to content

Instantly share code, notes, and snippets.

@stympy
Created July 1, 2024 16:32
Show Gist options
  • Save stympy/a99103a9f9a0c8d86f172e5747382dc8 to your computer and use it in GitHub Desktop.
Save stympy/a99103a9f9a0c8d86f172e5747382dc8 to your computer and use it in GitHub Desktop.
Config for esbuild in a Rails app
const path = require("path");
const esbuild = require("esbuild");
esbuild
.build({
entryPoints: ["application.js"],
bundle: true,
outdir: path.join(process.cwd(), "app/assets/builds"),
absWorkingDir: path.join(process.cwd(), "app/assets/packs"),
minify: process.env.RAILS_ENV == "production",
watch: process.argv.includes("--watch"),
sourcemap: true,
publicPath: "assets",
plugins: [
{
name: "buildOutput",
setup(build) {
let time = 0
build.onStart(() => { time = new Date().getTime()})
build.onEnd(({errors}) => {
if(errors.length) {
console.error(`failed with ${errors.length} errors`)
} else {
console.log(`Done in ${new Date().getTime() - time}ms`);
}
})
},
}
],
})
.then(() => console.log("⚡JS ready"))
.catch(() => process.exit(1));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment