Created
May 17, 2025 21:18
-
-
Save yaodong/7373390763962af44003eed05562efe3 to your computer and use it in GitHub Desktop.
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
import path from 'path'; | |
import fs from 'fs'; | |
const config = { | |
sourcemap: "external", | |
entrypoints: ["app/javascript/application.js"], | |
outdir: path.join(process.cwd(), "app/assets/builds"), | |
}; | |
const build = async (config) => { | |
try { | |
await Bun.build(config); | |
} catch (error) { | |
if (process.argv.includes('--watch')) { | |
console.error(error.message); | |
console.error(error.errors); | |
} else { | |
throw new AggregateError(error.errors, error.message); | |
} | |
} | |
}; | |
(async () => { | |
await build(config); | |
if (process.argv.includes('--watch')) { | |
fs.watch(path.join(process.cwd(), "app/javascript"), { recursive: true }, (eventType, filename) => { | |
console.log(`File changed: ${filename}. Rebuilding...`); | |
build(config); | |
}); | |
} else { | |
process.exit(0); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment