<?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: Mark Hkr 😎</title>
    <description>The latest articles on DEV Community by Mark Hkr 😎 (@markhker).</description>
    <link>https://dev.to/markhker</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%2F141922%2F086bde32-5209-4f5c-aee1-38f6628e4068.jpg</url>
      <title>DEV Community: Mark Hkr 😎</title>
      <link>https://dev.to/markhker</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/markhker"/>
    <language>en</language>
    <item>
      <title>Upgrading to React 17 and Webpack 5</title>
      <dc:creator>Mark Hkr 😎</dc:creator>
      <pubDate>Mon, 26 Oct 2020 01:36:30 +0000</pubDate>
      <link>https://dev.to/markhker/upgrading-to-react-17-and-webpack-5-5bii</link>
      <guid>https://dev.to/markhker/upgrading-to-react-17-and-webpack-5-5bii</guid>
      <description>&lt;h1&gt;
  
  
  &lt;strong&gt;Breaking Changes!!&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;In &lt;a href="https://dev.to/markhker/react-app-from-scratch-10n8"&gt;my last post&lt;/a&gt; I showed you how to create a React app from scratch with Webpack. Since then, these libraries have been updated with new features and interesting alternatives.&lt;/p&gt;

&lt;p&gt;At least in Webpack…&lt;/p&gt;

&lt;p&gt;This week was released a new version of React and I couldn't be more happy about it. As they mention in &lt;a href="https://reactjs.org/blog/2020/10/20/react-v17.html"&gt;this blog post&lt;/a&gt; this new version does not contain any new features for us, the developers. Instead, they focused this release on features that enable gradual updates.&lt;/p&gt;

&lt;p&gt;And, the release of Webpack 5 which has many new features.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;The I'm more of a code type of person&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://github.com/markhker/react-from-scratch/tree/upgrade"&gt;The github repo&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;Upgrading Packages&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;First, lets update react and react dom:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn upgrade react@17.0.1 react-dom@17.0.1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since React 17 we can use the &lt;a href="https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html"&gt;new jsx transform&lt;/a&gt;, so we will need to upgrade our babel tools and install a new plugin:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn upgrade &lt;span class="nt"&gt;-D&lt;/span&gt; @babel/&lt;span class="o"&gt;{&lt;/span&gt;core,preset-&lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="nb"&gt;env&lt;/span&gt;,react&lt;span class="o"&gt;}}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn add &lt;span class="nt"&gt;-D&lt;/span&gt; @babel/plugin-transform-react-jsx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next we will need to update our .babelrc file to look like this:&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="p"&gt;{&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;presets&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@babel/preset-env&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@babel/preset-react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;runtime&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;automatic&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
    &lt;span class="p"&gt;}]&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Starting from Babel 8, "automatic" will be the default runtime for the plugins.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;Removing Unused React Imports&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;The new JSX transform automatically imports the necessary functions and React is no longer needed to be in the scope.&lt;/p&gt;

&lt;p&gt;Inside our 'src/index.js' we can get rid of the &lt;code&gt;import React&lt;/code&gt; statement:&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;ReactDOM&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&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="nx"&gt;there&lt;/span&gt;&lt;span class="o"&gt;!!&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;
&lt;span class="nx"&gt;ReactDOM&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;root&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that's it, when you create a new React component you don't need to &lt;code&gt;import React&lt;/code&gt; anymore.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;Upgrading Webpack&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;Webpack 5 has many breaking changes, so we will need to upgrade our dependencies and our code.&lt;/p&gt;

&lt;p&gt;Let's start by upgrading webpack itself and the cli tool:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn upgrade webpack&lt;span class="o"&gt;{&lt;/span&gt;,-cli&lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="nt"&gt;--latest&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Change the "start" script in your package.json file:&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;...&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&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;"webpack serve --mode='development'"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it.&lt;/p&gt;

