<?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: Aditya</title>
    <description>The latest articles on DEV Community by Aditya (@adityaj).</description>
    <link>https://dev.to/adityaj</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%2F643876%2Fa13a4e59-3fdc-41b9-99f3-5c7612ee45f0.jpeg</url>
      <title>DEV Community: Aditya</title>
      <link>https://dev.to/adityaj</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/adityaj"/>
    <language>en</language>
    <item>
      <title>Your only guide to babel in 2021</title>
      <dc:creator>Aditya</dc:creator>
      <pubDate>Wed, 09 Jun 2021 09:53:53 +0000</pubDate>
      <link>https://dev.to/adityaj/your-only-guide-to-babel-in-2021-1i4e</link>
      <guid>https://dev.to/adityaj/your-only-guide-to-babel-in-2021-1i4e</guid>
      <description>&lt;h2&gt;
  
  
  What's the story behind it?
&lt;/h2&gt;

&lt;p&gt;👨‍💻 I was in a search for an all-in-one article to help me get started with Babel without ever reading the whole &lt;code&gt;documentation&lt;/code&gt; but I didn't found any So, after deeply going through the &lt;code&gt;Babel docs&lt;/code&gt; I'm writing this.&lt;/p&gt;

&lt;p&gt;I assure you to move you from zero to a little less than advanced in babel but don't worry I'll also tell you important things to become advance in it.&lt;/p&gt;

&lt;p&gt;So, if you've heard about babel but never got into knowing what, why, and how about it, you should continue reading this.&lt;/p&gt;

&lt;h2&gt;
  
  
  Babel is the Middleman
&lt;/h2&gt;

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

&lt;p&gt;The left one is the user and the right one is the browser.&lt;/p&gt;

&lt;p&gt;JavaScript has evolved a lot in the previous years and the all latest features of JavaScript are not supported in many modern browsers but most of them are.&lt;/p&gt;

&lt;p&gt;Babel is the middle man(transpiler) between your modern JavaScript code and the browser you're targetting. It makes sure that whatever JavaScript you're writing will be &lt;strong&gt;compatible&lt;/strong&gt; with almost every browser out there even IE11.&lt;/p&gt;

&lt;p&gt;E.g. Opera Mini does not support &lt;code&gt;flatMap()&lt;/code&gt; as of now and babel includes an external library for it to make sure it will work on it.&lt;/p&gt;

&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;

