<?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: Royal Bhati</title>
    <description>The latest articles on DEV Community by Royal Bhati (@royal_bhati).</description>
    <link>https://dev.to/royal_bhati</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%2F247586%2Fa1634116-c8b7-4eb6-8cbd-34e6a61fa321.jpg</url>
      <title>DEV Community: Royal Bhati</title>
      <link>https://dev.to/royal_bhati</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/royal_bhati"/>
    <language>en</language>
    <item>
      <title>DynamoDB Streams</title>
      <dc:creator>Royal Bhati</dc:creator>
      <pubDate>Fri, 18 Jun 2021 06:28:28 +0000</pubDate>
      <link>https://dev.to/royal_bhati/dynamodb-streams-13eg</link>
      <guid>https://dev.to/royal_bhati/dynamodb-streams-13eg</guid>
      <description>&lt;p&gt;While working on a backend service, I came across this problem where I had to retrieve a set of data of a specific type, but that type wasn’t having any index and the data was also updating frequently.&lt;/p&gt;

&lt;p&gt;Since the data was constantly changing, the first thing that came to mind was to attach a trigger. However, when looking at the documentation on how to add triggers to DynamoDB in AWS, I opted to go with another approach :p&lt;/p&gt;

&lt;p&gt;By the time I had time to consider, there were three viable options that were obvious without lengthy consideration&lt;/p&gt;

&lt;p&gt;→  &lt;strong&gt;Complete scan of the table and filter the results&lt;/strong&gt;&lt;br&gt;
 From the very first moment it entered my head, I knew this is a very inefficient solution&lt;/p&gt;

&lt;p&gt;→ &lt;strong&gt;Add an Index for that type&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;There were a couple of reasons I didn’t go along with this idea&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;That wasn't a very frequently queried data&lt;/li&gt;
&lt;li&gt;Already had so many indexes so didn't want to add one more just yet before trying other solutions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;→  &lt;strong&gt;Run a cron-job&lt;/strong&gt; &lt;br&gt;
A cron-job that will perform a table scan, store the result in a cache, or store it in another table.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A Great man once said, If you can't think of anything else, run a cron-job.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;Back in my mind, I wasn’t quite convinced with any of the above solutions and so I gave Dynamo db triggers try. I was aware of Dynamo db streams but never tried them.&lt;/p&gt;

&lt;p&gt;DynamoDB Streams are basically triggers like that we have in Relational DBs but the only difference is that it generates a stream of events when there is a data change and you can easily pipe that stream into Kinesis or a Lambda (In my case it was lambda).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flhsj779raxsprdth97ih.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flhsj779raxsprdth97ih.png" alt="Architecture"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;AWS made the things look difficult but the process was not complex at all. &lt;/p&gt;

&lt;p&gt;All I had to do was the following -&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Setup a stream on the dynamodb table which was just a one click action.&lt;/li&gt;
&lt;li&gt;Create a new lambda function and attach it to the dynamodb stream which was also fairly easy&lt;/li&gt;
&lt;li&gt;Rest was basic stuff of listening the data then processing it and finally saving it to the new table&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;DynamoDB streams are much more than what I have covered in my use case. You can read more about it here : -&lt;a href="https://aws.amazon.com/blogs/database/dynamodb-streams-use-cases-and-design-patterns/" rel="noopener noreferrer"&gt;https://aws.amazon.com/blogs/database/dynamodb-streams-use-cases-and-design-patterns/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>aws</category>
      <category>dynamodb</category>
      <category>node</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Go project layout</title>
      <dc:creator>Royal Bhati</dc:creator>
      <pubDate>Mon, 08 Feb 2021 12:36:09 +0000</pubDate>
      <link>https://dev.to/royal_bhati/package-layout-for-a-go-web-app-4oea</link>
      <guid>https://dev.to/royal_bhati/package-layout-for-a-go-web-app-4oea</guid>
      <description>&lt;p&gt;Go is very flexible when it comes to writing apps and structuring them.&lt;br&gt;
Though, you should always write idiomatic Go when possible.&lt;/p&gt;

