Created
August 14, 2024 21:18
-
-
Save kvzb/e5232d00723152832c7d43e3a349584e to your computer and use it in GitHub Desktop.
Solo Rails #3: Front-end stack config.
This file contains 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"), | |
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); | |
} | |
})(); |
This file contains 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
{ | |
"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" | |
} | |
} |
This file contains 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
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