<?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: Maximo Martinez Soria</title>
    <description>The latest articles on DEV Community by Maximo Martinez Soria (@mmartinezsoria).</description>
    <link>https://dev.to/mmartinezsoria</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%2F236197%2Ff4f48279-ceb7-4af5-a1e5-a81bdd2cfadf.png</url>
      <title>DEV Community: Maximo Martinez Soria</title>
      <link>https://dev.to/mmartinezsoria</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mmartinezsoria"/>
    <language>en</language>
    <item>
      <title>Not everything is an object in JavaScript</title>
      <dc:creator>Maximo Martinez Soria</dc:creator>
      <pubDate>Fri, 24 Jul 2020 20:56:41 +0000</pubDate>
      <link>https://dev.to/mmartinezsoria/not-everything-is-an-object-in-javascript-46c9</link>
      <guid>https://dev.to/mmartinezsoria/not-everything-is-an-object-in-javascript-46c9</guid>
      <description>&lt;p&gt;"Everything in JavaScript is an object" is a well known sentence that almost everyone have heard at least once. However, this is not correct at all.&lt;/p&gt;

&lt;p&gt;In order to understand the differences between JavaScript datatypes, let's split them into two categories: &lt;strong&gt;Primitive datatypes&lt;/strong&gt; and &lt;strong&gt;Objects&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Primitive datatypes
&lt;/h2&gt;

&lt;p&gt;Primitive datatypes are those things that aren't objects. They are just what they are.&lt;/p&gt;

&lt;p&gt;For example: a string, it's a string and that's it.&lt;/p&gt;

&lt;p&gt;There are seven primitive datatypes in the language so far:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;String:&lt;/strong&gt; usually texts, but it can be everything you insert into double or single quotes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Number:&lt;/strong&gt; quite self-descriptive. It can only save 64 bits.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;BigInt:&lt;/strong&gt; same as Number, but it can save more than 64 bits.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Boolean:&lt;/strong&gt; only two possible values: &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Symbol:&lt;/strong&gt; it's an anonymous and unique value.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;undefined:&lt;/strong&gt; it's used by JavaScript to say that something doesn't have a value.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;null:&lt;/strong&gt; it's an invalid or nonexistent value. You can use it to initialize a variable which is going to has an object later.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Null, is a special one, because if you check its type with the &lt;code&gt;typeof&lt;/code&gt; operator, it's going to return &lt;code&gt;object&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;All of these have two things in common:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;They are immutable:&lt;/strong&gt; they cannot change. If you change them, you are just creating a new one.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;They don't have any methods or properties.&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If primitive datatypes don't have methods or properties, then, why can we use &lt;code&gt;string.toUppercase()&lt;/code&gt;? or any of the other methods that primitives have.&lt;/p&gt;

&lt;p&gt;This is possible because some of the primitives have their equivalent in the objects world. That means that we use &lt;code&gt;string&lt;/code&gt; &lt;strong&gt;type&lt;/strong&gt; when we declare a string, but we use &lt;code&gt;String&lt;/code&gt; &lt;strong&gt;object&lt;/strong&gt; when we use some of the methods or properties on it.&lt;/p&gt;

&lt;p&gt;Another question that you may have is how or when is the string converted to an object.&lt;/p&gt;

&lt;p&gt;This is related with how the engine works. &lt;/p&gt;

&lt;p&gt;The engine, "wraps" the primitive datatype into its equivalent object.&lt;/p&gt;

&lt;p&gt;Finally, why don't keep it simple and just use objects everywhere? Smart question. We'll talk about it later. Let's discuss objects first.&lt;/p&gt;

&lt;h2&gt;
  
  
  Objects
&lt;/h2&gt;

&lt;p&gt;Everything else, such as functions or arrays, are objects.&lt;/p&gt;

&lt;p&gt;We've already talked about differences between objects and primitives. But there is one more. This one is quite more advanced, but it's also important in order to have a good understanding of how JavaScript actually works.&lt;/p&gt;

&lt;h2&gt;
  
  
  Memory
&lt;/h2&gt;

&lt;p&gt;Let's go back to that question about why we use primitives instead of having everything as an object.&lt;/p&gt;

&lt;p&gt;The answer is: because of how memory is handled.&lt;/p&gt;

&lt;p&gt;JavaScript uses two kinds of memories: Memory Heap and Memory Stack.&lt;/p&gt;

&lt;p&gt;Memory Stack, is where primitives are saved. This memory is smaller, but it's faster than Memory Heap. On the other hand, Memory Heap is bigger, but slower.&lt;/p&gt;

&lt;p&gt;So what JavaScript does is that it saves primitives and a reference to objects into the Memory Stack and saves the complete object into the Memory Heap.&lt;/p&gt;

&lt;p&gt;That's why we cannot copy objects that easy in JavaScript.&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;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;string&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;primitive&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;array&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;object&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;objCopy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;
&lt;span class="nx"&gt;objCopy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;primitive&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// {string: "primitive", array: "object", number: "primitive"}&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;objCopy&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// {string: "primitive", array: "object", number: "primitive"}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Give it a shot in the console and you'll see it.&lt;/p&gt;

&lt;p&gt;Since we are just copying a reference, both variables point to the same object.&lt;/p&gt;

&lt;p&gt;To avoid this behavior, you can use the spread operator.&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;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;string&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;primitive&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;array&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;object&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;objCopy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;objCopy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;primitive&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// {string: "primitive", array: "object"}&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;objCopy&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// {string: "primitive", array: "object", number: "primitive"}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>100daysofcode</category>
    </item>
    <item>
      <title>Why you should create your own Webpack configuration for React and how to do it</title>
      <dc:creator>Maximo Martinez Soria</dc:creator>
      <pubDate>Thu, 16 Jul 2020 20:08:33 +0000</pubDate>
      <link>https://dev.to/mmartinezsoria/why-you-should-create-your-own-webpack-configuration-for-react-and-how-to-do-it-51le</link>
      <guid>https://dev.to/mmartinezsoria/why-you-should-create-your-own-webpack-configuration-for-react-and-how-to-do-it-51le</guid>
      <description>&lt;p&gt;We all know &lt;code&gt;create-react-app&lt;/code&gt; and how easily we can get a React project configuration done. However, when you need some more project-specific stuff, you would definitely like to know how to change or add things.&lt;/p&gt;

&lt;p&gt;On the other hand, it's always a good idea to understand what's happening under the hood.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This is the second part of &lt;a href="https://dev.to/let-s-create-a-webpack-configuration-from-scratch"&gt;Let's create a Webpack configuration from scratch&lt;/a&gt; and I'll be using the files created on that post. So go and check it out before continue reading or just clone the &lt;a href="https://github.com/maximomartinezsoria/webpack-boilerplate" rel="noopener noreferrer"&gt;repo&lt;/a&gt; if you have a good understanding of how Webpack works.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here you have the repository of this post: &lt;a href="https://github.com/maximomartinezsoria/react-webpack-configuration" rel="noopener noreferrer"&gt;react-webpack-configuration&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Feel free to use it if you feel lost at some point.&lt;/p&gt;

&lt;h2&gt;
  
  
  Set Up
&lt;/h2&gt;

&lt;p&gt;First of all, if we are going to code a React app, we'll need React.&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="nv"&gt;$ &lt;/span&gt;npm i react react-dom
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also, let's create an entry point and a first component. Just to have something to test with.&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="c1"&gt;// src/index.js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./sass/index.scss&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="c1"&gt;// remember to import your styles in this file&lt;/span&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="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;App&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;./components/App&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="nf"&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="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#app&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;Let's create a hello world.&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="c1"&gt;// src/components/App.js&lt;/span&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="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;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Hello World!&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we are ready to go.&lt;/p&gt;

&lt;h2&gt;
  
  
  Babel for React
&lt;/h2&gt;

&lt;p&gt;We already have some babel configuration in our &lt;code&gt;.babelrc&lt;/code&gt; file. But it's not enough for React.&lt;/p&gt;