&lt;p&gt;While not thinking about structuring your apps is okay, but as your app starts to grow, you have to have a structured architecture so that it's easy for you and other devs to know how things connect in your app. It also avoids duplication of code and, maybe, will help you scale heights.&lt;/p&gt;

&lt;p&gt;I was looking for that one structure I could follow, but almost everyone has their stuff.&lt;br&gt;
So, I started reading blogs and even started reading open-source projects and finally picked the best parts.&lt;br&gt;
Before showing you the structure, I'll try to build your mental model for this architecture by this analogy.&lt;/p&gt;

&lt;p&gt;Let's say you want to start a business and the product your building is a Dancing Doggos App, which will contain dancing videos and photos of dogs.&lt;/p&gt;

&lt;p&gt;Exciting right?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/OnQqgkPWJ17DG/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/OnQqgkPWJ17DG/giphy.gif" alt="Dancing Doggo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, what should we do next?&lt;/p&gt;

&lt;p&gt;The first that comes to my mind is management that can manage our product specific to our needs.&lt;br&gt;
So we need to hire product managers, CEO, CTO and other fancy managers with those suits and ties :p&lt;/p&gt;

&lt;p&gt;Next, we need is the people who'll be working under our Managers. &lt;br&gt;
So, marketing team, sales team, and a team of amazing people aka developers :p&lt;/p&gt;

&lt;p&gt;Now that we have everything ready to go, we need to think about how everything will work.&lt;br&gt;
The following few lines are going to be the crucial part of all the useless stuff I wrote.&lt;/p&gt;

&lt;h4&gt;
  
  
  Product Owners -
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;They want their idea out in the market.&lt;/li&gt;
&lt;li&gt;They only talk to the managers.&lt;/li&gt;
&lt;li&gt;They don't care how you do it ( of-course not if its unethical :p)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Managers -
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;They are the people who are responsible for getting the work done.&lt;/li&gt;
&lt;li&gt;They manage the people working under them to work according to the needs&lt;/li&gt;
&lt;li&gt;Their work is mostly product specific.&lt;/li&gt;
&lt;li&gt;Their decisions and choices are governed by the product they are building. (A Manager who is working for Pepsi will have to make different decisions if he starts working for Gucci) &lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Teams -
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;They usually don't care what you are building&lt;/li&gt;
&lt;li&gt;They usually don't have to change their decisions based on the product (A Go Developer working on Go in Pepsi will also be working on Go if he makes a switch to Gucci).&lt;/li&gt;
&lt;li&gt;Teams are usually independent and don't require any other team to make their work done. ( Marketing team doesn't depend on Devs team to work)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You might be thinking I have read so much and still haven't found anything I can take away from this but please bear 🧸 with me for the next few minutes.&lt;/p&gt;

&lt;p&gt;Building upon our business workflow, we can structure our app. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwkdj3gs22mpvqxyklvcl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwkdj3gs22mpvqxyklvcl.png" alt="structure"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  /app
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Product owner&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This folder contains our business logic, and that's it. &lt;/p&gt;

&lt;p&gt;This directory doesn't care about what database driver you are using or which caching solution your using, or any third-party apps.&lt;/p&gt;

&lt;p&gt;Its only job is to provide the business-related details, including structuring the models, authorizing the clients, storing them in the database, or sending it to the clients.&lt;/p&gt;

&lt;h2&gt;
  
  
  /platform
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;teams&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This folder contains all the platform-level logic that will build up the actual product, like setting up the database, Redis instance, or maybe a router.&lt;/p&gt;

&lt;p&gt;All of the packages inside this directory are independent of each other.&lt;/p&gt;

&lt;p&gt;Packages inside this folder also don't care what's inside &lt;strong&gt;/app&lt;/strong&gt;  or &lt;strong&gt;/cmd&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  /cmd
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Management&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This folder contains all the application-specific code tailored only for your business use case—things like configuration, logging, and DB migrations.&lt;/p&gt;

