<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Rifki Fauzi</title>
    <description>The latest articles on DEV Community by Rifki Fauzi (@kubido).</description>
    <link>https://dev.to/kubido</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F108572%2Fad1e5422-0366-433c-b9e5-b67ce0a613da.png</url>
      <title>DEV Community: Rifki Fauzi</title>
      <link>https://dev.to/kubido</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kubido"/>
    <language>en</language>
    <item>
      <title>Upgrading old Rails 4.0 to Rails 6 with webpacker and React.js</title>
      <dc:creator>Rifki Fauzi</dc:creator>
      <pubDate>Wed, 03 Jun 2020 04:11:37 +0000</pubDate>
      <link>https://dev.to/kubido/upgrading-old-rails-4-0-to-rails-6-with-webpacker-and-react-js-10n6</link>
      <guid>https://dev.to/kubido/upgrading-old-rails-4-0-to-rails-6-with-webpacker-and-react-js-10n6</guid>
      <description>&lt;p&gt;It has been a while since I worked with ruby on rails… for the past couple of years, my main focus programming language is javascript. Node.js in the backend, and React on the frontend. so let’s start how we update our old rails app into the latest Rails app with React.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Upgrading Rails
&lt;/h2&gt;

&lt;p&gt;update your rails version inside Gemfile:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gem 'rails', '~&amp;gt; 6.0'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;and run bundle update rails&lt;/p&gt;
&lt;h2&gt;
  
  
  2. Setup Webpacker
&lt;/h2&gt;

&lt;p&gt;In your Gemfile&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Gemfile
gem 'webpacker', '~&amp;gt; 5.x'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;then run:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;bundle &amp;amp;&amp;amp; bundle exec rails webpacker:install&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Once your webpacker is setup. you are ready to put the bundle pack, you can say a pack is the entry point of your main js file. so all the js file required by rails views should be put inside &lt;code&gt;packs&lt;/code&gt; folder. and put inside your views &lt;code&gt;/layouts/application.html.erb&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;%= javascript_pack_tag 'application' %&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;by default, this will refer to /app/javascript/packs/application.js, you can change this path inside webpacker.yml by changing the source_entry_path&lt;/p&gt;
&lt;h2&gt;
  
  
  3. Setup React with Webpacker
&lt;/h2&gt;

&lt;p&gt;initialize react application with webpacker:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rails webpacker:install:react
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;it will install all related dependency using &lt;a href="https://yarnpkg.com"&gt;&lt;code&gt;yarn&lt;/code&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  4. Build your React Component
&lt;/h2&gt;

&lt;p&gt;I prefer to mount all my component into a single div, so I put empty div inside my &lt;code&gt;/layouts/application.html.erb&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div id="root"&amp;gt;&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;then inside my &lt;code&gt;packs/application.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;Done, and you ready to go build your React app inside Ruby on rails application&lt;/p&gt;

</description>
      <category>rails</category>
      <category>react</category>
      <category>webpacker</category>
      <category>reactonrubyonrails</category>
    </item>
  </channel>
</rss>
