-
Using Rails 7 and React (via esbuild)
-
Structure
- All React code lives in app/javascript
npm run build
runsbuild.js
which defines the main entryapp/javascript/application.js
(which then imports everything for the build)- see
routes.rb
for:- path to React (an empty
app/view/home/index.erb
with js set in the headers oflayouts/application.html.erb
) - path to Rails API (just the one
app/controllers/nyt_books_controller
that fetches and cleans the data)
- path to React (an empty
-
To run locally:
bin/dev
ornpm 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]