&lt;p&gt;This directory talks to the  &lt;strong&gt;/app&lt;/strong&gt; for instructions, and then it takes the services offered by &lt;strong&gt;/cmd&lt;/strong&gt; and finally delivers the product&lt;br&gt;
This directory is the Mitochondria of our application (Bad science pun, sorry :p)&lt;/p&gt;




&lt;h3&gt;
  
  
  tl;dr
&lt;/h3&gt;

&lt;p&gt;Your app's business-related logic shouldn't care about the platform and app-level code like routes, databases, and third-party packages you are using.&lt;br&gt;
Your Application-level code (/cmd) like configurations and routes will vary according to different services or business ideas.&lt;br&gt;
Your Platform level code doesn't care what you are building, and they should only have a single purpose. It shouldn't produce any side-effects inside your business logic.&lt;/p&gt;

&lt;p&gt;Here is the WIP project uses the above structure&lt;/p&gt;

&lt;p&gt;The project below is just a work in progress and only for my learning purpose, but the structure is handy if you want to use it in your next project.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/royalbhati/url-shortener" rel="noopener noreferrer"&gt;https://github.com/royalbhati/url-shortener&lt;/a&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>productivity</category>
      <category>go</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Remove unwanted properties from Javascript Objects using ES6 destructuring</title>
      <dc:creator>Royal Bhati</dc:creator>
      <pubDate>Tue, 26 May 2020 09:59:46 +0000</pubDate>
      <link>https://dev.to/royal_bhati/remove-unwanted-properties-from-javascript-objects-using-es6-destructuring-5c0a</link>
      <guid>https://dev.to/royal_bhati/remove-unwanted-properties-from-javascript-objects-using-es6-destructuring-5c0a</guid>
      <description>&lt;p&gt;lets say we received an object  from an api response which contains some sensitive data&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;userData&lt;/span&gt; &lt;span class="o"&gt;=&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="s2"&gt;Rick Sanchez&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ricksanchez@getSchwifty.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
  &lt;span class="na"&gt;address&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; Dimension C-137&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;sensitiveInfo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;wubba lubaa dub dub&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;secretportalkey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ABCDEF&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;Now we want to pass it to some third party api but we dont want to pass the sensitiveInfo and secretPortal key to the Api&lt;/p&gt;

&lt;p&gt;So, How do we remove that from the Object ?&lt;/p&gt;

&lt;p&gt;Simple, just use the power of destructuring&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="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;sensitiveInfo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;secretportalkey&lt;/span&gt;&lt;span class="p"&gt;,...&lt;/span&gt;&lt;span class="nx"&gt;notSoSensitiveData&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;userData&lt;/span&gt;

&lt;span class="cm"&gt;/* Now our notSoSensitiveData will contain all the properties except the ones which
 are destructured
*/&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;notSoSensitiveData&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="cm"&gt;/* {
  name:"Rick Sanchez",
  email:"ricksanchez@getSchwifty.com"
  address :" Dimension C-137",
}
*/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Understanding weird parts of Javascript</title>
      <dc:creator>Royal Bhati</dc:creator>
      <pubDate>Mon, 25 Nov 2019 21:20:01 +0000</pubDate>
      <link>https://dev.to/royal_bhati/understanding-weird-parts-of-javascript-44o</link>
      <guid>https://dev.to/royal_bhati/understanding-weird-parts-of-javascript-44o</guid>
      <description>&lt;p&gt;Since JavaScript is a weakly-typed language, values can also convert automatically between different types, and it is called implicit type coercion. People who don't understand the quirks of javascript tend to make fun of the language by sharing memes like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fgxzppgzfjt62v62a7g0h.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fgxzppgzfjt62v62a7g0h.jpeg" alt="js meme"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now in this post, I am going to walk through every example given in this meme and try to explain briefly and try to link references if possible.&lt;/p&gt;

&lt;p&gt;While every single example mentioned in this meme would have been a standalone long post, I kept it short to keep it concise and beginner-friendly. Might throw some more light on examples separately in future.&lt;/p&gt;

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

&lt;p&gt;1.&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="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="k"&gt;typeof&lt;/span&gt; &lt;span class="kc"&gt;NaN&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// "number";&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;According to the ECMAScript standard, Numbers should be IEEE-754 floating-point data. This includes Infinity, -Infinity, and also NaN.&lt;/p&gt;

