Skip to content

Instantly share code, notes, and snippets.

@yaodong
Created May 17, 2025 21:18
Show Gist options
  • Save yaodong/7373390763962af44003eed05562efe3 to your computer and use it in GitHub Desktop.
Save yaodong/7373390763962af44003eed05562efe3 to your computer and use it in GitHub Desktop.
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