Let’s create a rails application along with ReactJS and other node modules.
Install Node.js and NPM (on MAC)
I assume MAC already have
npm (node package manager) comes with node by default. Alternatively, we can use
yarn (my preferance also
rails prefer it :p).
Ah, it’s neecessary to use version manager for
node. Yes, there is node version manager
nvm. Follow these steps to install it.
Let’s create a Rails application
webpack. Good News is,
rails officially included
webpack inside rails (from
5.1) with name
Now, create a rails application including
webpack with react (only for rails
or just add
gem 'webpacker' to
Gemfile and bundle it. And then run
Yeah sit tight, it does a lot of work :smile:
So, this rails application is ready with
react. Yeah, inside
react files (
.jsx) will remain.
.jsx, this type of code will render
react-dom in Rails fornt-end:
hello-world-div react-dom will be rendered.
And finally, for continuous pre-compiling run
webpack using this command (your prefered configuration):
And to add a node module use:
Pretty cool and easy, right? Cheers!