&lt;p&gt;NaN stands for Not a number.&lt;/p&gt;

&lt;p&gt;Let's see when NaN is returned :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Division of zero by zero. ( 0 / 0)&lt;/li&gt;
&lt;li&gt;Dividing an infinity by infinity. (Inf / Inf)&lt;/li&gt;
&lt;li&gt;Multiplication of an infinity by a zero. ( Inf * 0)&lt;/li&gt;
&lt;li&gt;Any operation in which NaN is an operand. (NaN + 2)&lt;/li&gt;
&lt;li&gt;Converting any undefined or non-numeric string to a number. Number("abc")&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Saw anything common?&lt;br&gt;
NaN is returned only when there is a numerical operation.&lt;/p&gt;

&lt;p&gt;By definition, NaN is the return value from operations that have an undefined "numerical" result.&lt;br&gt;
So, It is evident that the type of NaN would be a number.&lt;/p&gt;

&lt;p&gt;Reference :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://en.wikipedia.org/wiki/NaN" rel="noopener noreferrer"&gt;https://en.wikipedia.org/wiki/NaN&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://en.wikipedia.org/wiki/IEEE_754-2008_revision" rel="noopener noreferrer"&gt;https://en.wikipedia.org/wiki/IEEE_754-2008_revision&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;2 .&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="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="mi"&gt;999999999999&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 10000000000000;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This happens because JavaScript only supports 53-bit integers.&lt;br&gt;
All numbers in JavaScript are floating-point which means that integers are always represented as&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sign × mantissa × 2^exponent
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;&lt;a href="https://www.ntu.edu.sg/home/ehchua/programming/java/images/DataRep_Double.png" rel="noopener noreferrer"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The fraction occupies bits 0 to 51, the exponent occupies bits 52 to 62, the sign occupies bit 63.&lt;br&gt;
So js suffers from a loss of precision where the least significant digits disappear if the number is huge.&lt;/p&gt;

&lt;p&gt;There has been a recent addition to javascript "BigInt" which solves the problem of representing whole numbers larger than&lt;br&gt;
 2^53 - 1&lt;/p&gt;

&lt;p&gt;References:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://tc39.es/ecma262/#sec-ecmascript-language-types-number-type" rel="noopener noreferrer"&gt;https://tc39.es/ecma262/#sec-ecmascript-language-types-number-type&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://tc39.es/ecma262/#sec-ecmascript-language-types-bigint-type" rel="noopener noreferrer"&gt;https://tc39.es/ecma262/#sec-ecmascript-language-types-bigint-type&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;3.&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="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="mf"&gt;0.5&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.1&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mf"&gt;0.6&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true&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="mf"&gt;0.1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.2&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mf"&gt;0.3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I have already mentioned it above but gonna repeat it, JavaScript uses a 64-bit floating-point representation according to IEEE 754.&lt;br&gt;
64-bit Binary floating-point format cannot accurately represent a number like 0.1, 0.2 or 0.3 at all. While most of the languages round off the number to give results as expected but JS don't.&lt;/p&gt;

&lt;p&gt;If you convert 0.1 to binary representation you would end up with a 0.00011001100110011.... (endless repetition of 0011 ).&lt;br&gt;
&lt;a href="https://www.exploringbinary.com/why-0-point-1-does-not-exist-in-floating-point/" rel="noopener noreferrer"&gt;This post explains it in detail &lt;/a&gt;&lt;br&gt;
In double-precision floating-point (JS), 53 bits are used, so the otherwise infinite representation is rounded to 53 significant bits. So results are always inaccurate in decimal.&lt;br&gt;
This stack overflow answer  also explains it very well - &lt;a href="https://stackoverflow.com/a/28679423" rel="noopener noreferrer"&gt;https://stackoverflow.com/a/28679423&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;References :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://tc39.es/ecma262/#sec-ecmascript-language-types-number-type" rel="noopener noreferrer"&gt;https://tc39.es/ecma262/#sec-ecmascript-language-types-number-type&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;4 .&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="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="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;  &lt;span class="c1"&gt;//-Infinity&lt;/span&gt;
&lt;span class="nx"&gt;conosle&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="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="c1"&gt;//+Infinity&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First Let's make it clear that...&lt;br&gt;
THEY DON'T RETURN LARGEST OR MINIMUM NUMBERS, for those needs we have Number.MAX_VALUE and NUMBER.MIN_VALUE.&lt;/p&gt;