&lt;p&gt;We'll need one more package.&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="nv"&gt;$ &lt;/span&gt;npm i &lt;span class="nt"&gt;-D&lt;/span&gt; @babel/preset-react
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, just add it to the &lt;code&gt;presets&lt;/code&gt; array.&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="c1"&gt;// .babelrc&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;plugins&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/plugin-transform-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;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="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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Development
&lt;/h2&gt;

&lt;p&gt;As you know for the previous post, we're using two different files to take apart development and production configurations.&lt;/p&gt;

&lt;p&gt;We've done quite a good job last time. But we need to improve something for React.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hot Module Replacement
&lt;/h2&gt;

&lt;p&gt;Hot Module Replacement, allows us to refresh just one part of the browser every time we save a file. This makes the developer experience delightful.&lt;/p&gt;

&lt;p&gt;Let's do it.&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="c1"&gt;// webpack.dev.config.js&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;webpack&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&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;webpack&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="p"&gt;...&lt;/span&gt;
  &lt;span class="na"&gt;devServer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;contentBase&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;__dirname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dist&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="na"&gt;open&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;hot&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&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;webpack&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;HotModuleReplacementPlugin&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;webpack.HotModuleReplacementPlugin&lt;/code&gt; does quite all the job. Remember to import &lt;code&gt;webpack&lt;/code&gt; and set &lt;code&gt;hot&lt;/code&gt; to &lt;code&gt;true&lt;/code&gt; in &lt;code&gt;devServer&lt;/code&gt; object.&lt;/p&gt;

&lt;p&gt;Finally, we'll need to make a little refactor in the entry point.&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="c1"&gt;// src/index.js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./styles/index.scss&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;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="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;App&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;./components/App&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;renderApp&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&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="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#app&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="nf"&gt;renderApp&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="k"&gt;if &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;hot&lt;/span&gt;&lt;span class="p"&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;hot&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;accept&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./components/App&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;renderApp&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;Encapsulate react render function into a custom function and then tell &lt;code&gt;webpack&lt;/code&gt; to re-run that function every time we save the file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Production
&lt;/h2&gt;

&lt;p&gt;This is probably the worthiest part of making a custom configuration.&lt;/p&gt;

&lt;p&gt;You can really improve performance and user experience with the following technique. However, there are a lot of things you could add here.&lt;/p&gt;

&lt;h2&gt;
  
  
  Dynamic Link Library
&lt;/h2&gt;

&lt;p&gt;Dynamic link library is a set of libraries that hardly ever change. So we're going to pre-bundle them in order to avoid bundle them every time we run our build command. Also, the fact of having these libraries in a different file, will prevent the browser to download them over and over again.&lt;/p&gt;

&lt;p&gt;First, we need to create a new webpack file. Yes, another one. This one is so simple and it's usually called &lt;code&gt;webpack.dll.config.js&lt;/code&gt;.&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="c1"&gt;// webpack.dll.config.js&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&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;path&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;webpack&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&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;webpack&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;entry&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;modules&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="s1"&gt;react&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="s1"&gt;react-dom&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="na"&gt;output&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;__dirname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dist&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="na"&gt;filename&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;js/[name].dll.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;library&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;[name]&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="na"&gt;mode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;production&lt;/span&gt;&lt;span class="dl"&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;webpack&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DllPlugin&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
            &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;[name]&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;__dirname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;[name]-manifest.json&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You might be able to understand almost everything. But there are a couple of weird things...&lt;/p&gt;

&lt;p&gt;Why is the entry point receiving and array of strings? Well, those strings are the names of the libraries. And those libraries are the ones that we are compiling.&lt;/p&gt;

&lt;p&gt;In this case we're only using &lt;code&gt;react&lt;/code&gt; and &lt;code&gt;react-dom&lt;/code&gt; because it's a very simple example. But go ahead and install &lt;code&gt;react-router&lt;/code&gt;, &lt;code&gt;redux&lt;/code&gt; or any other library that you want and add them to the modules array.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Output&lt;/code&gt; and &lt;code&gt;mode&lt;/code&gt; are quite simple. We've been using them for a while and they don't have nothing new in this case.&lt;/p&gt;

&lt;p&gt;Finally, we are using a new plugin. It is part of the Webpack core and it help us creating a manifest. This manifest, is going to tell Webpack not to re-compile this libraries that we've already compiled.&lt;/p&gt;

