-
Using Rails 7 and React (via esbuild)
-
Structure
- All React code lives in app/javascript
npm run buildrunsbuild.jswhich defines the main entryapp/javascript/application.js(which then imports everything for the build)- see
routes.rbfor:- path to React (an empty
app/view/home/index.erbwith js set in the headers oflayouts/application.html.erb) - path to Rails API (just the one
app/controllers/nyt_books_controllerthat fetches and cleans the data)
- path to React (an empty
-
To run locally:
bin/devornpm run build && rails s -
Thank you DigitalOcean for this tutorial: [https://www.digitalocean.com/community/tutorials/how-to-set-up-a-ruby-on-rails-v7-project-with-a-react-frontend-on-ubuntu-20-04]