&lt;p&gt;It uses AST to make it compiler work(that's a part of compiler design), but you don't have to know anything to make use of it to any level just remember it works upon the modern JavaScript to compile it down to ES15 that most browsers support.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use Sourcemap to map both codes.&lt;/li&gt;
&lt;li&gt;Does not do static typing as &lt;code&gt;TypeScript&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How to setup
&lt;/h2&gt;

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

&lt;p&gt;Make sure you have these&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Node.js&lt;/code&gt; (LTS or latest)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;npm&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Setup a folder with &lt;code&gt;index.js&lt;/code&gt; 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;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--save-dev&lt;/span&gt; @babel/core @babel/cli @babel/preset-env
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make a &lt;code&gt;babel.config.json&lt;/code&gt; file in the root directory of your app.&lt;/p&gt;

&lt;p&gt;For this configuration, Babel will try to find all &lt;code&gt;.js&lt;/code&gt; files in the &lt;code&gt;src&lt;/code&gt; folder so make sure you've all your files set up.&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="sb"&gt;`&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="s2"&gt;"presets"&lt;/span&gt;: &lt;span class="o"&gt;[&lt;/span&gt;
    &lt;span class="o"&gt;[&lt;/span&gt;
      &lt;span class="s2"&gt;"@babel/env"&lt;/span&gt;,
      &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="s2"&gt;"targets"&lt;/span&gt;: &lt;span class="o"&gt;{&lt;/span&gt;
          &lt;span class="s2"&gt;"edge"&lt;/span&gt;: &lt;span class="s2"&gt;"17"&lt;/span&gt;,
          &lt;span class="s2"&gt;"firefox"&lt;/span&gt;: &lt;span class="s2"&gt;"60"&lt;/span&gt;,
          &lt;span class="s2"&gt;"chrome"&lt;/span&gt;: &lt;span class="s2"&gt;"67"&lt;/span&gt;,
          &lt;span class="s2"&gt;"safari"&lt;/span&gt;: &lt;span class="s2"&gt;"11.1"&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;,
        &lt;span class="s2"&gt;"useBuiltIns"&lt;/span&gt;: &lt;span class="s2"&gt;"usage"&lt;/span&gt;,
        &lt;span class="s2"&gt;"corejs"&lt;/span&gt;: &lt;span class="s2"&gt;"3.6.5"&lt;/span&gt;
      &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;]&lt;/span&gt;
  &lt;span class="o"&gt;]&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add this to &lt;code&gt;package.json&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="s2"&gt;"build"&lt;/span&gt;: &lt;span class="s2"&gt;"./node_modules/.bin/babel src --out-dir build"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and run &lt;code&gt;npm run build&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Voila! you've done it! there will be a &lt;code&gt;build&lt;/code&gt; folder in your main directory that will contain your converted codes from src.&lt;/p&gt;

&lt;h2&gt;
  
  
  It was just the Start
&lt;/h2&gt;

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

&lt;p&gt;Now, we'll understand how it all works. Let's start with&lt;/p&gt;

&lt;h2&gt;
  
  
  Types of Babel configurations
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Project-wide configuration (New in Bable 7.x)
&lt;/h3&gt;

&lt;p&gt;It will just take a simple file &lt;code&gt;babel.config.json&lt;/code&gt; as we did above and find the &lt;code&gt;.js&lt;/code&gt; files as specified in search behavior in the &lt;code&gt;babel.config.json&lt;/code&gt; file.&lt;/p&gt;

&lt;h3&gt;
  
  
  File-relative configuration
&lt;/h3&gt;

&lt;p&gt;The setup is similar but you can use &lt;code&gt;.babelrc.json&lt;/code&gt; for it just to define it with a higher priority and for differentiating than the main config file.&lt;/p&gt;

&lt;p&gt;There can be a few edge cases when you might need it like applying babel to only a single package.&lt;/p&gt;

&lt;h4&gt;
  
  
  Important thing to remember
&lt;/h4&gt;

&lt;p&gt;File-relative configurations are also merged over top of project-wide config values, making them potentially useful for specific overrides, though that can also be accomplished through "overrides".&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's talk about what we installed with npm
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;@babel/core&lt;/code&gt; → All the core functionality of Babel resides here.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;@babel/cli&lt;/code&gt; → Babel can be used from CLI with this tool, we're able to use &lt;code&gt;npm run build&lt;/code&gt; because of this. &lt;/p&gt;

&lt;p&gt;We used the &lt;code&gt;--out-dir&lt;/code&gt; option behind the scenes that is possible because of &lt;code&gt;@babel/cli&lt;/code&gt;. Run &lt;code&gt;npm run build —help&lt;/code&gt; for more info.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;@babel/preset-env&lt;/code&gt; → This is a new preset that has been amazing, it has replaced most previous presets, It smartly adds the required libraries to ES5 code.&lt;/p&gt;

&lt;p&gt;Let's first understand this 👇.&lt;/p&gt;

&lt;h3&gt;
  
  
  Plugins
&lt;/h3&gt;

&lt;p&gt;Babel uses Plugins to perform transformations, Plugins are nothing but small JavaScript programs that instructs Babel to perform required transformations to the code.&lt;/p&gt;

&lt;h4&gt;
  
  
  Important thing
&lt;/h4&gt;

&lt;p&gt;You can write your own plugins or use official plugins like &lt;code&gt;@babel/plugin-transform-arrow-functions&lt;/code&gt; that is just a plugin to convert modern arrow functions to ES5.&lt;/p&gt;

&lt;p&gt;It simply does 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;// From this&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fn&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="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Converted to this&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;fn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;fn&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="mi"&gt;1&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;
  
  
  Coming Back to &lt;code&gt;@babel/preset-env&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;It's simply a set of plugins that can handle all the headaches of setting up plugins manually for every feature. It'll take care of your all smart code most of the time.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/fZ6bIf6SQI1gz27gCJ/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/fZ6bIf6SQI1gz27gCJ/giphy.gif" alt="You're getting it"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Polyfill
&lt;/h2&gt;

&lt;p&gt;🚨 Earlier it was part of babel but now we've to &lt;code&gt;import&lt;/code&gt; it directly with this code in your modern JS code.&lt;/p&gt;

&lt;p&gt;Polyfills are not used exclusively because of poor functionality and poor performance. Native implementations of APIs can do more and are faster than polyfills. For example, the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create#polyfill" rel="noopener noreferrer"&gt;Object.create polyfill&lt;/a&gt; only contains the functionalities that are possible in a non-native implementation of Object.create.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is Polyfill?
&lt;/h3&gt;

&lt;p&gt;A polyfill is a piece of code (usually JavaScript on the Web) used to provide modern functionality on older browsers that do not natively support it.&lt;/p&gt;

&lt;p&gt;Dear IE11&lt;br&gt;
&lt;a href="https://i.giphy.com/media/l3fQgjVoyZ1I4EyOs/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/l3fQgjVoyZ1I4EyOs/giphy.gif" alt="Old-Code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For example, a polyfill could be used to mimic the functionality of a &lt;code&gt;[text-shadow](https://developer.mozilla.org/en-US/docs/Web/CSS/text-shadow)&lt;/code&gt; in IE7 using proprietary IE filters, or mimic rem units or media queries by using JavaScript to dynamically adjust the styling as appropriate, or whatever else you require.&lt;/p&gt;

&lt;p&gt;Read in depth &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Polyfill" rel="noopener noreferrer"&gt;Mozilla Docs Polyfill&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  What about it in Babel?
&lt;/h3&gt;

&lt;p&gt;The polyfill module includes &lt;code&gt;core-js&lt;/code&gt; and a custom regenerator runtime to emulate a full ES2015+ environment.&lt;/p&gt;

&lt;p&gt;As babel has already removed it but just for the sake of knowing you can import it with this&lt;/p&gt;

&lt;p&gt;You've to use&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;// Install via &lt;/span&gt;
&lt;span class="nx"&gt;npm&lt;/span&gt; &lt;span class="nx"&gt;install&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="nx"&gt;save&lt;/span&gt; &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;babel&lt;/span&gt;&lt;span class="sr"&gt;/polyfil&lt;/span&gt;&lt;span class="err"&gt;l
&lt;/span&gt;
&lt;span class="c1"&gt;// Add via&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;core-js/stable&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;regenerator-runtime/runtime&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;h2&gt;
  
  
  Types of configuration in babel
&lt;/h2&gt;

&lt;p&gt;Four ways are listed in priority from lowest to highest.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;babel.config.json&lt;/code&gt; or inside &lt;code&gt;package.json&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;babel.config.js&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;.babelrc.json&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;programmatic options from &lt;code&gt;@babel/cli&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By &lt;strong&gt;priority&lt;/strong&gt; it simply means that &lt;code&gt;babel.config.json&lt;/code&gt; is overwritten by &lt;code&gt;.babelrc&lt;/code&gt;, and &lt;code&gt;.babelrc&lt;/code&gt; is overwritten by &lt;code&gt;programmatic options&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You can also write &lt;code&gt;babel.config.json&lt;/code&gt; and &lt;code&gt;.babelrc.json&lt;/code&gt; files using &lt;strong&gt;JavaScript&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Options
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What are babel options?
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/3o84sw9CmwYpAnRRni/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/3o84sw9CmwYpAnRRni/giphy.gif" alt="do-it-babel"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Babel options are a way to tell babel to do specific things e.g. minifying, ignoring some file, or explicitly tell babel to compile files from a specific directory while disabling everything else.&lt;/p&gt;

&lt;p&gt;Don't worry I'll explain everything I said above.&lt;/p&gt;

&lt;h3&gt;
  
  
  First understand how we can use any option
&lt;/h3&gt;

&lt;p&gt;Options are defined in your chosen config file let's say that is &lt;code&gt;babel.config.json&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"presets"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="s2"&gt;"@babel/env"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="nl"&gt;"targets"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
                    &lt;/span&gt;&lt;span class="nl"&gt;"edge"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"17"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                    &lt;/span&gt;&lt;span class="nl"&gt;"firefox"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"60"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                    &lt;/span&gt;&lt;span class="nl"&gt;"chrome"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"67"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                    &lt;/span&gt;&lt;span class="nl"&gt;"safari"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"11.1"&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="nl"&gt;"useBuiltIns"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"usage"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="nl"&gt;"corejs"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"3.6.5"&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;

        &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;To &lt;strong&gt;minify&lt;/strong&gt; your output code from babel, just add &lt;code&gt;minified&lt;/code&gt; to true like below.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"presets"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="s2"&gt;"@babel/env"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="nl"&gt;"targets"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
                    &lt;/span&gt;&lt;span class="nl"&gt;"edge"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"17"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                    &lt;/span&gt;&lt;span class="nl"&gt;"firefox"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"60"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                    &lt;/span&gt;&lt;span class="nl"&gt;"chrome"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"67"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                    &lt;/span&gt;&lt;span class="nl"&gt;"safari"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"11.1"&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="nl"&gt;"useBuiltIns"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"usage"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="nl"&gt;"corejs"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"3.6.5"&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;

        &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"minified"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Now, check your output in &lt;code&gt;build&lt;/code&gt; directory it should be minified, that basically means removing every extra space and line breaks.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;To &lt;strong&gt;ignore&lt;/strong&gt; a file, add &lt;code&gt;ignore: ["file or directory path"]&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;e.g.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="err"&gt;//&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;For&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;Files&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"ignore"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"./src/some_file.js"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt;//&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;For&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;Directory&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"ignore"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"./src"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;To &lt;strong&gt;compile only&lt;/strong&gt; a specific file or folder.&lt;br&gt;
e.g.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="err"&gt;//&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;For&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;Files&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"only"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"./src/some_file.js"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt;//&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;For&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;Directory&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"only"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"./src"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  How Babel merges conflicting configurations
&lt;/h2&gt;

&lt;p&gt;Sometimes there can be some situations where we have to specify some configurations that may result in to conflict, so to understanding how babel solves it is crucial to work with such issues.&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%2Fmedia.tenor.com%2Fimages%2F8fbe862dbf870e0ef2ba6c7e91df28de%2Ftenor.gif" 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%2Fmedia.tenor.com%2Fimages%2F8fbe862dbf870e0ef2ba6c7e91df28de%2Ftenor.gif" alt="babel-is-simple"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Babel's configuration merging is simple and predictable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Options&lt;/strong&gt; will overwrite existing &lt;strong&gt;options&lt;/strong&gt; when they are present and their value is not undefined. There are, however, a few special cases:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;For &lt;strong&gt;&lt;a href="https://babeljs.io/docs/en/assumptions" rel="noopener noreferrer"&gt;assumptions&lt;/a&gt;, &lt;a href="https://babeljs.io/docs/en/babel-parser" rel="noopener noreferrer"&gt;parserOpts&lt;/a&gt; and &lt;a href="https://babeljs.io/docs/en/babel-generator" rel="noopener noreferrer"&gt;generatorOpts&lt;/a&gt;, objects are merged&lt;/strong&gt;, rather than replaced.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For &lt;strong&gt;plugins&lt;/strong&gt; and &lt;strong&gt;presets&lt;/strong&gt;, they are replaced based on the identity of the plugin/preset object/function itself combined with the name of the entry.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Option (except plugin/preset) merging&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;As an example, consider a config with:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;This is a JavaScript config file&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&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="nl"&gt;sourceType&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;script&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;assumptions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;setClassFields&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nx"&gt;iterableIsArray&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;test&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;sourceType&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;module&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;assumptions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="na"&gt;iterableIsArray&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When &lt;code&gt;NODE_ENV&lt;/code&gt; is test, the sourceType option will be replaced and the assumptions option will be merged. The effective config is:&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="nl"&gt;sourceType&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;module&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// sourceType: "script" is overwritten&lt;/span&gt;
  &lt;span class="nx"&gt;assumptions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;setClassFields&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;iterableIsArray&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// assumptions are merged by Object.assign&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

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

&lt;p&gt;Yes!, you did it. Just keep in mind, you should read the &lt;a href="https://babeljs.io/docs/en/" rel="noopener noreferrer"&gt;&lt;code&gt;docs&lt;/code&gt;&lt;/a&gt; as well, there's a lot more stuff.&lt;/p&gt;

&lt;p&gt;Definitely read this one 👉 &lt;a href="https://babeljs.io/docs/en/options#name-normalization" rel="noopener noreferrer"&gt;&lt;strong&gt;Name Normalization&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Sometimes you'll not find an article as I didn't found one when I started writing it. So, get reading docs in your habit to really become a good Software Engineer.&lt;/p&gt;

&lt;p&gt;🙌 I'll be adding anything new I found to my repo at &lt;a href="https://github.com/Aditya9056/babel-js" rel="noopener noreferrer"&gt;Github babel-js Repo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Good Bye!&lt;/p&gt;

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

</description>
      <category>babel</category>
      <category>javascript</category>
      <category>typescript</category>
      <category>webpack</category>
    </item>
  </channel>
</rss>