&lt;p&gt;That next step, is the &lt;code&gt;build&lt;/code&gt; command and in order to make that happen, we need to add a plugin.&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="c1"&gt;// webpack.config.js&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;webpack&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&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;webpack&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="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="p"&gt;...&lt;/span&gt;
        &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;CleanWebpackPlugin&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;cleanOnceBeforeBuildPatterns&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="s1"&gt;**/main.*&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="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;webpack&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DllReferencePlugin&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;manifest&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&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;./modules-manifest.json&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="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;AddAssetHtmlPlugin&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;filepath&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;__dirname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dist/js/*.dll.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
      &lt;span class="na"&gt;outputPath&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;publicPath&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;http://localhost:3001/js/&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;This one is again part of the Webpack core and it reads the output of &lt;code&gt;DllPlugin&lt;/code&gt; and prevents Webpack from compiling our libraries again.&lt;/p&gt;

&lt;p&gt;On the other hand, I've changed the pattern of &lt;code&gt;CleanWebpackPlugin&lt;/code&gt; to avoid deleting our &lt;code&gt;modules.dll.js&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;Finally, we're using a new plugin which links our &lt;code&gt;modules.dll.js&lt;/code&gt; to our html file automatically.&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="nv"&gt;$ &lt;/span&gt;npm i &lt;span class="nt"&gt;-D&lt;/span&gt; add-asset-html-webpack-plugin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  React code and Webpack Docs
&lt;/h2&gt;

&lt;p&gt;We've finished. But if you want to continue improving your user and development experience, I leave you a couple of things to look at.&lt;/p&gt;

&lt;p&gt;You can make a lot of difference in user experience if you take care of your React code. These are a couple of React techniques related with performance:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://reactjs.org/docs/react-api.html#reactlazy" rel="noopener noreferrer"&gt;Lazy load components&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://reactjs.org/docs/react-api.html#suspense" rel="noopener noreferrer"&gt;Suspense component&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;PWA&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;PWAs could be complicated at the beginning but they're really useful and allow you to have awesome features like offline support, notifications, offline analytics, shortcut icon from smartphones and computers, etc.&lt;/p&gt;

&lt;p&gt;Also, don't forget to check out Webpack's documentation. It's plenty of interesting options to improve either your experience or the users one.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Let's create a Webpack configuration from scratch</title>
      <dc:creator>Maximo Martinez Soria</dc:creator>
      <pubDate>Fri, 19 Jun 2020 16:41:50 +0000</pubDate>
      <link>https://dev.to/mmartinezsoria/let-s-create-a-webpack-configuration-from-scratch-1jml</link>
      <guid>https://dev.to/mmartinezsoria/let-s-create-a-webpack-configuration-from-scratch-1jml</guid>
      <description>&lt;p&gt;Even though It's not that difficult, webpack could be so intimidating.&lt;/p&gt;

&lt;p&gt;We just need to understand a couple of things.&lt;/p&gt;

&lt;p&gt;At the end of the post you will be able to fully understand how to write a &lt;code&gt;webpack.config.js&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;This is the full repo: &lt;a href="https://github.com/maximomartinezsoria/webpack-boilerplate" rel="noopener noreferrer"&gt;https://github.com/maximomartinezsoria/webpack-boilerplate&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Feel free to check it out if you feel lost at any point.&lt;/p&gt;

&lt;p&gt;Let's get started.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup
&lt;/h2&gt;

&lt;p&gt;First of all, we'll need to create a new folder and initialize git and npm.&lt;/p&gt;

&lt;p&gt;We'll also create a &lt;code&gt;src&lt;/code&gt; folder with a javascript file where our code is going to live.&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="c"&gt;# create a new folder and move into it&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;webpack-boilerplate
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;webpack-boilerplate

&lt;span class="c"&gt;# Initialize git and npm&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git init
&lt;span class="nv"&gt;$ &lt;/span&gt;npm init

&lt;span class="c"&gt;# create src folder, move into and create a file&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;src
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;src
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;touch &lt;/span&gt;index.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, we'll install &lt;code&gt;webpack&lt;/code&gt; and &lt;code&gt;webpack-cli&lt;/code&gt;. The first one, is the core library and the other will help us interact with webpack.&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="c"&gt;# i: install&lt;/span&gt;
&lt;span class="c"&gt;# -D: development dependencies&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;npm i &lt;span class="nt"&gt;-D&lt;/span&gt; webpack webpack-cli
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, let's create a configuration file at the same level of &lt;code&gt;package.json&lt;/code&gt;.&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="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;touch &lt;/span&gt;webpack.config.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should finish with somthing like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;- webpack-boilerplate
  - node_modules
    - ....
  - src
    - index.js
  - package.json
  - package.lock.json
  - webpack.config.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Getting into Webpack
&lt;/h2&gt;

&lt;p&gt;Let's work a little bit in &lt;code&gt;webpack.config.js&lt;/code&gt; file.&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="c1"&gt;// webpack.config.js&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&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;path&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;entry&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;__dirname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;src/index.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="na"&gt;output&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;__dirname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dist&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="na"&gt;filename&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;js/[name].js&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;This is a node file, so we are using commonjs instead of es6 import / export syntax.&lt;/p&gt;

&lt;p&gt;Entry, is where Webpack is going to look for the code.&lt;/p&gt;

&lt;p&gt;From now on, if you want a code to pass through Webpack, you'll need to import it in that file.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;CSS, preprocessors, and other sort of files could be imported as well. Just need the proper loader.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Output, is where Webpack is going to drop the resultant files.&lt;/p&gt;

&lt;p&gt;Notice that we are using a placeholder. This one will be replaced with the name of the file by Webpack.&lt;/p&gt;

&lt;h3&gt;
  
  
  Giving it a shot
&lt;/h3&gt;

&lt;p&gt;We need to create some commands in order to start using webpack.&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="err"&gt;package.json&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="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;"dev"&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"&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;As simple as that.&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="nv"&gt;$ &lt;/span&gt;npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The command will throw you a warning message saying that you should specify the &lt;code&gt;mode&lt;/code&gt; option.&lt;/p&gt;

&lt;p&gt;Go ahead and add a flag to the command specifying either &lt;code&gt;development&lt;/code&gt; or &lt;code&gt;production&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;We are going to create specific configurations for both modes later, so it's not important right now.&lt;/p&gt;

&lt;h2&gt;
  
  
  Loaders and Plugins
&lt;/h2&gt;

&lt;p&gt;Loaders allow us to load and pre-process different kinds of files, and plugins extends their possibilities.&lt;/p&gt;

&lt;p&gt;I know that this doesn't make much sense right now, but you'll understand soon. Let's go to the code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Handle HTML
&lt;/h2&gt;

&lt;p&gt;As you now know, the entry point and main file of the app is &lt;code&gt;index.js&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;As you also know, browsers need html files. At least one.&lt;/p&gt;

&lt;p&gt;The first thing that we are going to do, is to export a html file.&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="c1"&gt;// webpack.config.js&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&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;path&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&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="nf"&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;entry&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;__dirname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;src/index.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="na"&gt;output&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;__dirname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dist&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="na"&gt;filename&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;js/[name].js&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="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="nc"&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="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;__dirname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;public/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;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Remember to install the plugin.&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="nv"&gt;$ &lt;/span&gt;npm i &lt;span class="nt"&gt;-D&lt;/span&gt; html-webpack-plugin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Babel for modern JavaScript
&lt;/h2&gt;

&lt;p&gt;Not all people use modern browsers. That's why we need Babel to transpile our modern JavaScript into ES5.&lt;/p&gt;

&lt;p&gt;First, we need to install some dependencies:&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="nv"&gt;$ &lt;/span&gt;npm i &lt;span class="nt"&gt;-D&lt;/span&gt; babel-loader @babel/core @babel/preset-env
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As I told you, loaders allow us to load different kinds of files.&lt;/p&gt;

&lt;p&gt;This time we have &lt;code&gt;babel-loader&lt;/code&gt;, which loads JavaScript files into &lt;code&gt;@babel-core&lt;/code&gt;, which transpiles our modern JavaScript into ES5 using the rules defined in &lt;code&gt;@babel/preset-env&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;After that little explanation, let's go to the code.&lt;/p&gt;

&lt;p&gt;In order to use a loader, we need to use the key &lt;code&gt;module&lt;/code&gt; and set an array of rules inside it.&lt;/p&gt;

&lt;p&gt;Each rule has some configurations. In this case we are using the followings:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;test: tells Webpack which kind of files is this rule for.&lt;/li&gt;
&lt;li&gt;use: which loader will be applied in this rule.&lt;/li&gt;
&lt;li&gt;exclude: we are excluding the &lt;code&gt;node_modules&lt;/code&gt; folder to improve performance.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// webpack.config.js&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="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$/&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&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="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="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="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;Ok. We are asking Webpack to use babel. Now we need to tell babel what to do.&lt;/p&gt;

&lt;p&gt;All babel configurations need to be set in a specific file called &lt;code&gt;.babelrc&lt;/code&gt; in the root folder.&lt;/p&gt;

&lt;p&gt;In addition to presets, we can use plugins to increase presets functionality.&lt;/p&gt;

&lt;p&gt;In this case, lets install &lt;code&gt;@babel-plugin-transform-runtime&lt;/code&gt;, which allows us to use async/await.&lt;/p&gt;

&lt;p&gt;We are also installing &lt;code&gt;@babel/runtime&lt;/code&gt;. It's needed by the plugin and it's highly recommended to install it as a production dependency.&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="nv"&gt;$ &lt;/span&gt;npm i &lt;span class="nt"&gt;-D&lt;/span&gt; @babel/plugin-transform-runtime
&lt;span class="nv"&gt;$ &lt;/span&gt;npm i @babel/runtime
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// .babelrc&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;plugins&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/plugin-transform-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;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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Styles
&lt;/h2&gt;

&lt;p&gt;Every website or app needs styles.&lt;/p&gt;

&lt;p&gt;As you already know, loaders allow us to import different kinds of files into webpack.&lt;/p&gt;

&lt;p&gt;Does that mean that we can import css into JavaScript? Yes, it does.&lt;/p&gt;

&lt;p&gt;It sounds weird and a little bit crazy, but importing css in JS is how we include our styles into the bundle.&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="nv"&gt;$ &lt;/span&gt;npm i &lt;span class="nt"&gt;-D&lt;/span&gt; style-loader css-loader
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Importing css into JavaScript is actually weird. That's why we need a couple of things.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;css-loader&lt;/code&gt; is the one who handle the importing, and &lt;code&gt;style-loader&lt;/code&gt; injects css in the html file that we've already generated with &lt;code&gt;HtmlWebpackPlugin&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If you want to use a preprocessor, you need one more loader to handle that file and the specific preprocessor library itself.&lt;/p&gt;

&lt;p&gt;SASS / SCSS&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="nv"&gt;$ &lt;/span&gt;npm i &lt;span class="nt"&gt;-D&lt;/span&gt; sass-loader node-sass
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;STYLUS&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="nv"&gt;$ &lt;/span&gt;npm i &lt;span class="nt"&gt;-D&lt;/span&gt; stylus-loader stylus
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;LESS&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="nv"&gt;$ &lt;/span&gt;npm i &lt;span class="nt"&gt;-D&lt;/span&gt; less-loader less
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code is quite similar than the last time. We are just adding more rules.&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="c1"&gt;// webpack.config.js&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="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&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;css$/&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;style-loader&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="s1"&gt;css-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;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;scss$/&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;style-loader&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="s1"&gt;css-loader&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="s1"&gt;sass-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="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;less$/&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;style-loader&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="s1"&gt;css-loader&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="s1"&gt;less-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="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;styl$/&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;style-loader&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="s1"&gt;css-loader&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="s1"&gt;stylus-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="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;Let's recap.&lt;/p&gt;

&lt;p&gt;First, we've used a specific loader for a preprocessor, which turns the code into css. Then, &lt;code&gt;css-loader&lt;/code&gt; handles that code and finally &lt;code&gt;style-loader&lt;/code&gt; injects css into html.&lt;/p&gt;

&lt;p&gt;Remember to import these files into your main JS file.&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="c1"&gt;// index.js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./index.css&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./index.scss&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./index.less&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./index.styl&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Images, videos and fonts
&lt;/h2&gt;

&lt;p&gt;In order to use images, videos or fonts in our css, we need to use a specific loader.&lt;/p&gt;

&lt;p&gt;In this case, we are using an object in the &lt;code&gt;use&lt;/code&gt; key. This allows us to use additional configurations like the output path.&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="nv"&gt;$ &lt;/span&gt;npm i &lt;span class="nt"&gt;-D&lt;/span&gt; file-loader
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// webpack.config.js&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="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&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="p"&gt;{&lt;/span&gt;
            &lt;span class="c1"&gt;// '?' means that 'e' is optional. So we can use jpg or jpeg&lt;/span&gt;
      &lt;span class="nl"&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;jpe&lt;/span&gt;&lt;span class="se"&gt;?&lt;/span&gt;&lt;span class="sr"&gt;g|png|gif|woff|eot|ttf|svg|mp4|webm$/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nx"&gt;use&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;loader&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;file-loader&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="nl"&gt;outputPath&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;assets/&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="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;h2&gt;
  
  
  Development vs Production
&lt;/h2&gt;

&lt;p&gt;We've already learned a lot about Webpack. We are able to use lots of files as well as modern Javascript and CSS preprocessors.&lt;/p&gt;

&lt;p&gt;But the real power of Webpack is to make a better developer experience in development mode and a better user experience in production mode. That's why we are going to make two different configurations from now on.&lt;/p&gt;

&lt;h2&gt;
  
  
  Development
&lt;/h2&gt;

&lt;p&gt;Let's create a new configuration file for development purposes.&lt;/p&gt;

&lt;p&gt;The standard name is usually &lt;code&gt;webpack.dev.config.js&lt;/code&gt;, but you can use anyone.&lt;/p&gt;

&lt;p&gt;We need all the things that we've done before. So I'm going to rename the file that I was using, as oposed to create a new one.&lt;/p&gt;

&lt;p&gt;Since we are working in development mode, let's get Webpack to know that, using the &lt;code&gt;mode&lt;/code&gt; key.&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="c1"&gt;//webpack.config.js&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;entry&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;__dirname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;src/index.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="na"&gt;output&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;__dirname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dist&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="na"&gt;filename&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;js/[name].js&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="na"&gt;mode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;development&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;It's also time to change our &lt;code&gt;package.json&lt;/code&gt; 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="err"&gt;//&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;package.json&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;"dev"&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 --config ./webpack.dev.config.js"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="err"&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;config&lt;/code&gt; option defines the path to the config file.&lt;/p&gt;

&lt;p&gt;Let's talk about &lt;code&gt;webpack-dev-server&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Development server
&lt;/h3&gt;

&lt;p&gt;The first and one of the most important things that a developer needs is a local server.&lt;/p&gt;

&lt;p&gt;That's what we use &lt;code&gt;webpack-dev-server&lt;/code&gt; for.&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="nv"&gt;$ &lt;/span&gt;npm i &lt;span class="nt"&gt;-D&lt;/span&gt; webpack-dev-server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We also need to write the configuration for the server.&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="c1"&gt;//webpack.config.js&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="p"&gt;...&lt;/span&gt;
  &lt;span class="na"&gt;mode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;development&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;devServer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;contentBase&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;__dirname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dist&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="na"&gt;open&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;contentBase&lt;/code&gt; defines the directory where is going to look for the files and &lt;code&gt;open&lt;/code&gt; in true, means that when we run the command Webpack is going to open a browser automatically.&lt;/p&gt;

&lt;p&gt;From now on, Webpack is going to create a new bundle every time you save a file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Production
&lt;/h2&gt;

&lt;p&gt;Our development configuration is done.&lt;/p&gt;

&lt;p&gt;But for a better user experience we can change some things for production.&lt;/p&gt;

&lt;p&gt;As we are going to change lots of things, let's create another file and make a new script. I'll call it &lt;code&gt;webpack.config.js&lt;/code&gt;.&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="err"&gt;package.json&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;"dev"&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 --config ./webpack.dev.config.js"&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"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="err"&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As long as you use the default name (&lt;code&gt;webpack.config.js&lt;/code&gt;), &lt;code&gt;config&lt;/code&gt; option is not required.&lt;/p&gt;

&lt;p&gt;We can reuse some options that we've already written, so my new file it's just a duplication from &lt;code&gt;webpack.dev.config.js&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Some important changes that we need before getting started are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;mode: set to &lt;code&gt;production&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;devServer: remove the entire object. We don't need a local server in production.&lt;/li&gt;
&lt;li&gt;output: is a good practice to use hash in production files in order to avoid cache problems.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="nx"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;__dirname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;src/index.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="nx"&gt;output&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;__dirname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dist&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="nx"&gt;filename&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;js/[name].[hash].js&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="nx"&gt;mode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;production&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we are ready to start.&lt;/p&gt;

&lt;h3&gt;
  
  
  Extracting styles
&lt;/h3&gt;

&lt;p&gt;The first difference between development and production is how styles are handled.&lt;/p&gt;

&lt;p&gt;In development, we inject the css in order to accelerate things. But in production we need a css file. That's why, we are using a new loader that will extract the css into a new file.&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="nv"&gt;$ &lt;/span&gt;npm i &lt;span class="nt"&gt;-D&lt;/span&gt; mini-css-extract-plugin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, is it a plugin or a loader? Actually, both. You'll see.&lt;/p&gt;

&lt;p&gt;We need to pass it as a plugin to define both the output &lt;code&gt;filename&lt;/code&gt; and the &lt;code&gt;chunkFilename&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;hash&lt;/code&gt; placeholder, allows us to avoid cache problems.&lt;/p&gt;

&lt;p&gt;We need to pass it as a loader also. And, as you can see, we are not using &lt;code&gt;style-loader&lt;/code&gt; any more.&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="c1"&gt;// webpack.config.js&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;MiniCSSExtractPlugin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&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;mini-css-extract-plugin&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="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;css$/&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="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="nx"&gt;MiniCSSExtractPlugin&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;loader&lt;/span&gt;
          &lt;span class="p"&gt;},&lt;/span&gt;
          &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;css-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;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;scss$/&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="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="nx"&gt;MiniCSSExtractPlugin&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;loader&lt;/span&gt;
          &lt;span class="p"&gt;},&lt;/span&gt;
          &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;css-loader&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="s1"&gt;sass-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="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;less$/&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="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="nx"&gt;MiniCSSExtractPlugin&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;loader&lt;/span&gt;
          &lt;span class="p"&gt;},&lt;/span&gt;
          &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;css-loader&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="s1"&gt;less-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="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;styl$/&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="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="nx"&gt;MiniCSSExtractPlugin&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;loader&lt;/span&gt;
          &lt;span class="p"&gt;},&lt;/span&gt;
          &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;css-loader&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="s1"&gt;stylus-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="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="p"&gt;...&lt;/span&gt;
    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;MiniCSSExtractPlugin&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;filename&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;css/[name].[hash].css&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;chunkFilename&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;css/[id].[hash].css&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;So, let's recall.&lt;/p&gt;

&lt;p&gt;We are using &lt;code&gt;css-loader&lt;/code&gt; or the specific loaders for preprocessors to allow importing those files into JavaScript. Then, we use &lt;code&gt;MiniCSSExtractPlugin&lt;/code&gt; to extract css and create a file with it. Finally, that new file will be linked to the html automatically.&lt;/p&gt;

&lt;h3&gt;
  
  
  Cleaning
&lt;/h3&gt;

&lt;p&gt;We are almost done. Let's add two more fixes.&lt;/p&gt;

&lt;p&gt;The first one is related with hashes. As you know, we are using hashes everywhere to avoid cache problems. But now we have a problem with hashes. It's a bug or a feature?&lt;/p&gt;

&lt;p&gt;The problem is that we are creating new files every time we run Webpack, but we are just using the last one. So, if you run a couple of times the command and see the &lt;code&gt;css&lt;/code&gt; or &lt;code&gt;js&lt;/code&gt; folder, you are going to find lots of garbage files.&lt;/p&gt;

&lt;p&gt;It would be great to erase all of those files before each run of Webpack. Let's do it.&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="nv"&gt;$ &lt;/span&gt;npm i &lt;span class="nt"&gt;-D&lt;/span&gt; clean-webpack-plugin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// webpack.config.js&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;CleanWebpackPlugin&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&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;clean-webpack-plugin&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="nx"&gt;plugins&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="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;CleanWebpackPlugin&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
          &lt;span class="na"&gt;cleanOnceBeforeBuildPatterns&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="s1"&gt;**/*&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That does exactly what we want. It cleans the whole &lt;code&gt;dist&lt;/code&gt; folder before each bundle creation.&lt;/p&gt;

