<?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: Bruno Moura</title>
    <description>The latest articles on DEV Community by Bruno Moura (@bruno8moura).</description>
    <link>https://dev.to/bruno8moura</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%2F405633%2F1a8df5e9-1e24-4da9-b1e4-810636b6cafa.png</url>
      <title>DEV Community: Bruno Moura</title>
      <link>https://dev.to/bruno8moura</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bruno8moura"/>
    <language>en</language>
    <item>
      <title>[Databases] - Update consistency</title>
      <dc:creator>Bruno Moura</dc:creator>
      <pubDate>Sat, 25 Nov 2023 01:02:38 +0000</pubDate>
      <link>https://dev.to/bruno8moura/databases-update-consistency-4p7m</link>
      <guid>https://dev.to/bruno8moura/databases-update-consistency-4p7m</guid>
      <description>&lt;h2&gt;
  
  
  Prelude
&lt;/h2&gt;

&lt;p&gt;A centralized relational database tries to show a robust data consistency and concurrency control.&lt;/p&gt;

&lt;p&gt;But in a world where chasing to improve performance is a constant, so when we are dealing with databases clusters, issues like &lt;em&gt;update consistency&lt;/em&gt;, &lt;em&gt;reading consistency&lt;/em&gt;,replicatation consistency, &lt;em&gt;eventual consistency&lt;/em&gt;,&lt;em&gt;conditional update&lt;/em&gt;, etc comes to hand.&lt;/p&gt;

&lt;p&gt;Let's talk about the many ways that consitency may mean.&lt;/p&gt;

&lt;h2&gt;
  
  
  The issue with "Update consistency"
&lt;/h2&gt;

&lt;p&gt;In this situation we have to deal with write-write conflict, means two clients trying to update the same data at the same time.&lt;/p&gt;

&lt;p&gt;When there is a centralized database, a single node, that receive all writes, then &lt;em&gt;&lt;strong&gt;we are trying to maintain consistency confronting concurrency&lt;/strong&gt;&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Scenery like this are described as optimistic and pessimistic. &lt;/p&gt;

&lt;h2&gt;
  
  
  Keeping consistency in a optimistic way
&lt;/h2&gt;

&lt;p&gt;In optimistic scenario, the node accepts all writes, and after try to solve the conflicts.&lt;/p&gt;

&lt;p&gt;An approach very common is the "&lt;strong&gt;conditional update&lt;/strong&gt;", means, test the data before write. &lt;/p&gt;

&lt;p&gt;Let's say, along with the data that will be updated, a field called "version" is used to test the update. Every update that occurs the version number is incremented.&lt;/p&gt;

&lt;p&gt;In a context that conflicts happen rarely, this approach works fine.&lt;/p&gt;

&lt;p&gt;In other hand, in a context that conflicts happen many times, many data can be without updates and will be lost.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keeping consistency in a pessimistic way
&lt;/h2&gt;

&lt;p&gt;The premise here is "no conflict will happen".&lt;/p&gt;

&lt;p&gt;No write will happen until the current write finishes its update.&lt;/p&gt;

&lt;p&gt;By the strategy nature, performance is not a priority here.&lt;/p&gt;

&lt;p&gt;This strategy, many times, leads to deadlocks conflicts.&lt;/p&gt;

&lt;p&gt;By the end, when we are building a software, there is not the right answer, the answer is depends what the business need. &lt;/p&gt;

&lt;p&gt;What characteristics your software must have?&lt;/p&gt;

&lt;p&gt;Security and responsiveness are fundamental when dealing with concurrent programming.&lt;/p&gt;

</description>
      <category>sql</category>
      <category>nosql</category>
      <category>cap</category>
      <category>distributedsystems</category>
    </item>
    <item>
      <title>[Javascript] - [Part 1] - Prototype</title>
      <dc:creator>Bruno Moura</dc:creator>
      <pubDate>Thu, 23 Nov 2023 00:22:29 +0000</pubDate>
      <link>https://dev.to/bruno8moura/javascript-part-1-prototype-4776</link>
      <guid>https://dev.to/bruno8moura/javascript-part-1-prototype-4776</guid>
      <description>&lt;p&gt;"prototype" is called "a reference to another object". From where? From any javascript object.&lt;/p&gt;

&lt;p&gt;So, prototype is a parent from your custom object.&lt;/p&gt;

&lt;p&gt;If none parent is set, then the parent is the object "Object". &lt;/p&gt;

&lt;p&gt;And this parent points to primitive type "null".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const b = { b: 1 }

b // the custom object
b.__proto__ // the parent "Object"
b.__proto__.__proto__ // null
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;__proto__ gets an object prototype from the object itself!&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Just it. Here we have what is called "prototype chain".&lt;/p&gt;

&lt;p&gt;But, be careful, as we said before, every object point to the same parent "Object".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const custom1 = {c1:1}
const custom2 = {c2:2}

custom1.__proto__.myNewProp = 2

console.log(custom2.myNewProp) // prints: 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Good luck! ;)&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>node</category>
    </item>
    <item>
      <title>[Javascript] - Data dictionary</title>
      <dc:creator>Bruno Moura</dc:creator>
      <pubDate>Wed, 15 Nov 2023 14:37:37 +0000</pubDate>
      <link>https://dev.to/bruno8moura/javascript-data-dictionary-4p7f</link>
      <guid>https://dev.to/bruno8moura/javascript-data-dictionary-4p7f</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Object.create() // TypeError: Object prototype may only be an Object or null
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Object.create(null) //[Object: null prototype] {}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Object.create({}) // {}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;The second one is a data dictionary, because it is an object without a parent.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It creates an object that has an empty [[Prototype]] binding (also known as null), and therefore this object cannot delegate anywhere. &lt;/p&gt;

&lt;p&gt;As an object of this type does not have a prototype chain, the &lt;em&gt;&lt;strong&gt;instanceof&lt;/strong&gt;&lt;/em&gt; operator has nothing to check, so it will always return false. &lt;/p&gt;