&lt;p&gt;Math. max() and Math. min() are static methods that return maximum and min values among the respective arguments.&lt;br&gt;
So according to the spec, if you call them without any arguments, they would return -Inf and +Inf.&lt;/p&gt;

&lt;p&gt;While the spec doesn't say anything regarding why it does that, so I looked into the chromium source code to find that out.&lt;br&gt;
To be honest, I found what I was thinking i.e. whenever you call the Math. max() method with a single argument(Math. max(100)), it compares it with -Infinity and returns the Number itself because if it is a valid number, it would always be more significant than -Infinity.&lt;br&gt;
Same goes for Math.min().&lt;br&gt;
So when there is no argument to compare it returns -Infinity as its the max value between nothing and -Inf.&lt;/p&gt;

&lt;p&gt;5.&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="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="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;[])&lt;/span&gt; &lt;span class="c1"&gt;// ""&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;According to the spec, when javascript encounters The Addition Operator ( + ) it performs following steps.&lt;/p&gt;

&lt;p&gt;These steps will build foundation for upcoming few examples.&lt;/p&gt;

&lt;p&gt;a. Convert both operands to Primitive values&lt;br&gt;
b. If any of the operand is type String then return result as string concatenation&lt;br&gt;
c. Else convert both the Operands to Number using ToNumber()&lt;br&gt;
d. If type of one operand is different from other then throw a TypeError&lt;br&gt;
e  Else return the mathematical sum&lt;/p&gt;

&lt;p&gt;So lets walkthrough our example :&lt;/p&gt;

&lt;p&gt;a. First operands are first converted to their primitive values if they are not, which in this case are not primitive .&lt;/p&gt;

&lt;p&gt;b. Now the ToPrimitive converts the object type to a primitive type. Along with the input, ToPrimitive also accepts an optional "Preferred type" parameter which is provided to give ToPrimitive a hint of the type.&lt;/p&gt;

&lt;p&gt;c. After converting to the primitives if any of the primitive is of type string,then string concatenation takes place which in this case is true (explained below) and we see a "" as a result.&lt;/p&gt;

&lt;p&gt;Let's se how ToPrimitive works :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;When there is no hint is given, ToPrimitive defaults the hint to Number.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After deciding the hint, it checks it against list of two methods in a defined order.&lt;br&gt;
[valueOf, toString] in the case of hint Number and reverse in the case of String.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In this case it uses the default hint so the following steps are taken&lt;br&gt;
    a) [].valueof returns Array itself ans since its not primitive, so it goes to the second method&lt;br&gt;
    b) [].toString returns "" and since it returns a primitive value it is returned as a primitive value.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;References :&lt;br&gt;
&lt;a href="https://tc39.es/ecma262/#sec-addition-operator-plus" rel="noopener noreferrer"&gt;https://tc39.es/ecma262/#sec-addition-operator-plus&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;6 .&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="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="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;{})&lt;/span&gt; &lt;span class="c1"&gt;// "[object Object]"&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Adding to the explaination above, {}.toString is [object Object] so by string concatenation we get this result.&lt;/p&gt;

&lt;p&gt;7.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;{}&lt;/span&gt; &lt;span class="o"&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 this example would return the same result as [] +{}.&lt;/p&gt;

&lt;p&gt;But does that mean the meme has a typo?&lt;/p&gt;

&lt;p&gt;NO, but If you try that example in the console of chrome or firefox it would return 0.&lt;br&gt;
This is becaus Object literal in starting is treated as an empty code block and is ignored by interpreter and we are left with this &lt;br&gt;
expression " + [] ".&lt;br&gt;
Now the unary "+" operator converts its operand to Number and Number([]) equals to zero.&lt;/p&gt;