&lt;p&gt;Note that you can modify the pattern (&lt;code&gt;**/*&lt;/code&gt;) to match just the things you want. This might be useful when you are using dll for example.&lt;/p&gt;

&lt;h3&gt;
  
  
  Minify CSS
&lt;/h3&gt;

&lt;p&gt;The second fix is that css is not being minified.&lt;/p&gt;

&lt;p&gt;Minification process removes all unnecessary spaces in the file so it becomes smaller.&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="nv"&gt;$ &lt;/span&gt;npm i &lt;span class="nt"&gt;-D&lt;/span&gt; optimize-css-assets-webpack-plugin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// webpack.config.js&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;OptimizeCSSAssetsPlugin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&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;optimize-css-assets-webpack-plugin&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="nx"&gt;output&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="nx"&gt;optimization&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;minimizer&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="nc"&gt;OptimizeCSSAssetsPlugin&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;optimization&lt;/code&gt; is a new key that we didn't use before. I recommend you to take a look at the docs to know more about this key.&lt;/p&gt;

&lt;h3&gt;
  
  
  The perfect configuration
&lt;/h3&gt;

&lt;p&gt;since this is a very general configuration, we're done.&lt;/p&gt;

&lt;p&gt;But this isn't the perfect Webpack configuration. Actually, that doesn't exists.&lt;/p&gt;

&lt;p&gt;Each project has its own configuration so you can do whatever you need.&lt;/p&gt;

&lt;p&gt;I'm preparing another example of &lt;a href="https://dev.to/why-you-should-create-your-own-webpack-configuration-for-react-and-how-to-do-it"&gt;Webpack configuration for React&lt;/a&gt;. Stay tuned.&lt;/p&gt;

</description>
      <category>webpack</category>
      <category>babel</category>
      <category>frontend</category>
    </item>
    <item>
      <title>HTTP Explained</title>
      <dc:creator>Maximo Martinez Soria</dc:creator>
      <pubDate>Thu, 30 Apr 2020 13:15:15 +0000</pubDate>
      <link>https://dev.to/mmartinezsoria/http-explained-4cb</link>
      <guid>https://dev.to/mmartinezsoria/http-explained-4cb</guid>
      <description>&lt;p&gt;HTTP stands for Hyper Text Transfer Protocol and is the one that specifies the rules on the communication between two computers through internet.&lt;/p&gt;

&lt;h2&gt;
  
  
  Verbs
&lt;/h2&gt;

&lt;p&gt;The verbs are actions that define what each request is about to do.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GET:&lt;/strong&gt; fetch data.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;HEAD:&lt;/strong&gt; get headers. It's like a GET request but without content.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;POST:&lt;/strong&gt; create information.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PUT / PATCH:&lt;/strong&gt; update information.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;DELETE:&lt;/strong&gt; delete information.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Verbs, allow us to have different responses for only one endpoint.&lt;/p&gt;

&lt;p&gt;We could create lots of endpoints for a resource or we can just use the main word and use the verbs.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;GET &lt;code&gt;/books&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;POST &lt;code&gt;/books&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;DELETE &lt;code&gt;/books&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Is better than:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;GET &lt;code&gt;/get-all-books&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;POST &lt;code&gt;/create-a-book&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;DELETE &lt;code&gt;/delete-book&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Status
&lt;/h2&gt;

&lt;p&gt;Every request is going to return a status code. Let's see which codes exist and why.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;1xx:&lt;/strong&gt; pending. Nothing happened yet.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;2xx:&lt;/strong&gt; success.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;3xx:&lt;/strong&gt; usually a redirect.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;4xx:&lt;/strong&gt; client-side errors.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;5xx:&lt;/strong&gt; server-side errors.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Common Status Codes
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;200:&lt;/strong&gt; everything is ok. Usually used in GET request.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;201:&lt;/strong&gt; everything is ok. Usually used in POST / PUT request.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;204:&lt;/strong&gt; usually used to say that a DELETE request was completed successfully. The resource was deleted.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;400:&lt;/strong&gt; bad request. Something is wrong in the request.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;401:&lt;/strong&gt; unauthorised. You need to specify credentials first.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;403:&lt;/strong&gt; forbidden. You don't have permissions over that resource even though you are authenticated.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;404:&lt;/strong&gt; not found. Resource doesn't exist.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;500:&lt;/strong&gt; internal server error. The request couldn't be processed.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>http</category>
      <category>ajax</category>
      <category>database</category>
      <category>api</category>
    </item>
    <item>
      <title>Mastering Git</title>
      <dc:creator>Maximo Martinez Soria</dc:creator>
      <pubDate>Wed, 29 Apr 2020 15:14:41 +0000</pubDate>
      <link>https://dev.to/mmartinezsoria/mastering-git-2i3j</link>
      <guid>https://dev.to/mmartinezsoria/mastering-git-2i3j</guid>
      <description>&lt;p&gt;Git is an atomic version control system that allows us to keep a very specific tracking of our code or whatever plain text documents you want.&lt;/p&gt;

&lt;p&gt;Awesome, but why should I use git?&lt;/p&gt;

&lt;p&gt;When you have some code and you need to change it, how do you save the last version?&lt;/p&gt;

&lt;p&gt;You might use something like this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;myCode.js&lt;/li&gt;
&lt;li&gt;myCode_v2.js&lt;/li&gt;
&lt;li&gt;myCode_v3.js&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Terrible!&lt;/p&gt;

&lt;p&gt;That horrible way of organization has a ton of problems:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Saves all the code again, when you only need the new changes.&lt;/li&gt;
&lt;li&gt;You can't go back easily.&lt;/li&gt;
&lt;li&gt;You can't track changes between versions.&lt;/li&gt;
&lt;li&gt;You can't work with others.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Git solve all these problems and many more. Let's take it a look.&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
Getting started

&lt;ul&gt;
&lt;li&gt;Installation&lt;/li&gt;
&lt;li&gt;Configuration&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

First steps

&lt;ul&gt;
&lt;li&gt;Tracking code&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Branches&lt;/li&gt;

&lt;li&gt;Take a look at the changes&lt;/li&gt;

&lt;li&gt;Go back to a previous version&lt;/li&gt;

&lt;li&gt;

Git WorkFlow

&lt;ul&gt;
&lt;li&gt;New features&lt;/li&gt;
&lt;li&gt;Fix&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

Save the repository in an online server

&lt;ul&gt;
&lt;li&gt;Asymmetric encryption&lt;/li&gt;
&lt;li&gt;Pulling and pushing code&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Gitignore&lt;/li&gt;

&lt;li&gt;Readme&lt;/li&gt;

&lt;li&gt;Tags&lt;/li&gt;

&lt;li&gt;Rebase&lt;/li&gt;

&lt;li&gt;Stash&lt;/li&gt;

&lt;li&gt;Removing files&lt;/li&gt;

&lt;li&gt;Git cherry-pick&lt;/li&gt;

&lt;li&gt;Amending commits&lt;/li&gt;

&lt;li&gt;Clone&lt;/li&gt;

&lt;li&gt;Git reflog&lt;/li&gt;

&lt;li&gt;Search&lt;/li&gt;

&lt;li&gt;Complete log&lt;/li&gt;

&lt;li&gt;Aliases&lt;/li&gt;

&lt;li&gt;Git is really big&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  Getting started
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Installation
&lt;/h3&gt;

&lt;p&gt;The installation is kind of different across operating systems. So we will take care of each one separately.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mac OS&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It's quite simple in mac. You only need to go to the &lt;a href="https://git-scm.com/" rel="noopener noreferrer"&gt;git page&lt;/a&gt;, download the .pkg installler, open it and follow the instructions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Windows&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Again, go to the &lt;a href="https://git-scm.com/" rel="noopener noreferrer"&gt;git page&lt;/a&gt;, download the .exe installer, open it, and follow the instructions.&lt;/p&gt;

&lt;p&gt;It should be configured by default, but doble check the settings in the installer. You need to install git bash and open ssl in order to get git to work.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Linux&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you are using linux, you might know more than me.&lt;/p&gt;

&lt;p&gt;First, it is a good practice to update and upgrade your package manager. Then, you can install git and you shouldn't have any problem.&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="c"&gt;# Example with apt-get, which is the package manager for ubuntu, debian and others distributions based on those.&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get update
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get upgrade
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get &lt;span class="nb"&gt;install &lt;/span&gt;git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Configuration
&lt;/h3&gt;

&lt;p&gt;Git works almost out of the box. The only thing that you need to do, is to tell it what's your name and email.&lt;/p&gt;

&lt;p&gt;From now on, we will use the terminal for everything.&lt;/p&gt;

&lt;p&gt;If you are a windows user, you might want to use git bash.&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="nv"&gt;$ &lt;/span&gt;git config &lt;span class="nt"&gt;--global&lt;/span&gt; user.name &lt;span class="s2"&gt;"John Doe"&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git config &lt;span class="nt"&gt;--global&lt;/span&gt; user.email johndoe@example.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  First steps
&lt;/h2&gt;

&lt;p&gt;First of all, you need to initialize a git repository inside the folder that you want to track.&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="nv"&gt;$ &lt;/span&gt;git init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That command creates two different areas: staging and repository.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Staging&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It is a RAM space and a bridge between our non-tracked code and our repository.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Repository&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here is where our tracked code lives.&lt;/p&gt;

&lt;h3&gt;
  
  
  Tracking code
&lt;/h3&gt;

&lt;p&gt;When you have a new change in your code, and you want to track it, you need to add it to the staging area.&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="nv"&gt;$ &lt;/span&gt;git add webpack.config.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, you need to commit it to the repository with a descriptive message of what you have changed.&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="nv"&gt;$ &lt;/span&gt;git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Webpack configuration"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Branches
&lt;/h2&gt;

&lt;p&gt;Each branch is a different timeline of the code.&lt;/p&gt;

&lt;p&gt;Imagine you are working on frontend features and your partner on backend features. So you might have two branches: &lt;code&gt;frontend&lt;/code&gt; and &lt;code&gt;backend&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;By default, all your changes are going to a branch called &lt;code&gt;master&lt;/code&gt;.&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="c"&gt;# Create branch&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git checkout &lt;span class="nt"&gt;-b&lt;/span&gt; my-new-branch

&lt;span class="c"&gt;# Delete branch locally&lt;/span&gt;
&lt;span class="c"&gt;# -d will delete the branch only if it has already been pushed and merged with the remote branch.&lt;/span&gt;
&lt;span class="c"&gt;# Use -D instead if you want to force the branch to be deleted, even if it hasn't been pushed and merged yet.&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git checkout &lt;span class="nt"&gt;-d&lt;/span&gt; my-new-branch

&lt;span class="c"&gt;# Delete branch remotely&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git push origin &lt;span class="nt"&gt;--delete&lt;/span&gt; my-new-branch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Take a look at the changes
&lt;/h2&gt;

&lt;p&gt;You can see the whole history of a file with the command &lt;code&gt;show&lt;/code&gt;&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="nv"&gt;$ &lt;/span&gt;git show webpack.config.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you need to compare two specific commits you can do it with the command &lt;code&gt;diff&lt;/code&gt;&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="nv"&gt;$ &lt;/span&gt;git diff id-commit-x id-commit-y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In order to see the id of each commit, take a look at the log.&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="nv"&gt;$ &lt;/span&gt;git log
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Go back to a previous version
&lt;/h2&gt;

&lt;p&gt;Git gives us a couple of possibilities to go back in time.&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="c"&gt;# Go back but keep the added changes (This will erase all the changes made after the selected commit)&lt;/span&gt;
git reset id-commit &lt;span class="nt"&gt;--soft&lt;/span&gt;

&lt;span class="c"&gt;# Go back and erase added changes (This will erase all the changes made after the selected commit)&lt;/span&gt;
git reset id-commit &lt;span class="nt"&gt;--hard&lt;/span&gt;

&lt;span class="c"&gt;# Go back without erasing anything&lt;/span&gt;
git checkout id-commit

&lt;span class="c"&gt;# Go back a specific file&lt;/span&gt;
git checkout id-commit webpack.config.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Git WorkFlow
&lt;/h2&gt;

&lt;p&gt;Usually you are going to have two main branches: &lt;code&gt;master&lt;/code&gt; and &lt;code&gt;develop&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Master is where production code lives and develop where staging code does.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Remember that staging as environment isn’t the same as the git area called with the same name. As environment, it’s the middle place between production and local. Where we can test all the features as a user before doing the final deploy.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;On the other hand, the project could have hundreds of branches. Let’s see how we can deal with them in an organized way.&lt;/p&gt;

&lt;h3&gt;
  
  
  New features
&lt;/h3&gt;

&lt;p&gt;In order to keep things tidy and simple, you might want to create a new branch for each new feature that you need to code.&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="c"&gt;# Create a new branch called Feature/Auth&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git checkout &lt;span class="nt"&gt;-b&lt;/span&gt; Feature/Auth
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you’ve finished coding. You might want to see those changes in staging or production. Therefore you need to merge it with either &lt;code&gt;master,&lt;/code&gt; &lt;code&gt;develop&lt;/code&gt; or whatever the deploy branch is called in your project.&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="c"&gt;# Move to master&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git checkout master

&lt;span class="c"&gt;# Merge branch&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git merge Feature/Auth
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Fix
&lt;/h3&gt;

&lt;p&gt;We usually call &lt;code&gt;hotfix&lt;/code&gt; to the branch where we work on killing those bugs that need immediate attention.&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="nv"&gt;$ &lt;/span&gt;git checkout &lt;span class="nt"&gt;-b&lt;/span&gt; hotfix
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Again, once you are ready, merge changes with &lt;code&gt;master&lt;/code&gt; or &lt;code&gt;develop&lt;/code&gt;.&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="c"&gt;# Move to master&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git checkout master

&lt;span class="c"&gt;# Merge branch&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git merge hotfix
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Save the repository in an online server
&lt;/h2&gt;

&lt;p&gt;Let’s use &lt;a href="https://github.com/" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt; for this example, but keep in mind that it's sort of similar in the other platforms.&lt;/p&gt;

&lt;p&gt;I’m pretty sure that you can create an account on your own so let’s skip that step.&lt;/p&gt;

&lt;p&gt;Once you have an account, you need to create a repository clicking the green button and filling the required fields.&lt;/p&gt;

&lt;p&gt;Don’t worry about &lt;code&gt;.gitignore&lt;/code&gt; and &lt;code&gt;Readme&lt;/code&gt; files right now. We will get there soon.&lt;/p&gt;

&lt;h3&gt;
  
  
  Asymmetric encryption
&lt;/h3&gt;

&lt;p&gt;The best and most secure way to connect our computers with GitHub is with asymmetric encryption.&lt;/p&gt;

&lt;p&gt;In summary, you need two keys. A public one and a private one. Github will have your public key and your computer will have the private one.&lt;/p&gt;

&lt;p&gt;Every piece of information that travels across the internet will be encrypted with those keys. The only way to decode it, is having them both.&lt;/p&gt;

&lt;p&gt;Don’t worry about the difficult words right now. Just follow my steps in order to configure the whole environment.&lt;/p&gt;

&lt;p&gt;First of all, we will create a set of keys running a command in the terminal. Keys, will be called &lt;code&gt;id_rsa&lt;/code&gt;(Private) and &lt;code&gt;id_rsa.pub&lt;/code&gt;(Public) and will live in a new folder called &lt;code&gt;.ssh&lt;/code&gt; in the home of your computer. Also, the command will ask you a passphrase.&lt;/p&gt;

&lt;p&gt;Second of all, we will turn on the ssh keys agent, which is a process that do all the magic behind the scenes.&lt;/p&gt;

&lt;p&gt;Then, we will add our private key to that agent.&lt;/p&gt;

&lt;p&gt;Finally, we will add the public key on GitHub.&lt;/p&gt;

&lt;p&gt;Let’s do it.&lt;/p&gt;

&lt;p&gt;Things are kind of different in Mac. So let’s start with windows and linux:&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="c"&gt;# Generate ssh keys&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;ssh-keygen &lt;span class="nt"&gt;-t&lt;/span&gt; rsa &lt;span class="nt"&gt;-b&lt;/span&gt; 4096 &lt;span class="nt"&gt;-C&lt;/span&gt; &lt;span class="s2"&gt;"your@email.com"&lt;/span&gt;

&lt;span class="c"&gt;# Turn on ssh keys agent in your machine&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;eval&lt;/span&gt; &lt;span class="si"&gt;$(&lt;/span&gt;ssh-agent &lt;span class="nt"&gt;-s&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;

&lt;span class="c"&gt;# Add keys to the agent&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;ssh-add ~/.ssh/id_rsa
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now for mac users:&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="c"&gt;# Generate ssh keys&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;ssh-keygen &lt;span class="nt"&gt;-t&lt;/span&gt; rsa &lt;span class="nt"&gt;-b&lt;/span&gt; 4096 &lt;span class="nt"&gt;-C&lt;/span&gt; &lt;span class="s2"&gt;"your@email.com"&lt;/span&gt;

&lt;span class="c"&gt;# Turn on ssh keys agent in your machine&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;eval&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;ssh-agent &lt;span class="nt"&gt;-s&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

&lt;span class="c"&gt;# Create a config file inside the new .ssh folder&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;touch&lt;/span&gt; ~/.ssh/config

&lt;span class="c"&gt;# Add this content to the file.&lt;/span&gt;
Host &lt;span class="k"&gt;*&lt;/span&gt;
  AddKeysToAgent &lt;span class="nb"&gt;yes
  &lt;/span&gt;UseKeychain &lt;span class="nb"&gt;yes
  &lt;/span&gt;IdentityFile ~/.ssh/id_rsa

&lt;span class="c"&gt;# Add keys to the agent&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;ssh-add &lt;span class="nt"&gt;-K&lt;/span&gt; ~/.ssh/id_rsa
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, let’s add the public key on GitHub. First, copy the content of the public key. You can see it with &lt;code&gt;cat&lt;/code&gt;.&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="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cat&lt;/span&gt; ~/.ssh/id_rsa.pub
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is a specific menu for ssh into Github settings: &lt;a href="https://github.com/settings/keys" rel="noopener noreferrer"&gt;https://github.com/settings/keys&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Add a SSH key, put a title and paste your public key.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Title usually is the model of the computer.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Pulling and pushing code
&lt;/h3&gt;

&lt;p&gt;Going back to the terminal and in order to be able to push your committed changes, you have to set up an &lt;code&gt;origin&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;origin&lt;/code&gt;, tells git where to find the remote repository.&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="nv"&gt;$ &lt;/span&gt;git remote add origin https://github.com/maximomartinezsoria/app.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Remember to use your own repository’s link&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Finally, let’s push our code.&lt;/p&gt;

&lt;p&gt;The first time that you push a repository, you will need to tell git which origin to use.&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="nv"&gt;$ &lt;/span&gt;git push &lt;span class="nt"&gt;-u&lt;/span&gt; origin master
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From now on, you can keep it simple and just push without specifying anything.&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="nv"&gt;$ &lt;/span&gt;git push
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the repository already had some code before your first push, git would throw an error. You will need to allow git to merge the local history with the upcoming history.&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="nv"&gt;$ &lt;/span&gt;git pull origin master —allow-unrelated-histories
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you’re working with a team, they might push their code to the same repository.&lt;/p&gt;

&lt;p&gt;Next time that you need to push, git will tell you that there is code that you don’t have in your local repository. So you will need to pull it down.&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="c"&gt;# Download changes and merge them with local code automatically&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git pull
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Gitignore
&lt;/h2&gt;

&lt;p&gt;Sometimes, we need git to avoid tracking some files. For instance, we don’t want to track compiled files or &lt;code&gt;node_modules&lt;/code&gt; folder.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;.gitignore&lt;/code&gt;, is a file that tells git what not to track.&lt;/p&gt;

&lt;p&gt;Let’s create an example:&lt;/p&gt;

&lt;p&gt;Create a &lt;code&gt;.gitignore&lt;/code&gt; file in the root of your project and paste this content:&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="c"&gt;# env files and node_modules folder should not be tracked by git&lt;/span&gt;
.env
/node_modules
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, add everything with &lt;code&gt;git add -A&lt;/code&gt; and you'll notice that the files specified in &lt;code&gt;.gitignore&lt;/code&gt; are not included.&lt;/p&gt;

&lt;h2&gt;
  
  
  Readme
&lt;/h2&gt;

&lt;p&gt;Readme files are the ones that you can see at the end of each GitHub repository. They usually contain highlights of the documentation or how to set up the project.&lt;/p&gt;

&lt;p&gt;Here you can see an example: &lt;a href="https://github.com/maximomartinezsoria/minimalist-spa-router/blob/master/Readme.md" rel="noopener noreferrer"&gt;https://github.com/maximomartinezsoria/minimalist-spa-router/blob/master/Readme.md&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Tags
&lt;/h2&gt;

&lt;p&gt;Tags are what we usually use to save a reference in some part of the repository timeline.&lt;/p&gt;

&lt;p&gt;For instance is the way that we have to reference versions.&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="c"&gt;# Create a tag&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git tag &lt;span class="nt"&gt;-a&lt;/span&gt; tag-name commit-id

&lt;span class="c"&gt;# Delete a tag locally&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git tag &lt;span class="nt"&gt;-d&lt;/span&gt; tag-name

&lt;span class="c"&gt;# Delete a tag from the remote repository&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git tag &lt;span class="nt"&gt;-d&lt;/span&gt; tag-name
&lt;span class="nv"&gt;$ &lt;/span&gt;git push origin :refs/tags/tag-name.

&lt;span class="c"&gt;# Show tags&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git tag

&lt;span class="c"&gt;# Show tags with more info&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git show-ref &lt;span class="nt"&gt;--tags&lt;/span&gt;

&lt;span class="c"&gt;# Push tags&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git push origin &lt;span class="nt"&gt;--tags&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Rebase
&lt;/h2&gt;

&lt;p&gt;Previously in this article, we used &lt;code&gt;merge&lt;/code&gt; to join two branches. If you take a look at the log, you will see both branches, the commits on them and the point where they were merged.&lt;/p&gt;

&lt;p&gt;With &lt;code&gt;rebase&lt;/code&gt;, we are able to merge two branches and erase the history.&lt;br&gt;
What &lt;code&gt;rebase&lt;/code&gt; actually does is to show the commits that were made in a branch as if they were made in another.&lt;/p&gt;

&lt;p&gt;It's quite simple to get that result. Just make two rebases, one from the branch that you don't want anymore and another from the branch that is going to keep all the changes.&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="nv"&gt;$ &lt;/span&gt;git checkout experiment
&lt;span class="nv"&gt;$ &lt;/span&gt;git reabase master

&lt;span class="nv"&gt;$ &lt;/span&gt;git checkout master
&lt;span class="nv"&gt;$ &lt;/span&gt;git rebase experiment
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Keep in mind that we use Git in order to have a complete history of all our project's changes. Using this kind of things might be considered as a bad practice, because you are changing that history and making it not completely real.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Stash
&lt;/h2&gt;

&lt;p&gt;Imagine this situation:&lt;/p&gt;

&lt;p&gt;You are working in a feature. You coded a lot. Eventually, you need to take a look at something in another branch, but you are not ready to commit your changes. So, what can you do?&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Stash&lt;/code&gt; allows us to save current not commited changes in a temporary place.&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="c"&gt;# Save not commited changes in a temporary place&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git stash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, you can go to another branch and do whatever you want.&lt;/p&gt;

&lt;p&gt;When you want to bring those changes back, you just pop them.&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="c"&gt;# Bring stashed changes back&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git stash pop
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also see the list of all your stashed code and erase it if you don't need that code anymore.&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="c"&gt;# List stashs&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git stash list

&lt;span class="c"&gt;# Erase stashs&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git stash drop
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Another cool thing about stash, is that you can take your current changes and go to another branch without a commit.&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="c"&gt;# Create a new branch called 'new-feature' with the current changes.&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git stash branch new-feature
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Removing files
&lt;/h2&gt;

&lt;p&gt;Git clean, delete those new files that are not tracked yet.&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="c"&gt;# See what files will be deleted but don't erase anything&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git clean &lt;span class="nt"&gt;--dry-run&lt;/span&gt;

&lt;span class="c"&gt;# Delete the files listed by the previous command&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git clean &lt;span class="nt"&gt;-f&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Git rm, allows us to delete tracked files.&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="c"&gt;# Delete file from staging area but keep it in your computer&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git &lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;--cached&lt;/span&gt;

&lt;span class="c"&gt;# Delete file from staging area and from your computer&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git &lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;--force&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Git cherry-pick
&lt;/h2&gt;

&lt;p&gt;Imagine that you are working in that awesome new feature. As a good practice, you are coding in a new branch. Eventually, you need to deploy one commit of that branch. But you haven’t finished your new feature yet. So you need to merge your feature branch with master but want only one commit.&lt;/p&gt;

&lt;p&gt;It's kind of a weird situation, but it could happen. Git, solves this problem with something called &lt;code&gt;cherry-pick&lt;/code&gt;&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="c"&gt;# Look for the id of a commit. Remember that you should run this command into the branch where the commit has been done.&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git log

&lt;span class="c"&gt;# Go to master branch&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git checkout master

&lt;span class="c"&gt;# Merge only one commit of a branch to master&lt;/span&gt;
&lt;span class="c"&gt;# That strange string is the id of a commit 🙂&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git cherry-pick 4fd534
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There you go. Now you should see that commit in the master's log.&lt;/p&gt;

&lt;p&gt;Just like with rebase, be carefull with this command and remember that you are changing the history.&lt;/p&gt;

&lt;h2&gt;
  
  
  Amending commits
&lt;/h2&gt;

&lt;p&gt;Amend a commit, means that you commit a change to the very last commit that you did.&lt;/p&gt;

&lt;p&gt;Let's say that you wrote lots of &lt;code&gt;console.logs&lt;/code&gt; but forgot to erase them before the commit.&lt;/p&gt;

&lt;p&gt;Ok, it's not a problem. Go back to the code, erase them and commit again:&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="c"&gt;# add changes&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git add &lt;span class="nt"&gt;-A&lt;/span&gt;

&lt;span class="c"&gt;# amend last commit&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git commit &lt;span class="nt"&gt;--amend&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Take a look at the log and you'll see only one commit.&lt;/p&gt;

&lt;h2&gt;
  
  
  Clone
&lt;/h2&gt;

&lt;p&gt;Git has been made for teams.&lt;/p&gt;

&lt;p&gt;If you want to get into a project that has already been started, you will need to clone it.&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="c"&gt;# Example with SSH&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git clone git@github.com:user/repository.git

&lt;span class="c"&gt;# Example with HTTPS&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git clone https://github.com/user/repository.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Note: you will find the link in GitHub, GitLab, Bitbucket or the service where the project is hosted.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Git reflog
&lt;/h2&gt;

&lt;p&gt;There is a command that remembers everything. Even though you have used rebase, cherry pick or another of those commands that changes the history shown in git log; git rebase knows that you've done all of that crazy things.&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="nv"&gt;$ &lt;/span&gt;git reflog
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Search
&lt;/h2&gt;

&lt;p&gt;Git allows us to search throughout our project with 2 commands.&lt;/p&gt;

&lt;p&gt;For searching in the files: &lt;code&gt;git grep&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For searching in commits: &lt;code&gt;git log -S&lt;/code&gt;.&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="c"&gt;# Look for all p tags&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git &lt;span class="nb"&gt;grep&lt;/span&gt; &lt;span class="s2"&gt;"&amp;lt;p&amp;gt;"&lt;/span&gt;

&lt;span class="c"&gt;# Look for the commit where we change colors&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git log &lt;span class="nt"&gt;-S&lt;/span&gt; &lt;span class="s2"&gt;"change colors"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Some interesting flags for grep command:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;-n&lt;/code&gt;: returns the specific line where the word is.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-c&lt;/code&gt;: counts how many times was the word written.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Complete log
&lt;/h2&gt;

&lt;p&gt;We've already talked about git log, but it is much more powerful than expected.&lt;/p&gt;

&lt;p&gt;Let's see some flags:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;--oneline&lt;/code&gt;: shows each result in one line. Useful to see more information in less space.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--all&lt;/code&gt;: shows the logs of all the references: branches, tags.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--graph&lt;/code&gt;: draws lines to illustrate the relationship of the different branches.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--decorate&lt;/code&gt;: a little bit of colors for the graph.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, let's put it all together.&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="nv"&gt;$ &lt;/span&gt;git log &lt;span class="nt"&gt;--all&lt;/span&gt; &lt;span class="nt"&gt;--graph&lt;/span&gt; &lt;span class="nt"&gt;--decorate&lt;/span&gt; &lt;span class="nt"&gt;--oneline&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Aliases
&lt;/h2&gt;

&lt;p&gt;Git allows us to create an alias for a command.&lt;/p&gt;

&lt;p&gt;If you know about linux aliases, it's the same idea.&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="nv"&gt;$ &lt;/span&gt;git config &lt;span class="nt"&gt;--global&lt;/span&gt; alias.name &lt;span class="s2"&gt;"command"&lt;/span&gt;

&lt;span class="c"&gt;# Example&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git config &lt;span class="nt"&gt;--global&lt;/span&gt; alias.tree &lt;span class="s2"&gt;"log --all --graph --decorate --oneline"&lt;/span&gt;

&lt;span class="c"&gt;# Trying it&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git tree
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Git is really big
&lt;/h2&gt;

&lt;p&gt;You have now a really good understanding of git and how to use it. But Git is really big. I encourage you to read the docs to learn a lot more about it.&lt;/p&gt;

</description>
      <category>git</category>
      <category>github</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