&lt;p&gt;These special empty [[Prototype]] objects are often called "dictionaries" as they are typically only used to store data in properties, most of the time because they have no surprise effect coming from any delegated property/function in the chain [[Prototype]], and therefore are only used for data storage.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof"&gt;The &lt;strong&gt;&lt;em&gt;instanceof&lt;/em&gt;&lt;/strong&gt; operator tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object. The return value is a boolean value.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Constructors&lt;/em&gt;&lt;/strong&gt;, in javaScript, it is more appropriate to say that, a "constructor" is any function called with a "new" keyword before it. &lt;strong&gt;&lt;em&gt;Functions are not constructors&lt;/em&gt;&lt;/strong&gt;, but function calls are "constructor calls" if and only if "new" is used.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>node</category>
    </item>
    <item>
      <title>[Javascript] - Arrays</title>
      <dc:creator>Bruno Moura</dc:creator>
      <pubDate>Thu, 09 Nov 2023 01:58:19 +0000</pubDate>
      <link>https://dev.to/bruno8moura/javascript-arrays-2egd</link>
      <guid>https://dev.to/bruno8moura/javascript-arrays-2egd</guid>
      <description>&lt;p&gt;An object, {}, can look like an array, e.g.&lt;/p&gt;

&lt;p&gt;const x = {}&lt;br&gt;
x[0] = 1 // works&lt;br&gt;
console.log(x[0]) // works&lt;br&gt;
console.log(x.0) // doesn't work&lt;br&gt;
const [first] = x // doesn't work, non-iterable object&lt;/p&gt;

&lt;p&gt;For example, arrays are by default converted(auto-coercion allowed, means signal “==“ ) to strings by simply joining all the values ​​with commas (,) between them. You might think that two arrays with the same content are equal ==, when in fact they are not:&lt;/p&gt;

&lt;p&gt;var a = [1,2,3];&lt;br&gt;
var b = [1,2,3];&lt;br&gt;
var c = "1,2,3";&lt;/p&gt;

&lt;p&gt;a == c; // true&lt;br&gt;
b == c; // true&lt;br&gt;
a == b; // false&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>node</category>
    </item>
    <item>
      <title>dotenv and typescript</title>
      <dc:creator>Bruno Moura</dc:creator>
      <pubDate>Sat, 15 Oct 2022 09:14:18 +0000</pubDate>
      <link>https://dev.to/bruno8moura/dotenv-and-typescrypt-286</link>
      <guid>https://dev.to/bruno8moura/dotenv-and-typescrypt-286</guid>
      <description>&lt;p&gt;When we are developing our app, it is very important to put things in its right place.&lt;/p&gt;

&lt;p&gt;Here, I'm talking about "typescript" with "dotenv".&lt;/p&gt;

&lt;p&gt;They are two powerful tool that increases considerably the development speed.&lt;/p&gt;

&lt;p&gt;In order we can do that, we can do something like this,&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;.env&lt;/strong&gt; file must exists in root application path.&lt;/p&gt;

&lt;h3&gt;
  
  
  package.json
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"scripts": {
...
    "dev": "ts-node-dev --transpile-only -r dotenv/config -- src/main/server.ts",
...
  },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That way, we don´t "dirty" our code when we have to load local env variables for our app.&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>dotenv</category>
      <category>env</category>
      <category>environmentvariable</category>
    </item>
    <item>
      <title>An overview about Microservices</title>
      <dc:creator>Bruno Moura</dc:creator>
      <pubDate>Thu, 27 Aug 2020 10:07:07 +0000</pubDate>
      <link>https://dev.to/bruno8moura/an-overview-about-microservices-8f7</link>
      <guid>https://dev.to/bruno8moura/an-overview-about-microservices-8f7</guid>
      <description>&lt;p&gt;The microservice's core is performance, is all about performance.&lt;/p&gt;

&lt;p&gt;A strategy that born from the experience market, the need of scale, to serve more and more requests.&lt;/p&gt;

&lt;p&gt;A point that have to be clear is when we increasing the positive points, what we doing is increasing the negative ones as well. So the success of a microservices' architecture is a well defined strategy to deal with the all complexity that born with that type of approach.&lt;/p&gt;

&lt;p&gt;The microservice's strategy is not only about manage the software's life cycle but how to organize your business in order to reflect it in your teams as well.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Microservices are small&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.rea-group.com/blog/micro-services-what-even-are-they/"&gt;Two weeks is a good start point when we think about re-built an entire microservice.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is where things start to get interesting...&lt;/p&gt;

&lt;p&gt;Let's think about the meaning 'small enough',&lt;/p&gt;

&lt;p&gt;Software is about automate routines.&lt;/p&gt;

&lt;p&gt;A way that we do the things cheaper, structured, organized, patterned, etc.&lt;/p&gt;

&lt;p&gt;Software is located in the middle, not the end of your business.&lt;/p&gt;

&lt;p&gt;If we don't have a context to use it, the software there isn't a meaning.&lt;/p&gt;

&lt;p&gt;So, we can say here that 'small enough' depending  on your business, your context.&lt;/p&gt;

&lt;p&gt;How small can be the smallest routine of your business? &lt;/p&gt;

&lt;p&gt;The response is a routine(service) that do only one thing but do it very well and can be re-built  within around two weeks.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Autonomous&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Microservice is totally separate entity, there is no dependency to deploy it and is a good practice think about deploy every microservice into a new machine(container?).&lt;/p&gt;

&lt;p&gt;All that isolation results on more complexity, but nowadays there are many technologies that help us to mitigate it.&lt;/p&gt;

&lt;p&gt;All communication is made via network calls to enforce low coupling.&lt;/p&gt;

&lt;p&gt;When we are talking about autonomy it means that the service need to be change without concern if the client or another service will be affected. We need to think about what our service will expose and what will be hidden. Because these thing decrease the microservice autonomy.&lt;/p&gt;

