Demo showing a basic Rails 5.1.0 app with React using the webpacker gem. Based on this article by @gauravtiwari
Steps:
- run
rails new webpacker-example-app --webpack=react
- Alternative: run
rails new webpacker-example-app
rails webpacker:install
rails webpacker:install:react
- Optional: run
rails g controller pages index
to create an index view for our hello_react component
-
run
bin/webpack-dev-server
to start webpack compilation -
Add
<%= javascript_pack_tag 'application'
to application.html.erb -
Add
<%= javascript_pack_tag 'hello_react'
to index.html.erb or any other page. -
Go to localhost:3000/pages/index.html