&lt;p&gt;This is still a pretty much basic (but powerful) configuration, we will need to add more tools to create a full fledged React app.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://twitter.com/intent/tweet?url=https%3A%2F%2Fmarlom.dev%2Fupgrade-to-react-17-and-webpack-5"&gt;Share this on Twitter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>webpack</category>
      <category>babel</category>
      <category>javascript</category>
    </item>
    <item>
      <title>React App From Scratch</title>
      <dc:creator>Mark Hkr 😎</dc:creator>
      <pubDate>Sat, 26 Sep 2020 01:01:35 +0000</pubDate>
      <link>https://dev.to/markhker/react-app-from-scratch-10n8</link>
      <guid>https://dev.to/markhker/react-app-from-scratch-10n8</guid>
      <description>&lt;p&gt;There are several ways of starting a React App, the most popular and easy being &lt;a href="https://github.com/facebook/create-react-app"&gt;create-react-app&lt;/a&gt;, and &lt;a href="https://www.gatsbyjs.org/"&gt;Gatsby&lt;/a&gt; for static pages. These tools let you build a React application with no extra configuration, but at a cost:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Usually you wouldn't know what is happening behind the scenes.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And if you want a more fledged application you will need to tweak almost every part of the configuration.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;The I'm more of a code type of person&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/markhker/react-from-scratch/tree/basic"&gt;The github repo&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Start Simple&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In this tutorial I assume you have basic knowledge of JavaScript, bash commands, git, node and npm/&lt;a href="https://yarnpkg.com/"&gt;yarn&lt;/a&gt; installed. I will use yarn for all the examples, but you could change them for npm commands.&lt;/p&gt;

&lt;p&gt;Let's start with a simple configuration, including only the React package, Babel for transformations and Webpack to handle the bundle.&lt;/p&gt;

&lt;p&gt;To get started let's create a new directory for your React Application and move in:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;react-from-scratch &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;cd&lt;/span&gt; &lt;span class="nv"&gt;$\&lt;/span&gt;_
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Initialize your project and create a minimal folder structure, use the -y option in yarn to skip the init questions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn init &lt;span class="nt"&gt;-y&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Install dependencies&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;With the next commands you will install the dependencies and the development-only dependencies needed to start developing your React app:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn add react react-dom
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn add &lt;span class="nt"&gt;-D&lt;/span&gt; @babel/&lt;span class="o"&gt;{&lt;/span&gt;core,preset-&lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="nb"&gt;env&lt;/span&gt;,react&lt;span class="o"&gt;}}&lt;/span&gt; babel-loader webpack&lt;span class="o"&gt;{&lt;/span&gt;,-cli,-dev-server&lt;span class="o"&gt;}&lt;/span&gt; html-webpack-plugin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above command we are using brace expansion as shortcut to install npm packages with similar names at once, the same as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn add &lt;span class="nt"&gt;-D&lt;/span&gt; @babel/core @babel/preset-env @babel/preset-react babel-loader webpack webpack-cli webpack-dev-server html-webpack-plugin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With React, we will use modern ECMAScript features that older browsers don't understand, that's why we need to transform our code. This transformation is "transpilling" and it's executed through a webpack loader. A webpack loader is a translator so webpack can understand what type of code you're using e.g: ECMAScript, css, html, etc.&lt;/p&gt;

&lt;p&gt;Each package serves a purpose:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;react:&lt;/strong&gt; Well, you know what React is. (Do you?)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;react-dom:&lt;/strong&gt; For rendering React components into the DOM&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;webpack:&lt;/strong&gt; It's the bundler, that packages our code for production use&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;webpack-dev-server:&lt;/strong&gt; It's a simple web server that provides us live reloading&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;html-webpack-plugin:&lt;/strong&gt; Simplifies creating and using HTML files to serve our webpack bundles in the browser&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;@babel/core:&lt;/strong&gt; The main package used to convert ECMAScript 2015+ into backwards compatible code&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;@babel-preset-env:&lt;/strong&gt; A predefined configuration for converting modern JavaScript into more compatible code&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;@babel-preset-react:&lt;/strong&gt; Configuration and plugins for transforming JSX and other React-specific code to JavaScript&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;babel-loader:&lt;/strong&gt; The translator webpack will use to bundle our code&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;Setup your files&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;First we will need "support" files, or configuration files. The ones that will let our application know what it is and how it needs to be interpreted.&lt;/p&gt;

