<?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: Yip</title>
    <description>The latest articles on DEV Community by Yip (@coderific).</description>
    <link>https://dev.to/coderific</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%2F375467%2Fe873b746-52e6-4760-9891-4a5f006e8bb0.png</url>
      <title>DEV Community: Yip</title>
      <link>https://dev.to/coderific</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/coderific"/>
    <language>en</language>
    <item>
      <title>Using Parcel to create a React app</title>
      <dc:creator>Yip</dc:creator>
      <pubDate>Thu, 28 Jan 2021 13:07:37 +0000</pubDate>
      <link>https://dev.to/coderific/using-parcel-to-create-a-react-app-3cp0</link>
      <guid>https://dev.to/coderific/using-parcel-to-create-a-react-app-3cp0</guid>
      <description>&lt;p&gt;&lt;a href="https://parceljs.org"&gt;Parcel&lt;/a&gt; is a fast application bundler that allows you to create a more lean and lightweight setup of React (as well as other types of app) with zero configuration.  Over the last few months it has become my personal favourite method of creating a React app.  &lt;/p&gt;

&lt;p&gt;Let's create a bare-bones "Hello, world!" app using Parcel. &lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1) Create a new folder for your project
&lt;/h2&gt;

&lt;p&gt;Yeah, probably able to do that bit yourself&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2) Create a &lt;code&gt;package.json&lt;/code&gt; file
&lt;/h2&gt;

&lt;p&gt;In Terminal, &lt;code&gt;cd&lt;/code&gt; into your new folder and run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="err"&gt;npm&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;init&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;-y&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will automatically create a new fresh &lt;code&gt;package.json&lt;/code&gt; file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3) Installing Parcel, React and ReactDOM
&lt;/h2&gt;

&lt;p&gt;First let's install the Parcel bundler as a dev-dependancy.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="err"&gt;npm&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;i&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;-D&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;parcel-bundler&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and now install react, and react-dom.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i react react-dom
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 4) Adding a "start" script
&lt;/h2&gt;

&lt;p&gt;Open the &lt;code&gt;package.json&lt;/code&gt; file, and in the "scripts" section add the following "start" script.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"start"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"parcel index.html --open"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 5) Create the initial &lt;code&gt;index.html&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;In your chosen text editor create a new file called &lt;code&gt;index.html&lt;/code&gt; and create the standard HTML boilerplate.  &lt;/p&gt;

&lt;p&gt;Now we need to add a couple of things.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A &lt;code&gt;div&lt;/code&gt; where React will be inserted&lt;/li&gt;
&lt;li&gt;A &lt;code&gt;script&lt;/code&gt; which will act as the javaScript entry point&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In the &lt;code&gt;body&lt;/code&gt; of the &lt;code&gt;index.html&lt;/code&gt;, add&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"root"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"./index.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 6) Create the &lt;code&gt;index.js&lt;/code&gt; file
&lt;/h2&gt;

&lt;p&gt;Now create the &lt;code&gt;index.js&lt;/code&gt; so we can add React&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;render&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-dom&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Hello&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;world&lt;/span&gt;&lt;span class="o"&gt;!&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&amp;gt;, document.getElementById&lt;/span&gt;&lt;span class="se"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;'root'&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="err"&gt;)
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 7) Check everything works
&lt;/h2&gt;

&lt;p&gt;From terminal run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="err"&gt;npm&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;start&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Yes, that is it. Parcel will now do its magic and you will be sat in front of a fully functional React app. &lt;/p&gt;

&lt;h2&gt;
  
  
  Next Steps
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Create a base component (&lt;code&gt;App.js&lt;/code&gt; or similar), import it into &lt;code&gt;index.js&lt;/code&gt; and replace the paragraph tags and 'Hello, world!' with your base component&lt;/li&gt;
&lt;li&gt;Have a read of the &lt;a href="https://parceljs.org/getting_started.html"&gt;parcel documentation&lt;/a&gt; to understand how awesome Parcel is and what Parcel supports right out of the box.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>react</category>
      <category>beginners</category>
      <category>codenewbie</category>
      <category>100daysofcode</category>
    </item>
  </channel>
</rss>