&lt;p&gt;What we are seeking when creating a new microservice is...&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Can you make a change to a service and deploy it by itself without changing anything else?&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Technology Heterogeneity&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;With microservices result in a bunch independent services from which we can take advantages, like using different technologies' stacks that lead us to solve different problems.&lt;/p&gt;

&lt;p&gt;If there is a part of our systems that is facing performance problems, for instance, we can select a better one technology's stack to solve this problem. That way we are totally concern about to solve the problem and not about to solve the problem limited to follow a pre-established development standard.&lt;/p&gt;

&lt;p&gt;And, of course, everything is a trade-off. All that flexibility comes with overhead.&lt;/p&gt;

&lt;p&gt;Different stacks don't reuse the same library, for instance. Once we have different platforms.&lt;/p&gt;

&lt;p&gt;Some companies(Netflix and Twitter for example), mostly use Java Virtual Machine as a platform, as they have a very good understanding of the reliability and performance of that system.&lt;/p&gt;

&lt;p&gt;Again, If we can rewrite a microservice in two weeks, we may well mitigate the risks of embracing new technology.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Resilience&lt;/strong&gt;
&lt;/h3&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Monolithic world&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;In a &lt;em&gt;monolithic architecture&lt;/em&gt;, only one service/system is responsible by many tasks), if it fails, everything the system is responsible stops working(API, UI, Batch routines, etc).&lt;/p&gt;

&lt;p&gt;The way to mitigate a general fail is running multiples instances of that system.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Microservice world&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Provides us the ability to deal with a fail, isolate it and allow the rest of system keep working. Every microservice is responsible for only one task.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Scaling&lt;/strong&gt;
&lt;/h3&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Monolithic world&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;No matter if only one part of the system that is more requested, the entire system has to be scaled(two or more instances). It means much more computational resources to increase system's availability.&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F8xc6mcjnkg7p1q6t2e0e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F8xc6mcjnkg7p1q6t2e0e.png" alt="Monolithic scaling" width="619" height="628"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Microservice world&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;When a service have to be scaled, the other parts of a system know nothing about that. Only one functionality will have your performance increased and the rest of the system continuous working normally.&lt;/p&gt;

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

&lt;h3&gt;
  
  
  &lt;strong&gt;Deployment&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;If an application is composed of many parts, when we have to deploy, it means that we will deploy just a piece, a limited part of the system. We don't have to deal with the risk of deploy the entire system. In case of problem with that small part, only that part will be unavailable instead of entire system. Once the risk is lower, the incidence of deploys increases.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Composability&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;SOA(Service Oriented Architecture) bring us the reuse of functionalities. Next to that, Microservices allow us consuming the functionalities in different ways for different purposes.&lt;/p&gt;

&lt;p&gt;As the companies evolves, the architecture has to be flexible in the way to support the business needs, to do that we need to build things in different ways.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Optimizing for Replaceability&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Change the entire microservice is a task that is not involve a big headache at all, because microservices are small by your nature.&lt;/p&gt;

&lt;p&gt;Who never worked by a company with a big old system, a legacy one, that is the company's heart, that no one wants touch it?&lt;/p&gt;

&lt;p&gt;And if no one wants to touch that system why hasn't that system been changed? We know why, because it is vital to the company and there is a high risk involved.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;SOA - Service Oriented Architecture&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Are routines(services) that communicate each other through network calls rather than method calls within only one process.&lt;/p&gt;

&lt;p&gt;SOA emerged as an alternative to monolithic systems.&lt;/p&gt;

&lt;p&gt;SOA promote the reuse of services. Where the service has a well designed interface based on a concise semantic.&lt;/p&gt;

&lt;p&gt;No matter where you are in the company, a service can be used by different areas or even, once outside the company, can be selling as company's resource in order to open new business.&lt;/p&gt;

&lt;p&gt;In my opinion, what are doing in practice are simple webservices. Taking the data from one node to another over network. What I means is a Service(note the upper case 'S') is an entity, there is more than transport data one point to another. When we reach the usability characteristic of the Service, it transcending over the company. The Service transform the company's business.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Summary&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;In that article, I'm introducing the microservice approach and bringing more information to help when decided to implement it.&lt;/p&gt;

&lt;p&gt;All I'm talking here is based from book,&lt;br&gt;
&lt;strong&gt;Building Microservices: Designing Fine-Grained Systems by Sam Newman&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Cover Picture credits: &lt;span&gt;Photo by &lt;a href="https://unsplash.com/@clintadair?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Clint Adair&lt;/a&gt; on &lt;a href="https://unsplash.com/s/photos/network?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Unsplash&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>microservices</category>
      <category>soa</category>
    </item>
    <item>
      <title>React, how to use useState() method</title>
      <dc:creator>Bruno Moura</dc:creator>
      <pubDate>Wed, 17 Jun 2020 18:31:37 +0000</pubDate>
      <link>https://dev.to/bruno8moura/react-a-simple-use-of-usestate-method-8p1</link>
      <guid>https://dev.to/bruno8moura/react-a-simple-use-of-usestate-method-8p1</guid>
      <description>&lt;p&gt;When I started the use with React, a thing that bodereds me was the method useState().&lt;/p&gt;

&lt;p&gt;So I understood that we have two types of storage when working with React,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Memory storage and;&lt;/li&gt;
&lt;li&gt;Component storage,&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And finally, with that vision, I managed to absorbed the knowledge about the use of useState() method.&lt;/p&gt;

&lt;p&gt;After that, I built a gif to turn my words clear,&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fkurztbmpjvihyzehfkpr.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fkurztbmpjvihyzehfkpr.gif" alt="Memory storage x Component storage" width="974" height="696"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Summing up, you can change values without useState(), but what you're changing is the value in browser's memory, not in the React Component. To do that you have to use useState().&lt;/p&gt;