&lt;p&gt;Reference:&lt;br&gt;
    -&lt;a href="https://tc39.es/ecma262/#sec-unary-plus-operator" rel="noopener noreferrer"&gt;https://tc39.es/ecma262/#sec-unary-plus-operator&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;8.&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="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="kc"&gt;true&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 3&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="kc"&gt;true&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//0&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now according to algorithm in the 5th point, we already have a primitive value i.e boolean and since none of the operand is a string we convert the first two operands to Numeric and according to the spec, ToNumber(Boolean) is 1 for true and 0 for false.&lt;br&gt;
So true + true gives 1+1 = 2&lt;/p&gt;

&lt;p&gt;No we have "2 + true" which is processed same as we did for the first two operands and we get 3.&lt;/p&gt;

&lt;p&gt;So both of the results makes sense now.&lt;/p&gt;

&lt;p&gt;Reference :&lt;br&gt;
    - &lt;a href="https://tc39.es/ecma262/#sec-tonumber" rel="noopener noreferrer"&gt;https://tc39.es/ecma262/#sec-tonumber&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;9 .&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="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="kc"&gt;true&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//true&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="kc"&gt;true&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;First expression is compared using Abstract Equality Comparison which allows coercion so according to the spec&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;If Type(x) is Boolean, return the result of the comparison ToNumber(x) == y.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So using that we get ToNumber(true) ==1&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Second expression is compared using Strict Equality Comparison which does not allow coercion so according to the spec&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;If Type(x) is different from Type(y), return false.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Clearly, types are different so result is false&lt;/p&gt;

&lt;p&gt;10.&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="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="o"&gt;!+&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="o"&gt;+!&lt;/span&gt;&lt;span class="p"&gt;[]).&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 9 &lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is was a mind fuck when I was first saw this :p&lt;/p&gt;

&lt;p&gt;Lets divide this in four pieces.&lt;/p&gt;

&lt;p&gt;lets begin with !+[]&lt;/p&gt;

&lt;p&gt;Now here, we don't have two operands but two unary operators (! &amp;amp; +) and  since ! and + has same precedence we start from left to right.&lt;br&gt;
We first encounter "!" whose associativity is right to left so we evaluate "+[]" which results in 0 (we have already discussed why the result is zero in 7th post)&lt;/p&gt;

&lt;p&gt;Now negation operator according to the spec converts the operand into boolean if its not already so if we convert 0 to boolean we get a false.&lt;br&gt;
So, "!false" returns true which is of type boolean.&lt;/p&gt;

&lt;p&gt;Now we have (true + [] + ![]).length&lt;/p&gt;

&lt;p&gt;Taking "true + []" for evaluation according to the rules of addition operator we get a result "true" of type string because the primitive value of empty array is an empty string and if any of the operand is of type string we perform string concatenation.&lt;/p&gt;

&lt;p&gt;Now we are left with ("true"+![]).length&lt;/p&gt;

&lt;p&gt;So according to the rules of "!" operator we convert [] to boolean which results in true (According to the spec ToBoolean(object) returns true).&lt;br&gt;
So now,placing true in place of empty array we get "!true" which results in false and since one of our operand is of type string we concatenate the operands which results in "truefalse"&lt;/p&gt;

&lt;p&gt;Now its obvious why console.log("truefalse".length) returns 9&lt;/p&gt;

&lt;p&gt;Reference : &lt;br&gt;
    - &lt;a href="https://tc39.es/ecma262/#sec-toboolean" rel="noopener noreferrer"&gt;https://tc39.es/ecma262/#sec-toboolean&lt;/a&gt;&lt;br&gt;
    - &lt;a href="https://tc39.es/ecma262/#sec-logical-not-operator" rel="noopener noreferrer"&gt;https://tc39.es/ecma262/#sec-logical-not-operator&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;11.&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="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="mi"&gt;9&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//91&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We have already discussed this but I am gonna mention it again.&lt;br&gt;