&lt;p&gt;First our babel configuration file (.babelrc):&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="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"presets"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s2"&gt;"@babel/preset-env"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s2"&gt;"@babel/preset-react"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We include our earlier installed presets to let know babel what we want it to do with our code. We are telling babel: "I will write some JavaScript from the future and some React components. And I want you to transform it to a backwards compatible version of JavaScript. Thank You"&lt;/p&gt;

&lt;p&gt;You need an HTML index file to load the JavaScript on the browser (index.html):&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="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"UTF-8"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width, initial-scale=1.0"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;React From Scratch&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="c"&gt;&amp;lt;!-- Prompt a message in the browser if users disabled JS --&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;noscript&amp;gt;&lt;/span&gt;Your browser does not support JavaScript!&lt;span class="nt"&gt;&amp;lt;/noscript&amp;gt;&lt;/span&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;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will provide an entry point for webpack, to attach our main JavaScript bundle to the DOM.&lt;/p&gt;

&lt;p&gt;Next we will write (or copy/paste) our webpack config file (webpack.config.js):&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;HtmlWebpackPlugin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;html-webpack-plugin&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;module&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;rules&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;test&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\.(&lt;/span&gt;&lt;span class="sr"&gt;js|jsx&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="sr"&gt;$/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;exclude&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sr"&gt;/node_modules/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;use&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="na"&gt;loader&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;babel-loader&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;plugins&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;HtmlWebpackPlugin&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;template&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;index.html&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="p"&gt;}),&lt;/span&gt;
  &lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The minimal configuration we need to transform our React app. Here we are telling webpack to pipe every file with the .js or .jsx extension through the babel-loader translator. And pointing to the main html file we want to use as a template.&lt;/p&gt;

&lt;p&gt;You can know more of webpack on &lt;a href="https://webpack.js.org/concepts/"&gt;their documentation.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You need a React entry file, you will call this index.js (src/index.js):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&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="nx"&gt;ReactDOM&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Hello there!!&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="nx"&gt;ReactDOM&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;(&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;App&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;,&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;root&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the entry point of your application, the root. From here you will be calling the rest of the code necessary for you app. And must be inside your src folder.&lt;/p&gt;

&lt;p&gt;And we will need to add a few scripts to our package.json file:&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="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&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;"webpack-dev-server --open --mode development"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"build"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"webpack --mode production"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then you can run &lt;code&gt;yarn start&lt;/code&gt; to start the development server and see the changes on your browser. This should open a tab on your default browser, if not, go to &lt;code&gt;http://localhost:8080&lt;/code&gt; to see your application.&lt;/p&gt;

&lt;p&gt;When you want to build a production package you run &lt;code&gt;yarn build&lt;/code&gt;. And you can see you final static assets on the &lt;code&gt;dist&lt;/code&gt; folder.&lt;/p&gt;

&lt;p&gt;With this you have the basic configuration to start developing you app. But one of the main benefits of starting a React project from scratch is that you can expand your configuration to increase its features.&lt;/p&gt;

&lt;p&gt;In the next post I'll explain how to add tried methods for a more professional application, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Advanced Composing Configuration&lt;/li&gt;
&lt;li&gt;Tree Shaking&lt;/li&gt;
&lt;li&gt;Minification and Optimization&lt;/li&gt;
&lt;li&gt;Source Mapping&lt;/li&gt;
&lt;li&gt;Linting and Prettifying&lt;/li&gt;
&lt;li&gt;Import Aliases&lt;/li&gt;
&lt;li&gt;Environment Variables&lt;/li&gt;
&lt;li&gt;Bundle Analyzing&lt;/li&gt;
&lt;li&gt;Hot Module Replacement&lt;/li&gt;
&lt;li&gt;Code Splitting&lt;/li&gt;
&lt;li&gt;Lazy Loading&lt;/li&gt;
&lt;li&gt;Basic Routing&lt;/li&gt;
&lt;li&gt;CSS in JS&lt;/li&gt;
&lt;li&gt;Assets loading&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://twitter.com/intent/tweet?url=https%3A%2F%2Fmarlom.dev%2Freact-app-from-scratch"&gt;Share this on Twitter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>webpack</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