&lt;p&gt;That's all folks!&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>html</category>
    </item>
    <item>
      <title>Why am'I using the webpack tool?</title>
      <dc:creator>Bruno Moura</dc:creator>
      <pubDate>Wed, 10 Jun 2020 18:02:05 +0000</pubDate>
      <link>https://dev.to/bruno8moura/why-am-i-using-the-webpack-tool-4h14</link>
      <guid>https://dev.to/bruno8moura/why-am-i-using-the-webpack-tool-4h14</guid>
      <description>&lt;p&gt;Everyone today is using webpack tool. When we enter the webpack website the first information that we see is,&lt;/p&gt;

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

&lt;p&gt;But, let me step back and ask something… Do I really know what that means?&lt;/p&gt;

&lt;p&gt;So, doing a superficial analysis I can understand that we have many assets from same type and then webpack compile into only one, e.g. there are the files a.js, b.js, c.js and then after perform webpack we have only “abc.js”, or “main.js”, whatever. And that’s it. It is what I’am getting from this image.&lt;/p&gt;

&lt;p&gt;Webpack is a tool that so many people and companies using today, to understand the reason of its popularity, we have to expose the problem that webpack solves and then we finally can bring light to the darkness.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Let’s begin with “What is HTTP Protocol”?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The word protocol means, &lt;a href="https://dictionary.cambridge.org/pt/dicionario/ingles/protocol"&gt;the system of rules that produces a expected behavior&lt;/a&gt;. According to this, make sense that there is a well defined protocol to exchange information through internet, once any type of data is supported, so a patterned one fits well.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Overview"&gt;HTTP&lt;/a&gt; messages is &lt;a href="https://stackoverflow.com/questions/393407/why-http-protocol-is-designed-in-plain-text-way"&gt;pure text&lt;/a&gt; but a well structured one, becoming it in a protocol.&lt;/p&gt;

&lt;p&gt;The HTTP specification can be find &lt;a href="https://tools.ietf.org/html/rfc2616"&gt;here&lt;/a&gt; and is held by &lt;a href="https://www.ietf.org/"&gt;Internet Engineering Task Force&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Http Server&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In short, is a software that serves static assets using HTTP protocol. Is a implementation of the &lt;a href="https://tools.ietf.org/html/rfc2616"&gt;HTTP specification&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Here I will use the npm module &lt;a href="https://www.npmjs.com/package/http-server"&gt;http-server&lt;/a&gt;, but you are free to choose any other implementation, e.g &lt;a href="https://httpd.apache.org/"&gt;apache http server&lt;/a&gt;, to replicate what is exposed here in this article.&lt;br&gt;&lt;br&gt;
Let’s install the http server,   &lt;/p&gt;

&lt;pre&gt;$ npm i -g http-server&lt;/pre&gt;
    

&lt;p&gt;And now start the server,&lt;/p&gt;

&lt;pre&gt;
&amp;gt; ~$ http-server dist/
&amp;lt; Starting up http-server, serving /dist
&amp;lt; Available on:
&amp;lt; http://127.0.0.1:8080
&amp;lt; http://192.168.0.25:8080
&lt;/pre&gt;

&lt;p&gt;in order to server everything under folder dist/ and port 8080. The entry point is dist/index.html.&lt;/p&gt;

&lt;p&gt;You can change this behavior, but I will not cover it here ok? :)&lt;/p&gt;

&lt;p&gt;Let’s test our http server using a tool called &lt;a href="https://curl.haxx.se/docs/manual.html"&gt;curl&lt;/a&gt;, a command line tool,&lt;/p&gt;

&lt;pre&gt;
$ curl http://localhost:8080 -v
&amp;gt; GET / HTTP/1.1
&amp;gt; Host: localhost:8080
&amp;gt; User-Agent: curl/7.58.0
&amp;gt; Accept: \*/\*
&amp;gt; 
&amp;lt; HTTP/1.1 200 OK
&amp;lt; server: ecstatic-3.3.2
&amp;lt; cache-control: max-age=3600
&amp;lt; last-modified: Tue, 21 Apr 2020 10:38:02 GMT
&amp;lt; etag: W/"3674320-600-2020-04-21T10:38:02.508Z"
&amp;lt; content-length: 600
&amp;lt; content-type: text/html; charset=UTF-8
&amp;lt; Date: Tue, 21 Apr 2020 10:38:19 GMT
&amp;lt; Connection: keep-alive
&amp;lt; 
&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;!-- &amp;lt;link rel="icon" href="http://localhost:8080/favicon.ico?v=2" /&amp;gt; --&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;link rel="stylesheet" href="table/position.css"&amp;gt;
    &amp;lt;link rel="stylesheet" href="table/color.css"&amp;gt;
    &amp;lt;link rel="stylesheet" href="table/layout.css"&amp;gt;
    &amp;lt;script src="https://code.jquery.com/jquery-3.5.0.min.js" integrity="sha256-xNzN2a4ltkB44Mc/Jz3pT4iU1cmeR0FkXs4pru/JxaQ=" crossorigin="anonymous"&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;title&amp;gt;Hello World&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;div id="app"&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;script type="module" src="./main.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/pre&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Notice that, with curl, only one file is downloaded, the index.html.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Everything that starts with ‘&amp;gt;’ we are sending and everything that starts with ‘&amp;lt;’ we are receiving from the http server, i.e. request and response respectively.&lt;/p&gt;

&lt;p&gt;The HTTP Request always will look like that, some header can be added or removed, but the structure will be always that way.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Using a browser client&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Let’s make the same request on Google Chrome. Notice the client(browser) request many files to the server in order to display the complete html page.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Some tags into html file, e.g. &amp;lt;script&amp;gt;, &amp;lt;link&amp;gt;, etc, make a new request to the server, and that is the reason in which that we see many request besides that we did.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

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

&lt;p&gt;Notice, when we open the chrome developer tools, in network tab is allowed to see files being downloaded in order to present the page that we requested.&lt;/p&gt;