According to js spec if any one of the operand's primitive value is of type string then we concatenate the operands's primitive value which results in "91"&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="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="mi"&gt;9&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 90&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;According to the spec, In subtraction operands are coerced to Number and if the ToNumber results are valid then final result is a mathematical subtraction.&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="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="o"&gt;==&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As mentioned earlier, Double equals uses Abstract Equality Comparison which allows coercion so our empty array is coneverted to its primitive value which is "" and according to the spec&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If Type(x) is String and Type(y) is Number, return the result of the comparison ToNumber(x) == y.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;and ToNumber("") is 0 so that is why we get a true.&lt;/p&gt;




&lt;p&gt;&lt;a href="https://i.giphy.com/media/229OX0vSVNys10AZnS/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/229OX0vSVNys10AZnS/giphy.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So next time if anyone shares this meme with you then you have answers to keep them shut.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>webdev</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Temp</title>
      <dc:creator>Royal Bhati</dc:creator>
      <pubDate>Mon, 25 Nov 2019 13:45:47 +0000</pubDate>
      <link>https://dev.to/royal_bhati/demystifying-javascript-2j1c</link>
      <guid>https://dev.to/royal_bhati/demystifying-javascript-2j1c</guid>
      <description></description>
    </item>
    <item>
      <title>Write your first webpack plugin</title>
      <dc:creator>Royal Bhati</dc:creator>
      <pubDate>Tue, 19 Nov 2019 14:21:39 +0000</pubDate>
      <link>https://dev.to/royal_bhati/write-your-first-webpack-plugin-20fh</link>
      <guid>https://dev.to/royal_bhati/write-your-first-webpack-plugin-20fh</guid>
      <description>&lt;p&gt;If you have clicked on the title, then I assume you have a basic understanding of webpack and webpack plugins.&lt;/p&gt;

&lt;p&gt;Plugins are great and helps you leverage the power of webpack.&lt;br&gt;
There are tons of plugins available for webpack, some of the famous ones are HtmlWebpackPlugin , HotModuleReplacementPlugin and webpack-bundle-analyzer.&lt;/p&gt;

&lt;p&gt;While these are great but there are always cases when you need a project specific plugin and it gets worse when you are unable to find any plugin for your needs.&lt;/p&gt;
&lt;h2&gt;
  
  
  How about creating your own Plugin ?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/5hc2bkC60heU/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/5hc2bkC60heU/giphy.gif" alt="giphy"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this post we will create a plugin to remove 'console.logs' from the production build.&lt;/p&gt;

&lt;p&gt;Let's begin by creating a simple react project.&lt;/p&gt;

&lt;p&gt;If your react project is not setup then follow these steps to create a basic react starter.&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;mkdir &lt;/span&gt;myplugin &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;cd &lt;/span&gt;myplugin
&lt;span class="nv"&gt;$ &lt;/span&gt;npx react-starter-lite

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;react-starter-lite is a simple boilerplate package to easily get your hands dirty on react projects.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Run the app to see if its working properly&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;yarn dev:hot

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After setting up the directory create a file named logRemover.js in your project directory and paste the following code.&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="c1"&gt;//logRemover.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="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;RemoveLogs&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="kd"&gt;constructor&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;options&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;compiler&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello from the new 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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Lets see whats happening in the code.
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;In the first line we are exporting the class we are creating.Plugins can be created using functions also but I have used classes here.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Constructor has an paramter options which accepts arguments related to the logic of the plugin. In this post we won't be needing the options but I showed you just show that you know.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;apply() is a mandatory method which recieves a compiler instance as   an argument which contains basically everything you need to do make your plugin.Since we are not using compiler yet I will tell you a bit more compiler when we are done with  basic setup.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Console.log() just to see if our setup is working&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After setting up the logRemover.js we need to invoke that plugin in our webpack configuration.&lt;/p&gt;

&lt;p&gt;In the project directory we have three webpack configurations, one is the base config and the other two are development and production configs.&lt;/p&gt;

&lt;p&gt;Since we just need to remove console.logs from the production build only, we need to add that plugin in the webpack production config.&lt;br&gt;
But for testing the setup, for now, we'll add that to development config and will change that later when we'll have logic for our plugin.&lt;/p&gt;

&lt;p&gt;So open webpack.config.dev.js and invoke the plugin like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="c1"&gt;//webpack.config.dev.js&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;merge&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;webpack-merge&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;baseConfig&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./webpack.config-base&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;RemoveLogs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./logRemover.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;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="nx"&gt;merge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;baseConfig&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="s2"&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;port&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;9000&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;devtool&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;source-map&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;RemoveLogs&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 lets test if our setup was successfull.&lt;br&gt;
Stop if the webpack server is running and run&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;yarn dev:hot

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now if you look in to you terminal you'll see that console.log statement.Since there is so much on terminal, you need to look carefully to find your log message.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/5GoVLqeAOo6PK/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/5GoVLqeAOo6PK/giphy.gif" alt="congrats"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Congrats if you have made this far :p&lt;/p&gt;




&lt;p&gt;Now since our basic setup is working let's write the logic for our plugin inside logRemover.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="c1"&gt;//logRemover.js&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;fs&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="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;RemoveLogs&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;compiler&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;compiler&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hooks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;done&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;tap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;RemoveLogs&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;stats&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&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;path&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="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;stats&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;compilation&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="nx"&gt;output&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;filePath&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;filename&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nx"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;readFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;filePath&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;utf8&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;err&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;data&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;{&lt;/span&gt;
          &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;rgx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sr"&gt;/console.log&lt;/span&gt;&lt;span class="se"&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;.*&lt;/span&gt;&lt;span class="se"&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;/&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;newdata&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rgx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;""&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;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
          &lt;span class="nx"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;writeFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;filePath&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;newdata&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&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;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
              &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Logs Removed&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="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&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 see what this code is doing&lt;/p&gt;

&lt;p&gt;1) apply(compiler) method takes in a compiler instance which contains events.&lt;br&gt;
Compiler module is the main engine of the webpack which emits events   just like dom. It extends Tapable lib to register and call plugins. In this logic we are tapping on hook "done" which is emitted after the compilation is completed and bundle is generated.&lt;/p&gt;

&lt;p&gt;2) using these compiler events we call our plugin to do its job&lt;/p&gt;

&lt;p&gt;3) Its job is nothing fancy but just to take the bundled js and pass it through a regex and remove all the console.logs and output the bundled js in the dist directory.&lt;/p&gt;

&lt;p&gt;Now since we are done with the logic we will remove the plugin from the dev config in webpack.config.dev.js and put it under production config in webpack.config.prod.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="c1"&gt;//webpack.config.prod.js&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;merge&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;webpack-merge&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;baseConfig&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./webpack.config-base&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;RemoveLogs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./logRemover.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;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="nx"&gt;merge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;baseConfig&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="s2"&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;RemoveLogs&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;To see if its working we will write a console.log statement in App.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;//src.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="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./styles.css&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;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;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;test console.log statement &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"card"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"content"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;{...&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="ni"&gt;&amp;amp;#9829;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;}&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h5&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;! hate&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h5&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&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;span class="p"&gt;;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now stop the webpack server and generate the build by&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 build

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now open the index.html from the dist directory and check if there any console.log statement or you can check  in the bundeled js in the editor by doing ctr/cmd + F in bundeled file.&lt;/p&gt;

&lt;p&gt;That's all for today :)&lt;/p&gt;

&lt;p&gt;Please feel free to comment and ping me if you have any doubts.&lt;/p&gt;

&lt;p&gt;Here is the github project if you want to see the full source code :&lt;/p&gt;

&lt;p&gt;&lt;a href="//github.com/royalbhati/webpack-LogRemover-plugin"&gt;webpack-LogRemover-plugin&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Additional Reading :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://webpack.js.org/api/compiler-hooks/?source=post_page-----1c2a292da2fd----------------------"&gt;Compiler&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://webpack.js.org/contribute/writing-a-plugin/?source=post_page-----1c2a292da2fd----------------------"&gt;Plugins&lt;/a&gt;&lt;/p&gt;

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