Created
July 1, 2024 16:32
-
-
Save stympy/a99103a9f9a0c8d86f172e5747382dc8 to your computer and use it in GitHub Desktop.
Config for esbuild in a Rails app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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