&lt;p&gt;Each file is a entirely new request for the server, note the http headers,&lt;/p&gt;

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

&lt;p&gt;And requests takes time to do their job done,&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fgne9x2dj2c6eg47a8odn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fgne9x2dj2c6eg47a8odn.png" alt="Request processing time" title="Request processing time" width="800" height="413"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When we type “localhost:8080” into browser toolbar we are requesting a information. The browser know how to deal with HTML language and when it finds a resource that needed by file HTML, the browser make a new request in order to mount the graphic view.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;And what about performance? Is the page loading fast enough?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;This characteristic is called non-functional requirement, meaning that what limits we have to design, or build, our application. No matter if your site is beautiful and use the latest technologies, if it doesn’t do the things fast enough then we won’t have satisfied users, i.e. users happy with our brand, users are buying in our site, returning to it and speaking well about it as well.&lt;/p&gt;

&lt;p&gt;Based on what has been shown so far, what the first thing that we get think in order to get a better performance?&lt;/p&gt;

&lt;p&gt;...   &lt;/p&gt;

&lt;p&gt;Decrease the size of files that will be downloaded by the client.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Minimizing Resources&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://developers.google.com/speed/docs/insights/MinifyResources"&gt;Minification is the process of removing unnecessary or unnecessary data without affecting the way resources are processed by the browser.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When we write the files, .html for instance, we need do it in a way that we, or any other person, is able to understand and maintain the code. All the comments and indentations is for us humans, not for computers.&lt;/p&gt;

&lt;p&gt;Let’s see an example a code structured and commented,&lt;/p&gt;

&lt;pre&gt; 
&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;!-- &amp;lt;link rel="icon" href="http://localhost:8080/favicon.ico?v=2" /&amp;gt; --&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;link rel="stylesheet" type="text/css" href="table/position.css"&amp;gt;
    &amp;lt;link rel="stylesheet" type="text/css" href="table/color.css"&amp;gt;
    &amp;lt;link rel="stylesheet" type="text/css" href="table/layout.css"&amp;gt;
    
    &amp;lt;!-- importing jquery --&amp;gt;
    &amp;lt;script src="jquery-3.5.0.js"&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;title&amp;gt;Hello World&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;div id="app"&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;script type="module" src="./main.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/pre&gt;

&lt;p&gt;That way we can understand the code, so it is possible to fix a possible bug or make an improvement.&lt;/p&gt;

&lt;p&gt;How was shown above, the browser understand it as well and processes the html file with success.&lt;/p&gt;

&lt;p&gt;One point to notice is, a file formatted that way have a size,&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ftnmngtexod5q7grfzl41.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ftnmngtexod5q7grfzl41.png" alt="Size of index.html in bytes." title="Size of index.html in bytes." width="800" height="40"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we’ll minify that same file in which we’ll be deleting comments and indentation, I will use the tool willpeavy.com to minify the assests,&lt;/p&gt;

&lt;pre&gt;
&amp;lt;!DOCTYPE html&amp;gt;&amp;lt;html lang="en"&amp;gt;&amp;lt;head&amp;gt; &amp;lt;meta charset="UTF-8"&amp;gt; &amp;lt;link rel="stylesheet" type="text/css" href="table/position.css"&amp;gt; &amp;lt;link rel="stylesheet" type="text/css" href="table/color.css"&amp;gt; &amp;lt;link rel="stylesheet" type="text/css" href="table/layout.css"&amp;gt; &amp;lt;script src="jquery-3.5.0.js"&amp;gt;&amp;lt;/script&amp;gt; &amp;lt;title&amp;gt;Hello World&amp;lt;/title&amp;gt;&amp;lt;/head&amp;gt;&amp;lt;body&amp;gt; &amp;lt;div id="app"&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;script type="module" src="./main.js"&amp;gt;&amp;lt;/script&amp;gt;&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;
&lt;/pre&gt;

&lt;p&gt;The browser continues understand and processing the html file,&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fitze0ey7dshzthj0zs7f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fitze0ey7dshzthj0zs7f.png" alt="index.html shown in a browser." title="index.html shown in a browser." width="800" height="412"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Resulting in a new size,&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fc3zh7pqg3khohw3sxi7i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fc3zh7pqg3khohw3sxi7i.png" alt="Size of index.html in bytes." title="Size of index.html in bytes." width="800" height="51"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Following that reasoning line, we can do more. So let’s minify the .js and CSSs files as well.&lt;/p&gt;

&lt;p&gt;The .js assets we have 2322,6 bytes,&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fdwxiodha2yn97gqlcnjm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fdwxiodha2yn97gqlcnjm.png" alt="Size of .js files in bytes." title="Size of .js files in bytes." width="800" height="309"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That minified we have 1615,5 bytes,&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Faszl1v21wz67vrmdd1e3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Faszl1v21wz67vrmdd1e3.png" alt="Size in bytes of .js assets." title="Size in bytes of .js assets." width="800" height="323"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;CSSs assets we have tree of them that summed 323 bytes,&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F4in6pq6252hlya3ae9zc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F4in6pq6252hlya3ae9zc.png" alt="Size in bytes of .css assets." title="Size in bytes of .css assets." width="800" height="130"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When each is minified we have 104 bytes,&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fix0mwybl8b4qgb6w85o0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fix0mwybl8b4qgb6w85o0.png" alt="Size in bytes of .css assets minified." title="Size in bytes of .css assets minified." width="800" height="137"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And the browser continues to understand and processes the files successfully,&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Favjtdnk0c4m7kns1q4qm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Favjtdnk0c4m7kns1q4qm.png" alt="index.html shown in a browser." title="index.html shown in a browser." width="800" height="412"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But three CSSs files? Why not only one? This would result in only one request and consequently, less time for the client receive all assets by the server. Let’s put all CSSs contents in one file and called it bundle.css,&lt;/p&gt;

&lt;pre&gt;
table{background-color: aqua;}table, th, td{border: 1px solid black; padding: 10px;}table{margin: 0 auto;}
&lt;/pre&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fj6dar66l9k6zgn4ogfhj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fj6dar66l9k6zgn4ogfhj.png" alt="Size in bytes of .css assets." title="Size in bytes of .css assets." width="800" height="48"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As we create a new asset, we need to modify our index.html in order it find that new asset and load. We minify the index.html, so it’s a little more hard to alter that, but we are pros, we’ll get it!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;We can revert the minification to a formatted file and then alter or we can alter the file minified as well, whatever, but we need alter it.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Once altered the index.html to point the right path to the new asset the browser continues rendering the page,&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fazw1v9bjszfauwa2y7xi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fazw1v9bjszfauwa2y7xi.png" alt="Size in bytes of .js assets." title="Size in bytes of .js assets." width="800" height="315"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s create another new asset, bundle.js, and put all content of .js files in it,&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;To do that we will have to deal with some hassles in order to get merge all files in only one and don’t forget that we need modify our index.html again, but we’ll get it! go go go!&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5qn29xx41s7tndq1vkyi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5qn29xx41s7tndq1vkyi.png" alt="Size in bytes of .js assets." title="Size in bytes of .js assets." width="800" height="51"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And the application continues to work,&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F9oqka54ic4y9rbadiodh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F9oqka54ic4y9rbadiodh.png" alt="index.html shown in a browser." title="index.html shown in a browser." width="800" height="408"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And now? What about the time the performance? When we look at the dev tools is possible to see the decrease of size of files and, consequently, the load page time as well.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;At the footer of each image there are some informations that means,&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;requests: requests made by the client to the server&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;transferred: bytes transferred over network&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;resources: bytes loaded by the page&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Finish: time to load all assets and show the page&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;DOMContentLoaded: time to load only the DOM(HTML)&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Load: time to load the DOM and its dependencies&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fw1z66u7205je6djtz1xy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fw1z66u7205je6djtz1xy.png" alt="None of assets were minified or bundled." title="None of assets were minified or bundled." width="800" height="187"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fpm8ox7ktmzcc4sp4vrds.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fpm8ox7ktmzcc4sp4vrds.png" alt="Assets were minified but not bundled." title="Assets were minified but not bundled." width="800" height="186"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fi1nknp81t3kfvwayrfr6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fi1nknp81t3kfvwayrfr6.png" alt="Assets were minified and bundled." title="Assets were minified and bundled." width="800" height="85"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Looking at the informations above, is easy to see that application now is spending less time to load, means that we get a better performance.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;But the only constant is change…&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;And how about now? After all changes we made to get a better performance, how can we get continuous changing things and formatting all the code to reach a better performance? The natural trend the applications is grow, that means more assets for minify and bundling. We won’t be able to deal with because in any moment a simple change would be result in so many time to implement. And if, nevertheless, do we decided use a new tecnology? We will have to deal with that as well.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Webpack to the rescue!&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;As we just saw, before webpack we had to deal with all these things. We had to know the every detail of our application like file dependencies each other, if a file is being really used, etc.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Webpack is able to bundle any static resource. You are free to build a any tupe of loader.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Just to make sure that we are in the same point, let’s do a very simple usage of webpack with the previously application introduced.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://webpack.js.org/concepts/#output"&gt;Out of the box, webpack bundle only javascript files.&lt;br&gt;
It searches for index.js into ./src and put the new generated asset, main.js, into /dist&lt;/a&gt;. Let’s see an example.&lt;/p&gt;

&lt;p&gt;Our structure project is,&lt;/p&gt;

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

&lt;p&gt;Within the folder &lt;em&gt;withwebpack&lt;/em&gt;, firstly we need rename the file &lt;em&gt;main.js&lt;/em&gt; to &lt;em&gt;index.js&lt;/em&gt; in order webpack get its job done,&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ mv src/main.js src/index.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F0vhzuo6kfiewtkwjb625.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F0vhzuo6kfiewtkwjb625.png" alt="main.js renamed to index.js" title="main.js renamed to index.js" width="348" height="156"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After, we will init a node project and install the two modules needed by webpack,&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ npm init -y &amp;amp;&amp;amp; npm i webpack webpack-cli --save-dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Three new artifacts will appeared,&lt;/p&gt;

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

&lt;p&gt;And now, run webpack,&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ npx webpack
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;And that’s it. The output will be within the /dist.&lt;/p&gt;

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

&lt;p&gt;That way we get keep our structure organized and we don’t need to deal with by ourselves all minification and bundling hassles and sure, we gain a better performance.&lt;/p&gt;

&lt;p&gt;When we open the main.js, we can see a lot of javascript code. Analyzing the first part, we can see &lt;a href="https://webpack.js.org/guides/getting-started/#modules"&gt;how webpack solves the transpilation, translation/compilation, in order to fit for the older browsers’ compabilities.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the last part we find our javascript code, slightly altered but not its functionality, in order to fits in the generated bundle by webpack. Let’s see how it turned out,&lt;/p&gt;

&lt;pre&gt;function(e){var t={};function r(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&amp;amp;&amp;amp;Symbol.toStringTag&amp;amp;&amp;amp;Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&amp;amp;t&amp;amp;&amp;amp;(e=r(e)),8&amp;amp;t)return e;if(4&amp;amp;t&amp;amp;&amp;amp;"object"==typeof e&amp;amp;&amp;amp;e&amp;amp;&amp;amp;e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&amp;amp;t&amp;amp;&amp;amp;"string"!=typeof e)for(var i in e)r.d(n,i,function(t){return e[t]}.bind(null,i));return n},r.n=function(e){var t=e&amp;amp;&amp;amp;e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){"use strict";r.r(t);class n{constructor(){this._field=""}tr(e){return this._field=`&lt;tr&gt;${e}&lt;/tr&gt;`,this}create(){return this._field}}class i{constructor(){this._field=""}td(e){return this._field=`&lt;td&gt;${e}&lt;/td&gt;`,this}create(){return this._field}}class o{constructor(){this._field=""}th(e){return this._field=`&lt;th&gt;${e}&lt;/th&gt;`,this}create(){return this._field}}let u=new class{constructor(e,t){this._rows=[];let r="";e.map(e=&amp;gt;{r+=(new o).th(e).create()}),this._rows.push((new n).tr(r).create()),t.map(e=&amp;gt;{let t="";Object.keys(e).map(r=&amp;gt;t+=(new i).td(e[r]).create()),this._rows.push((new n).tr(t).create())})}create(){return`&lt;/pre&gt;
&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;\n            ${this._rows.join("")}\n        &lt;/table&gt;&lt;/div&gt;`}}(["Name","Age"],[{name:"Bruno",age:33},{name:"Daniela",age:32}]).create();document.querySelector("#app").innerHTML=u}]);


&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Our code starts around when the word class appears for the first time. Here we have only javascript code.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;And the CSSs?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://webpack.js.org/concepts/modules/#supported-module-types"&gt;As I said before, webpack is a resource’s bundler and we just need teach him to bundle a resource type(loader) and what resource(file) it’ll bundle.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In order to bundle the CSS files, we must install a new loader,&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ npm i css-loader --save-dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Always we need a alike behavior from “out of the box”, webpack requires a configuration. We get that using the file webpack.config.js, so let create it,&lt;/p&gt;

&lt;pre&gt;
const path = require('path');

module.exports = {
    entry: [
        './src/index.js',
        './src/table/color.css',
        './src/table/position.css',
        './src/table/layout.css',
    ],
    output: {
        filename: 'bundle.js',
        path: path.resolve(__dirname, 'dist'),
    },
    module: {
        rules: [
            
            {
                test: /\.css$/,
                use: [ 'css-loader', ],
            }
        ]
    }
}
&lt;/pre&gt;

&lt;p&gt;The entry node means the start point that webpack will create its dependency graph. I configured the index.js as well because we need it to build the table within html file and the three css files that exists in the project, because there isn’t dependency between them.&lt;/p&gt;

&lt;p&gt;Actually, in real world, I think that isn’t used, at least I have never seen. Later, I will show how to use css files with import reserved word within a javascript file.&lt;/p&gt;

&lt;p&gt;The module node define how each module will be treated. Here I defined that every file .css will be transpiled with css-loader, means that teaching to webpack how to deal with css’ particularities and put it into generated bundle, just it, the css won’t be applied to any file. When we run webpack and start the http server, the result is our table without style,&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fevksyn4rlhnnpprr5pge.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fevksyn4rlhnnpprr5pge.png" alt="An html page without style." title="An html page without style." width="800" height="413"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But the css is contained within the bundle.js,&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F8qy6uy7eqhpuuhmnpsok.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F8qy6uy7eqhpuuhmnpsok.png" alt="bundle.js file" title="bundle.js file" width="800" height="192"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So that we can inject the css into the DOM we need install another loader, &lt;a href="https://webpack.js.org/loaders/style-loader/"&gt;style-loader&lt;/a&gt;.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ npm i style-loader --save-dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Configuring it in webpack.config.js,&lt;/p&gt;

&lt;pre&gt;
const path = require('path');

module.exports = {
    entry: [
        './src/index.js',
        './src/table/color.css',
        './src/table/position.css',
        './src/table/layout.css',
    ],
    output: {
        filename: 'bundle.js',
        path: path.resolve(__dirname, 'dist'),
    },
    module: {
        rules: [
            
            {
                test: /\.css$/,
                use: [ 'style-loader', 'css-loader', ],
            }
        ]
    }
}
&lt;/pre&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Pay atention the loaders’ order. They are performed from right to left, thus the css-loader will be run first and the style-loader will be the next, i.e. the CSSs will be translated to be then will be injected within the html.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Restarting the server,&lt;/p&gt;

&lt;pre&gt;
$ http-server dist/
Starting up http-server, serving dist/
Available on:
  http://127.0.0.1:8080
  http://192.168.0.13:8080
Hit CTRL-C to stop the server
&lt;/pre&gt;

&lt;p&gt;Refreshing the page,&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F4lp5ftpaxutl2caaxjl6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F4lp5ftpaxutl2caaxjl6.png" alt="An html page with style." title="An html page with style." width="800" height="398"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And there it is!&lt;/p&gt;

&lt;p&gt;But let’s get better the configuration in webpack.config.js file, removing all three css entries,&lt;/p&gt;

&lt;pre&gt;
const path = require('path');

module.exports = {
    entry: './src/index.js',
    output: {
        filename: 'bundle.js',
        path: path.resolve(__dirname, 'dist'),
    },
    module: {
        rules: [
            
            {
                test: /\.css$/,
                use: [ 'style-loader', 'css-loader', ],
            }
        ]
    }
}
&lt;/pre&gt;

&lt;p&gt;And importing them into Table.js file,&lt;/p&gt;

&lt;pre&gt;
import Row from './Row.js';
import Column from './Column.js';
import Header from './Header.js';

import color from './color.css';
import position from './position.css';
import layout from './layout.css';

export default class Table {
    constructor(tableHeader, tableData){
        this._rows = [];
        
        let headersRow = '';
        tableHeader.map( header =&amp;gt; {
            headersRow += new Header().th(header).create();
        });
        this._rows.push(new Row().tr(headersRow).create());

        tableData.map(data =&amp;gt; {
            let dataRow = '';
            Object.keys(data).map( field =&amp;gt; dataRow += new Column().td(data[field]).create());
            this._rows.push( new Row().tr(dataRow).create() );
        });
    }

    create(){
        return `&amp;lt;table&amp;gt;
            ${this._rows.join('')}
        &amp;lt;/table&amp;gt;`;
    }
}
&lt;/pre&gt;

&lt;p&gt;Running webpack again and restaring the server, the result is the same before,&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fzo65igxrg84bnw88ake8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fzo65igxrg84bnw88ake8.png" alt="An html page with style." title="An html page with style." width="800" height="416"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Minify CSSs file&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In order to extract the css’s code from js file and put it in a totally new file, we’ll use the &lt;a href="https://webpack.js.org/plugins/mini-css-extract-plugin/#getting-started"&gt;plugin mini-css-extract-plugin&lt;/a&gt;,&lt;/p&gt;

&lt;p&gt;Install it,&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ npm i mini-css-extract-plugin --save-dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://webpack.js.org/concepts/#plugins"&gt;About the Plugins, while a loader teach webpack how to deal with a specific file type, plugin do things like minify, remove code’s comments and spaces, etc.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s to alter our webpack.config.js,&lt;/p&gt;

&lt;pre&gt;

const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');

module.exports = {
    plugins: [
        new MiniCssExtractPlugin(),
    ],
    entry: './src/index.js',
    output: {
        filename: 'bundle.js',
        path: path.resolve(__dirname, 'dist'),
    },
    module: {
        rules: [

            {
                test: /\.css$/,
                use: [
                    MiniCssExtractPlugin.loader,
                    'css-loader',
                ],
            }
        ]
    }
}
&lt;/pre&gt;

&lt;p&gt;And when we run webpack again, the result is a new ./dist/main.css file bundling the all three css files,&lt;/p&gt;

&lt;pre&gt;
/* 
 * file: color.css 
 *
 * Sets the table's colors 
 */
table {
    background-color: aqua;
};
/* 
 * file: position.css 
 *
 * Sets the table's position on a screen 
 */
table {
    margin: 0 auto;
};
/* 
 * file: layout.css 
 *
 * Sets the table's layout 
 */
table, th, td {
    border: 1px solid black;
    padding: 10px;
};
&lt;/pre&gt;

&lt;p&gt;Now we’ll minify and remove the comments, let’s install another plugin,&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ npm i optimize-css-assets-webpack-plugin --save-dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Modifying the webpack.config.js,&lt;/p&gt;

&lt;pre&gt;
const path = require('path');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');

module.exports = {
    plugins: [        
        new MiniCssExtractPlugin(),
        new OptimizeCSSAssetsPlugin({
            cssProcessorPluginOptions: {
                discardComments: { removeAll: true },
            },
        }),
    ],
    entry: './src/index.js',
    output: {
        filename: 'bundle.js',
        path: path.resolve(__dirname, 'dist'),
    },
    module: {
        rules: [

            {
                test: /\.css$/,
                use: [
                    MiniCssExtractPlugin.loader,
                    'css-loader',
                ],
            }
        ]
    }
}
&lt;/pre&gt;

&lt;p&gt;Running,&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ npx webpack
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;And we get the ./dist/main.css minified and without comments,&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;table,td,th{border:1px solid #000;padding:10px}table{background-color:#0ff;margin:0 auto}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;And again, the application continue to work,&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fp2yqmur2mdc5u065ouxc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fp2yqmur2mdc5u065ouxc.png" alt="Html page without style." title="Html page without style." width="800" height="413"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The style is gone, once we ask to webpack to generate a new file, so it have to be requested by the html page as well, however we didn’t do that.&lt;/p&gt;

&lt;p&gt;Adding the link tag into our index.html,&lt;/p&gt;

&lt;pre&gt;
&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;link rel="stylesheet" href="main.css"&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;title&amp;gt;Hello World&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;div id="app"&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;script type="module" src="bundle.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/pre&gt;

&lt;p&gt;Refreshing the html page,&lt;/p&gt;

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

&lt;p&gt;So if we create a new asset, means that every time we have to deal with it? We’ll need to put it manually into index.html?&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Index.html with all its dependencies auto-generated&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Installing html-webpack-plugin simplifies our life because the all assets needed by html will be referenced by webpack into index.html. Let’s install it,&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ npm i html-webpack-plugin --save-dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;and setup it in webpack.config.js specifying the template in which we already have been using,&lt;/p&gt;

&lt;pre&gt;
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
    plugins: [
        new HtmlWebpackPlugin({
            template: './src/index.html'
        }),
        new MiniCssExtractPlugin(),
        new OptimizeCSSAssetsPlugin({
            cssProcessorPluginOptions: {
                discardComments: { removeAll: true },
            },
        }),
    ],
    entry: './src/index.js',
    output: {
        filename: 'bundle.js',
        path: path.resolve(__dirname, 'dist'),
    },
    module: {
        rules: [

            {
                test: /\.css$/,
                use: [
                    MiniCssExtractPlugin.loader,
                    'css-loader',
                ],
            }
        ]
    }
}
&lt;/pre&gt;

&lt;p&gt;Running,&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  $ npx webpack
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Starting the server and opening the browser,&lt;/p&gt;

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

&lt;p&gt;When we compare the spending time with and without webpack we have practically the same result in time and file’s size but, as well, we have the all facilities that webpack provide for us, no headache when evolving and keep the application.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;And that’s it. All assets generated here is available on my github.&lt;br&gt;
What I’am showing here is just a basic using of webpack, but my goal here is let you more comfortable when using that incredible tool that is very requisited by many companies out there.&lt;br&gt;
Don’t stop here, go to visit the &lt;a href="https://webpack.js.org/"&gt;webpack.js.org&lt;/a&gt; to know more the tool and have fun!&lt;br&gt;&lt;br&gt;
Useful links:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://webpack.js.org/concepts/why-webpack/"&gt;Why webpack&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://webpack.js.org/concepts/dependency-graph/"&gt;Dependency Graph&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://webpack.js.org/guides/asset-management/#setup"&gt;Asset Management&lt;/a&gt;&lt;/p&gt;

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