Skip to content

Instantly share code, notes, and snippets.

@kvzb
Created August 14, 2024 21:18
Show Gist options
  • Save kvzb/e5232d00723152832c7d43e3a349584e to your computer and use it in GitHub Desktop.
Save kvzb/e5232d00723152832c7d43e3a349584e to your computer and use it in GitHub Desktop.
Solo Rails #3: Front-end stack config.
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"),
minify: true,
};
const build = async (config) => {
const result = await Bun.build(config);
if (!result.success) {
if (process.argv.includes('--watch')) {
console.error("Build failed");
for (const message of result.logs) {
console.error(message);
}
return;
} else {
throw new AggregateError(result.logs, "Build failed");
}
}
};
(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);
}
})();
{
"name": "app",
"private": "true",
"dependencies": {
},
"devDependencies": {
},
"scripts": {
"build:css": "postcss ./app/assets/stylesheets/application.postcss.css -o ./app/assets/builds/application.css",
"build": "bun bun.config.js",
"outdated": "bunx npm-check-updates"
}
}
web: bin/rails server -p 3000
css: bun run build:css --watch
js: bun run build --watch
jobs: bundle exec good_job start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment