<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Abhishek Gangwar on Medium]]></title>
        <description><![CDATA[Stories by Abhishek Gangwar on Medium]]></description>
        <link>https://medium.com/@abhishek-gangwar?source=rss-5e4d50c56ac2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*l04mizmPxAGUF7CUgs4nIA.png</url>
            <title>Stories by Abhishek Gangwar on Medium</title>
            <link>https://medium.com/@abhishek-gangwar?source=rss-5e4d50c56ac2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 13:13:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@abhishek-gangwar/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Semantic HTML — Why it is important?]]></title>
            <link>https://abhishek-gangwar.medium.com/semantic-html-why-it-is-important-466299e19ab9?source=rss-5e4d50c56ac2------2</link>
            <guid isPermaLink="false">https://medium.com/p/466299e19ab9</guid>
            <category><![CDATA[html]]></category>
            <category><![CDATA[semantic-html]]></category>
            <category><![CDATA[html5]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[frontend]]></category>
            <dc:creator><![CDATA[Abhishek Gangwar]]></dc:creator>
            <pubDate>Tue, 30 Apr 2024 17:46:09 GMT</pubDate>
            <atom:updated>2024-04-30T17:46:09.193Z</atom:updated>
            <content:encoded><![CDATA[<h3>Semantic HTML — Why it is important?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*COz829VkQWbVjvsx" /><figcaption>Photo by <a href="https://unsplash.com/@jacksonsophat?utm_source=medium&amp;utm_medium=referral">Jackson Sophat</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>What is Semantic HTML?</h3><p>Semantic HTML, also known as semantic markup, refers to HTML code that uses tags to indicate the purpose of page elements. This helps visitors understand the structure of the content, such as paragraphs, and how it should be displayed on a web page.</p><p>Semantic markup aids readers, search engines, browsers, and assistive technologies in interpreting the elements of a web page.</p><h3>Why Semantic HTML is important?</h3><p>Semantic HTML offers several key features:</p><ul><li><strong>Accessibility</strong>: Semantic HTML tags make web page elements easier to understand and improve navigation. These tags help readers grasp the purpose of the content and how users can interact with it. In short, semantic tags enhance user navigation and present the content more effectively.</li><li><strong>SEO (Search Engine Optimization)</strong>: Semantic markup or semantic HTML tags benefit search engines. By using these tags, web pages can present elements in a way that search engines can easily understand, improving the site’s ranking based on efficient navigation by search engine crawlers.</li><li><strong>Human Readability</strong>: Semantic tags improve the human readability of web page elements. Developers can quickly locate specific page elements and make necessary changes or enhancements. Readability is crucial for enhancing user experience (UX), achieving a better ranking, and enabling developers to make improvements.</li><li><strong>Improved Interoperability</strong>: Semantic HTML ensures that content is correctly interpreted by different browsers, devices, and platforms, leading to a more consistent user experience.</li><li><strong>Future-proofing</strong>: As the web evolves, semantic HTML is more likely to be compatible with new technologies and standards, safeguarding against potential changes.</li></ul><h3>Semantic HTML Tags Structure</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W00d9sp0Okn-CVXlt9FwSw.png" /></figure><p>Here’s the list of some popular Semantic elements added in HTML5:</p><ul><li><strong>&lt;header&gt;</strong>: This tag defines the header of a document or a specific section within a document. It is typically used for introductory content, such as a title or a logo.</li><li><strong>&lt;nav&gt;</strong>: This tag is used to define a section of navigation links within a document.</li><li><strong>&lt;main&gt;</strong>: This tag specifies the main content of a document. There should be only one &lt;main&gt; tag per document, and it contains the central and most important information.</li><li><strong>&lt;section&gt;</strong>: This tag groups related content together. It&#39;s a way to create logical divisions within the document, such as chapters or sections of an article.</li><li><strong>&lt;article&gt;</strong>: This tag defines an independent, self-contained piece of content. An &lt;article&gt; can include text, images, and other multimedia elements and should be reusable and shareable.</li><li><strong>&lt;aside&gt;</strong>: This tag contains content that is tangentially related to the surrounding content. It is often used for sidebars or other supplementary information.</li><li><strong>&lt;footer&gt;</strong>: This tag defines the footer of a document, usually including information such as copyright notices, contact information, or links to additional resources.</li><li><strong>&lt;figure&gt;</strong>: This tag groups multimedia content (such as images, videos, or charts) with a caption for better context and description.</li><li><strong>&lt;figcaption&gt;</strong>: This tag provides a caption or description for multimedia content grouped within a &lt;figure&gt; element.</li><li><strong>&lt;time&gt;</strong>: This tag defines a date or time value, which can be presented in a standardized format for consistency and compatibility with assistive technologies.</li><li><strong>&lt;details&gt;</strong>: Represents additional information that can be toggled open or closed by the user.</li><li><strong>&lt;mark&gt;</strong>: Represents highlighted text.</li><li><strong>&lt;progress&gt;</strong>: Represents a progress bar for a task that is in progress.</li></ul><h3><strong>Summing it Up</strong></h3><p>When writing HTML, using semantic tags is important because it improves the accessibility and searchability of your content, as well as making the code more understandable and maintainable.</p><p>By using tags that convey the purpose of different sections of a webpage, you enhance the experience for both users and developers.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=466299e19ab9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[XSS attacks in React apps and how to prevent them.]]></title>
            <link>https://abhishek-gangwar.medium.com/xss-attacks-in-react-apps-and-how-to-prevent-them-cfafd2369dc5?source=rss-5e4d50c56ac2------2</link>
            <guid isPermaLink="false">https://medium.com/p/cfafd2369dc5</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[xss-bypass]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[xss-attack]]></category>
            <category><![CDATA[xss-vulnerability]]></category>
            <dc:creator><![CDATA[Abhishek Gangwar]]></dc:creator>
            <pubDate>Sun, 14 Apr 2024 06:09:24 GMT</pubDate>
            <atom:updated>2024-04-14T06:09:24.524Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*65uIweIJF_HGxNKH" /><figcaption>Photo by <a href="https://unsplash.com/@maxwbender?utm_source=medium&amp;utm_medium=referral">Max Bender</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Hey there, fellow tech enthusiasts! Today, we’re diving into a topic that might send a chill down your spine: <strong><em>XSS attacks in React.</em></strong> You might be thinking, “<strong>What on earth is XSS, and why should I care?</strong>” Well, buckle up, because we’re about to uncover the hidden dangers lurking in the world of web development.</p><p>Picture this: you’re happily coding away on your React application, creating beautiful user interfaces and seamless interactions. But behind the scenes, there’s a sinister threat waiting to strike — XSS, short for Cross-Site Scripting. Sounds ominous, right? That’s because it is.</p><h3>What exactly is XSS?</h3><p>In simple terms, it’s a type of security vulnerability that allows attackers to inject malicious scripts into web pages viewed by other users. These scripts can steal sensitive information, hijack user sessions, or even deface your website.</p><p>Now you might be thinking that —</p><blockquote><strong>Doesn’t React automatically prevent this?</strong></blockquote><p>Well, yes and no. while frameworks like React offer tools to mitigate XSS risks, they’re not foolproof shields and can be easily bypassed if we don’t understand how these work behind the scenes.</p><p>Developers need to leverage these features wisely, knowing they’re not bulletproof. Vigilance and skilful application of these capabilities are key to fortifying our apps against XSS threats.</p><h3>How to Prevent XSS Attacks in React?</h3><p>To prevent cross-site scripting (XSS) attacks in React, you can use the following techniques:</p><h4>1 — Avoid using dangerouslySetInnerHTML:</h4><p>As mentioned earlier, this method allows injecting raw HTML into your components, bypassing React’s built-in XSS protection mechanisms. Use it sparingly and only if you are certain that the HTML content is safe and sanitized.</p><h4>2 — Sanitize user inputs</h4><p>Always sanitize any user-generated content before rendering it in your React components. Libraries like DOMPurify can help ensure that the content is safe to render.</p><h4>3 — Escape HTML entities</h4><p>Use libraries like lodash.escape or a simple regEx to escape HTML entities in user inputs before rendering them. This prevents any malicious scripts from being executed.</p><h4>4 — Use JSX for rendering</h4><p>JSX automatically escapes any values embedded within curly braces {}. This ensures that data rendered using JSX is automatically sanitized.</p><h4>5 — Content Security Policy (CSP)</h4><p>Implement a strict Content Security Policy for your web application. CSP allows you to define a whitelist of trusted sources for content, scripts, and other resources. It can help mitigate the impact of XSS attacks by preventing the execution of scripts from unauthorized sources.</p><h4>6 — HTTPOnly cookies:</h4><p>Ensure that sensitive cookies, such as session tokens, are marked as <em>HTTPOnly</em>. This prevents them from being accessed by JavaScript, reducing the risk of XSS attacks that attempt to steal session data.</p><h4><strong>7 — Verify any Third-party Libraries before using them</strong></h4><p>Verify any third-party libraries before you use them inside your code base. Third-party libraries might contain vulnerabilities in their codebase. These vulnerabilities could be exploited by attackers to execute malicious scripts.</p><p>Last but not least is regularly reviewing your codebase for potential security vulnerabilities, including XSS vulnerabilities. Use automated scanning tools and manual code reviews to identify and address any security issues.</p><p>I hope this helps. Until next time, happy coding.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cfafd2369dc5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Custom hook — useClickOutside()]]></title>
            <link>https://abhishek-gangwar.medium.com/custom-hook-useclickoutside-105daca885d7?source=rss-5e4d50c56ac2------2</link>
            <guid isPermaLink="false">https://medium.com/p/105daca885d7</guid>
            <category><![CDATA[custom-hook]]></category>
            <category><![CDATA[useclickoutside]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-hook]]></category>
            <dc:creator><![CDATA[Abhishek Gangwar]]></dc:creator>
            <pubDate>Thu, 04 Apr 2024 18:48:08 GMT</pubDate>
            <atom:updated>2024-04-04T18:50:16.437Z</atom:updated>
            <content:encoded><![CDATA[<h3>Custom hook — useClickOutside()</h3><p>A Hook that detects if the user has clicked outside the container.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Jkj83Vs0bZjkKaBR" /><figcaption>Photo by <a href="https://unsplash.com/@lautaroandreani?utm_source=medium&amp;utm_medium=referral">Lautaro Andreani</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Introduction</h3><p>Hey there, tech enthusiasts! Today, we’re diving into the fascinating world of React hooks again. This time with a quirky little Hook called useClickOutside().</p><p>If you&#39;ve ever wondered how to tell when a user clicks outside a specific component, buckle up, because we&#39;re about to embark on a hilarious journey through the land of event listeners and state management to create a custom hook.</p><h3>The Problem: Dealing with Clicks Outside Your Components</h3><p>Picture this scenario: you’ve painstakingly crafted a beautiful dropdown menu for your web application. It’s elegant, it’s functional, but there’s just one problem — it refuses to close when the user clicks outside of it. Frustrating isn’t it? This is a common challenge many developers face when dealing with user interactions in web applications.</p><h3>The Implementation — useClickOutside() Hook</h3><pre>import React, { useEffect } from &quot;react&quot;;<br><br>/**<br> * useClickOutside Hook<br> * @param {*} callback<br> * @returns ref which needs to be added on component, outside which we need to listen for Clicks<br> */<br>export default function useClickOutside(callback) {<br>  const ref = React.useRef(null);<br>  const rootElement = document.getElementById(&quot;root&quot;);<br><br>  // Registers the Click Event<br>  function registerClickEventListener() {<br>    rootElement.addEventListener(&quot;click&quot;, (event) =&gt; {<br>      if (ref.current &amp;&amp; !ref.current.contains(event.target)) {<br>        callback();<br>      }<br>    });<br>  }<br><br>  // un-registers the Click Event<br>  function unRegisterClickEventListener() {<br>    rootElement.addEventListener(&quot;click&quot;, (event) =&gt; {<br>      if (event.target === ref.current) {<br>        callback();<br>      }<br>    });<br>  }<br><br>  useEffect(() =&gt; {<br>    registerClickEventListener();<br><br>    return () =&gt; {<br>      unRegisterClickEventListener();<br>    };<br>  }, []);<br><br>  return ref;<br>}</pre><h3>How to use useClickOutside Inside React component?</h3><pre><br>function HomePage() {<br>  // ref that needs to be attached to the component outside which we are listening for clicks<br>  const dropDownRef = useClickOutside(onOutsideClick);<br><br>  const onOutsideClick = () =&gt; {<br>    // Do something when outside click is detected<br>  };<br><br>  return &lt;DropDown ref={dropDownRef}&gt;<br>        // Render Childrens<br>  &lt;/DropDown&gt;<br>}</pre><h3>Explanation</h3><ol><li><strong><em>useClickOutside</em></strong> hook accepts a callback and returns a reference.</li><li>You can pass in a function as a callback that gets triggered whenever a click is detected outside the component.</li><li>It creates a reference (ref) to the component we&#39;re monitoring for clicks outside.</li><li>Sets up an event listener on the root element of the document to capture click events.</li><li>When a click occurs, it checks if the clicked element matches the monitored component. If it’s outside, it triggers the provided callback.</li><li>Removes the event listener when the component unmounts to prevent memory leaks.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=105daca885d7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting up React from Scratch]]></title>
            <link>https://abhishek-gangwar.medium.com/setting-up-react-from-scratch-d56e07752acc?source=rss-5e4d50c56ac2------2</link>
            <guid isPermaLink="false">https://medium.com/p/d56e07752acc</guid>
            <category><![CDATA[webpack]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[babel]]></category>
            <category><![CDATA[scss]]></category>
            <category><![CDATA[eslint]]></category>
            <dc:creator><![CDATA[Abhishek Gangwar]]></dc:creator>
            <pubDate>Sat, 12 Jun 2021 12:44:04 GMT</pubDate>
            <atom:updated>2021-06-12T12:44:04.236Z</atom:updated>
            <content:encoded><![CDATA[<h3>Setting up React Ecosystem from Scratch</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*i2vOwFuzTpc1wHiM" /><figcaption>Photo by <a href="https://unsplash.com/@fabioha?utm_source=medium&amp;utm_medium=referral">fabio</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>React has been a widely used framework in the frontend community and the community is growing with each day and many of us started on our first react project using the <a href="https://github.com/facebook/create-react-app">create-react-app</a> starter kit provided by the official React team.</p><p>As good as this starter kit is, it does not showcase how things are working behind the scenes. if you ever wondered how different plugins work with react and how your code is compiled &amp; bundled together you have come to the right place.</p><blockquote>Before we proceed any further if you are someone who likes to understand things by going through the code, you can check out the repository <a href="https://github.com/abhishekgangwar90/react-from-scratch">here</a>.</blockquote><p>In this article, We will be covering Webpack, babel, Sass, unit testing with jest and enzyme, code linting, and formatting with Eslint &amp; prettier, and many performance-related things.</p><p>So For simplicity and readability purposes, I have subdivided this article into the following pieces —</p><ul><li><a href="https://abhishek-gangwar.medium.com/react-ecosystem-setting-up-babel-and-webpack-for-react-938dd19d5197">Setting up Webpack 5 and Babel 7 for React.</a></li><li><a href="https://abhishek-gangwar.medium.com/how-to-configure-eslint-and-prettier-48470fa8a120">Setting up Eslint and Prettier.</a></li><li>Setting up Unit Testing framework with Jest and Enzyme.</li><li>Setting up Sass and Sass 7–1 pattern with React.</li><li>Setting up support for static content.</li><li>Code Splitting and Route-based chunking.</li><li>Hot Module Replacement</li><li>Performance improvements for React</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d56e07752acc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How To Configure ESLint and Prettier]]></title>
            <link>https://abhishek-gangwar.medium.com/how-to-configure-eslint-and-prettier-48470fa8a120?source=rss-5e4d50c56ac2------2</link>
            <guid isPermaLink="false">https://medium.com/p/48470fa8a120</guid>
            <category><![CDATA[eslint-configuration]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[eslint]]></category>
            <category><![CDATA[eslint-config]]></category>
            <category><![CDATA[prettier]]></category>
            <dc:creator><![CDATA[Abhishek Gangwar]]></dc:creator>
            <pubDate>Sat, 12 Jun 2021 12:37:27 GMT</pubDate>
            <atom:updated>2021-06-12T12:46:17.342Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*biLs0r8qLhaaorteiG6Dxg.jpeg" /></figure><p>In a web development world where speed and performance is everything. As a developer, you need to make sure you catching the errors early and writing scalable and maintainable code that follows certain coding standards and is easy to understand.</p><p>That’s why in this article we are gonna talk about the two most underrated things, <strong>Code Linting</strong> &amp; <strong>Code</strong> <strong>formatting </strong>by setting up <strong>Eslint</strong> and <strong>Prettier.</strong></p><blockquote>ESLint is a static code analysis tool for identifying problematic patterns found in JavaScript code.</blockquote><blockquote>Prettier is a code formatter, that helps in following industry standard coding practices.</blockquote><blockquote>This is the second part of the <a href="https://abhishek-gangwar.medium.com/setting-up-react-from-scratch-d56e07752acc">article series</a> where we will be setting up a production-grade React application from scratch.</blockquote><blockquote>In the <a href="https://abhishek-gangwar.medium.com/react-ecosystem-setting-up-babel-and-webpack-for-react-938dd19d5197">last part</a>, we did the setup for <em>Webpack &amp; </em><em>babel.</em> If you are someone who wants to understand how your React project work under the hood, check out this series where I have talked about setting up the React Ecosystem from scratch.</blockquote><blockquote>If at any point you feel like looking into the code, you can checkout the code from <a href="https://github.com/abhishekgangwar90/react-from-scratch">here</a>.</blockquote><h3>Table of Content</h3><ul><li>Installing the dependencies</li><li>Configuring Eslint and Prettier</li><li><strong>Optional</strong> — Installing Eslint and prettier Extensions for IDEs.</li><li>Running Eslint and Prettier.</li></ul><p>Before installing the dependencies, I want you to add some buggy code to your index.js file, so you can visualize how Eslint helps you in catching errors early. Add the following code to index.js inside src folder.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a1b13f6800cab5a3c93c778d56a67b81/href">https://medium.com/media/a1b13f6800cab5a3c93c778d56a67b81/href</a></iframe><blockquote>if you look closely on line no 4 and line no 6 , the two variables handleButtonClick and someLocalProperty are not defined, and this will throw errors when you will run this code. We will come back to this later, how Eslint will help you catch these error before running your code. for now let’s continue in our setup.</blockquote><h3>Step 1 — Installing the dependencies</h3><p>In Order for Eslint to work, we need to provide a certain set of rules. We will be eslint-config-airbnb for some predefined rules.</p><p>In order to install the <strong>Eslint</strong> run the following command —</p><pre>npm i --save-dev eslint prettier eslint-config-airbnb eslint-config-prettier eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-prettier eslint-plugin-react eslint-plugin-react-hooks</pre><blockquote>Alternatively, if you have npm v5+, you can directly run the shorter version of the above command.</blockquote><pre>npx install-peerdeps --dev eslint-config-airbnb &amp;&amp; npm i -D prettier</pre><p>The above commands will add the following dependencies to your package.json file —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/1*v2LWaLIt2HsLVl82jcPc2Q.png" /><figcaption>React Ecosystem: Eslint Prettier setup</figcaption></figure><h3>Step 2 — Configuring Eslint and prettier</h3><p>In order to set up the Eslint and prettier we need to add the configuration for both of them.</p><p>Let’s create two files at the root level-</p><ul><li>.eslintrc.js for Eslint configuration.</li><li>.prettierrc.js for Prettier configuration.</li></ul><blockquote><strong>Note </strong>— both files names start with a .</blockquote><blockquote>if you have been following the React Ecosystem article series, then your folder structure will look something like this after adding these two files.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/1*p8OqEi5F2EUyHE1bZz5Llg.png" /></figure><blockquote>Next, let’s add the following Eslint configuration to .eslintrc.js file —</blockquote><pre>module.exports = {<br>  extends: [ // extenind pre-defined rules<br>    &#39;airbnb&#39;, <br>    &#39;airbnb/hooks&#39;,<br>    &#39;prettier&#39;,<br>    &#39;plugin:prettier/recommended&#39;,<br>  ],<br>  plugins: [&#39;prettier&#39;], <br>  rules: { // you can modify some rules manually<br>    &#39;react/jsx-filename-extension&#39;: [<br>      1,<br>      {<br>        extensions: [&#39;.js&#39;, &#39;.jsx&#39;],<br>      },<br>    ],<br>    &#39;import/no-extraneous-dependencies&#39;: [&#39;error&#39;, { devDependencies: true }],<br>    &#39;react/jsx-props-no-spreading&#39;: [<br>      0,<br>      {<br>        html: &#39;ignore&#39;,<br>        custom: &#39;ignore&#39;,<br>        explicitSpread: &#39;ignore&#39;,<br>      },<br>    ],<br>    &#39;prettier/prettier&#39;: &#39;error&#39;,<br>    &#39;arrow-body-style&#39;: &#39;off&#39;,<br>    &#39;prefer-arrow-callback&#39;: &#39;off&#39;,<br>  },<br>  globals: {<br>    window: true,<br>    document: true,<br>    localStorage: true,<br>    FormData: true,<br>    FileReader: true,<br>    Blob: true,<br>    navigator: true,<br>  },<br>};</pre><p>extends — This helps in extending pre-defined rules from libs.</p><p>plugin — which third-party plugins define additional rules, environments, configs, etc. for ESLint to use.</p><p>rules — You can define, modify some rules here. You can turn on and off these rules based on your requirements. you can read more about configuring rules <a href="https://eslint.org/docs/user-guide/configuring/rules#configuring-rules">here</a>.</p><p>globals — the additional global variables your script accesses during execution.</p><blockquote>Next, let’s add some prettier configuration as well, add the following to to <em>.prettierrc.js .</em></blockquote><pre>module.exports = {<br>&quot;singleQuote&quot;: true,<br>&quot;printWidth&quot;: 100,<br>&quot;trailingComma&quot;: &quot;es5&quot;,<br>&quot;tabWidth&quot;: 2<br>}</pre><p>singleQuote — throws an error on double-quotes. allows the use of single quote only.</p><p>printWidth — sets max line width can be 100 characters.</p><p>trainlingComma — line should end with a comma.</p><p>tabWidth — sets tabwidth to 2 characters.</p><h3>Step 3 — Adding Eslint and prettier extensions</h3><p>If you want a visual representation of errors in your IDE, you can install these two extensions. You can search for theseextensions inside your IDE. I am a huge fan of VS Code, so I will be setting it up with VS code only.</p><p>You can search for them in extensions section of your VS code IDE or install via these links —</p><p>Eslint — <a href="https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint">https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint</a></p><p>Prettier — <a href="https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode">https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode</a></p><p>As soon as you add these extensions, your IDE will start showing the linting errors like this —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s9oPkUPmOM8rUypKmFjP4A.png" /></figure><p>See now handleButtonClick and someLocalProperty shows an error.</p><p>You can hover over the error and you can see the exact problem with the code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HV-6Ne6sjcl-rMjDgKkZpA.png" /></figure><p>In order to fix this, you can click on quick fix, which will show you this —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Peni0lq_aWgX9Psgu6g8tg.png" /></figure><p>you have three options here —</p><ul><li>you can disable no-undefined eslint rule for this line.</li><li>you can disable no-undefined eslint rule for entire file.</li><li>Or you can see the documentation, it will take you to the official page, where you can read more about it.</li></ul><h3>Step 4- Running Eslint and Prettier</h3><p>If you want to run this via the command line, you can add the following script to your package.json inside scripts .</p><pre>&quot;lint&quot;: &quot;eslint --fix .&quot;</pre><p>and then run the following command from the terminal —</p><pre>npm run lint</pre><p>This will go through all the files and <strong>fix all auto-fixable problems.</strong></p><p>And that’s it. Now you have Eslint and Prettier setup in your project.</p><p>Up Next in this series I will be talking about Unit Testing setup, checkout this article series for more info.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6lDmXaQ2YORA3l2k" /><figcaption>Photo by <a href="https://unsplash.com/@napr0tiv?utm_source=medium&amp;utm_medium=referral">Vasily Koloda</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=48470fa8a120" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Ecosystem: Setting up Babel 7 and Webpack 5 for React]]></title>
            <link>https://abhishek-gangwar.medium.com/react-ecosystem-setting-up-babel-and-webpack-for-react-938dd19d5197?source=rss-5e4d50c56ac2------2</link>
            <guid isPermaLink="false">https://medium.com/p/938dd19d5197</guid>
            <category><![CDATA[babel]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-from-scratch]]></category>
            <category><![CDATA[webpack-5]]></category>
            <category><![CDATA[webpack]]></category>
            <dc:creator><![CDATA[Abhishek Gangwar]]></dc:creator>
            <pubDate>Wed, 09 Jun 2021 19:22:33 GMT</pubDate>
            <atom:updated>2021-06-12T12:45:32.748Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NrBLWSYS7jLeod3Z" /><figcaption>Photo by <a href="https://unsplash.com/@cgower?utm_source=medium&amp;utm_medium=referral">Christopher Gower</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Have you ever wondered, How your React JSX code is running in a browser that only understands javascript? How your code is <strong>minified</strong> and <strong>bundled </strong>and <strong>shipped</strong> to the browser? Well If the answer to the above questions is YES, then you have come to the right place.</p><blockquote>This is the first part of the article series where we will be setting up a production-grade React application from scratch. Check-out this <a href="https://abhishek-gangwar.medium.com/setting-up-react-from-scratch-d56e07752acc">article</a> for more information.</blockquote><h3>Table of Content</h3><ul><li>Set up the folder structure.</li><li>Installing Webpack &amp; babel dependencies.</li><li>Setting up babel configurations.</li><li>Adding index.html and index.js</li><li>Setting up webpack configurations.</li><li>Adding React to the project.</li></ul><blockquote>Before jumping into the code, if you are someone who learns more via going through the code, feel free to check out the <a href="https://github.com/abhishekgangwar90/react-from-scratch">repo</a> for this project. I will be using the same repo to setup the whole React EcoSystem.</blockquote><h3>Step 1 - Set up the folder structure</h3><p>Alright, let’s create a folder named react-from-scratchor anything you want and open your terminal and navigate inside react-from-scratch.</p><p>Then run the following command in terminal —</p><pre>npm init -y</pre><p>The above command will create apackage.json and -y flag skips some simple questions. After running this command your package.json will look like this —</p><figure><img alt="React from scratch: package.json" src="https://cdn-images-1.medium.com/max/1024/1*VoLGZrqimVeY0wszMmyNaA.png" /></figure><p>While we are at it, let’s create some more files and folders to properly manage our codebase by running the following commands in your terminal -</p><pre>mkdir webpack public src</pre><p>This command will create 3 folders, I will explain why we need these but first, let’s put some files in these folders as well by running the following command</p><pre>touch webpack.config.js babel.config.js public/index.html webpack/webpack.dev.config.js webpack/webpack.prod.config.js webpack/webpack.base.config.js src/index.js</pre><blockquote>Remember, You can always create these files manually as well, After creating the files your folder structure should look something like this —</blockquote><figure><img alt="React from scratch: folder structure" src="https://cdn-images-1.medium.com/max/466/1*8QSsDpJu1k78eA-mugObOw.png" /></figure><p>Looks cool, right? Now before we start putting some configuration in these files let’s install some dependencies.</p><blockquote>In following steps 2, we will be talking about Webpack &amp; babel setup in depth, and will focus on why we are using a certain dependency. if you like to learn from code, you can skip this and refere the package.json mentioned in step 3 directly.</blockquote><h3>Step 2 — Installing Webpack and Babel</h3><p>Before installing let’s understand what is Webpack and babel.</p><blockquote>Webpack is an open-source JavaScript <strong>module bundler.</strong> It is made primarily for JavaScript, but it can transform front-end assets such as HTML, CSS, and images if the corresponding loaders are included.</blockquote><blockquote>Babel is a <strong>transcompiler</strong> which is mainly used to compiles ES6 code to backward compatible code that can run on older Javascript engines.</blockquote><p>Enough with the definition :P, let&#39;s install the dependencies by adding the following to your devDependencies inside your package.json and run command npm install from your terminal.</p><pre>&quot;devDependencies&quot;: {<br>    &quot;webpack&quot;: &quot;5.37.1&quot;,<br>    &quot;webpack-cli&quot;: &quot;4.7.0&quot;,<br>    &quot;webpack-dev-server&quot;: &quot;3.11.2&quot;,<br>    &quot;webpack-merge&quot;: &quot;5.7.3&quot;<br>    &quot;terser-webpack-plugin&quot;: &quot;5.1.2&quot;,<br>    &quot;optimize-css-assets-webpack-plugin&quot;: &quot;6.0.0&quot;,<br>    &quot;html-webpack-plugin&quot;: &quot;5.3.1&quot;,<br>    &quot;compression-webpack-plugin&quot;: &quot;8.0.0&quot;,<br>    &quot;mini-css-extract-plugin&quot;: &quot;1.6.0&quot;,<br>    &quot;copy-webpack-plugin&quot;: &quot;9.0.0&quot;,<br>    &quot;babel-loader&quot;: &quot;8.2.2&quot;,<br>    &quot;css-loader&quot;: &quot;5.2.6&quot;,<br>    &quot;style-loader&quot;: &quot;2.0.0&quot;,<br>    &quot;@babel/core&quot;: &quot;7.14.3&quot;,<br>    &quot;@babel/preset-env&quot;: &quot;7.14.4&quot;,<br>    &quot;@babel/preset-react&quot;: &quot;7.13.13&quot;,<br>    &quot;@babel/plugin-proposal-export-default-from&quot;: &quot;7.12.13&quot;,<br>    &quot;@babel/plugin-proposal-throw-expressions&quot;: &quot;7.12.13&quot;, <br>  }</pre><blockquote>To avoid any braking issue due to version change in the future, I have locked the dependencies version here.</blockquote><p>Okay I know what you are thinking, that’s a lot of dependencies right? Well hold your horses and roll up your sleeves because you are about to get bamboozled :P.</p><p>Because we are gonna talk about these one by one-</p><blockquote>First, we have some basic webpack dependencies -</blockquote><ul><li><a href="https://webpack.js.org/"><strong>webpack</strong></a>: a module bundler for js application, which compiles our code based on some rules/config. we will talk about these rules/config later.</li><li><strong>webpack-cli:</strong> enables the command line support for webpack.</li><li><strong>webpack-dev-server:</strong> provides a server where the application can run locally. This helps in developing the application, because of this we don’t have to create a Nodejs server just to run my code locally.</li></ul><blockquote>After that, we have some plugins to support webpack -</blockquote><ul><li><strong>webpack-merge:</strong> a plugin that helps in merging two webpack configurations.</li><li><strong>terser-webpack-plugin: </strong>used for minifying the js code.</li><li><strong>optimize-css-assets-webpack-plugin: </strong>used for minifying the CSS code.</li><li><strong>html-webpack-plugin: </strong>generates an HTML file, also it adds .css and .js files to that HTML dynamically.</li><li><strong>compression-webpack-plugin: </strong>the<strong> </strong>plugin which helps in compressing your code.</li><li><strong>mini-css-extract-plugin: </strong>This plugin extracts CSS into separate files. It creates a CSS file per JS file which contains CSS. It supports On-Demand-Loading of CSS and SourceMaps, <strong>Thus enhancing the performance.</strong></li><li><strong>copy-webpack-plugin: </strong>Copies individual files or entire directories, which already exist, to the build directory.</li></ul><blockquote>Up next, we have some loaders to help Webpack in compiling the code-</blockquote><ul><li><strong>babel-loader: </strong>This package allows transpiling JavaScript files using Babel and webpack.</li><li><strong>css-loader: </strong>This<strong> </strong>would help webpack to collect CSS from all the CSS files referenced in your application and put them into a string.</li><li><strong>style-loader: </strong>it takes the output string generated by the above css-loader and puts it inside the &lt;style&gt; tags in the index.html file.</li></ul><blockquote>And last but not the least, we have some babel dependencies —</blockquote><ul><li><a href="https://babeljs.io/docs/en/babel-core"><strong>@babel/core</strong></a><strong>: </strong>The core functionality of babel is provided by this package.</li><li><a href="https://babeljs.io/docs/en/babel-preset-env"><strong>@babel/preset-env</strong></a><strong>: </strong>enables you to write code in ES6.</li><li><a href="https://babeljs.io/docs/en/babel-preset-react"><strong>@babel/preset-react</strong></a><strong>: </strong>preset for react. it helps babel in compiling JSX to browser understandable code.</li><li><a href="https://babeljs.io/docs/en/babel-plugin-proposal-throw-expressions"><strong>@babel/plugin-proposal-throw-expressions:</strong></a><strong> </strong>lets you throw exceptions from expression context by usingthrow keyword.</li><li><a href="https://babeljs.io/docs/en/babel-plugin-proposal-export-default-from"><strong>@babel/plugin-proposal-export-default-from</strong></a><strong> : </strong>used for default exports</li></ul><p>Before we jump into setting up configurations, I wanna talk about the revolutionary breaking changes that babel introduced with v7-</p><blockquote>Before v7<strong> , </strong>babel had stage presets like stage-0, es2015 etc. so even if you were using only one feature from a preset, you still had to add the complete preset, which was making your codebase heavy and your application slow.</blockquote><blockquote><strong>With v7</strong>, Babel introduced some <a href="https://babeljs.io/blog/2018/07/27/removing-babels-stage-presets">breaking changes</a> and has decided to move away from the above approach and started shipping each feature separately. Interesting right?</blockquote><h3>Step 3— Setting up babel config</h3><p>Well let&#39;s add some configuration to those files which we created, but before that, a quick check, at this point your package.json should look like below-</p><blockquote>If you have skipped the step 2, you can simply copy this package.json and run npm install from your terminal.</blockquote><pre>{<br>  &quot;name&quot;: &quot;react-from-scratch&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;description&quot;: &quot;&quot;,<br>  &quot;main&quot;: &quot;index.js&quot;,<br>  &quot;scripts&quot;: {<br>    &quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;<br>  },<br>  &quot;keywords&quot;: [],<br>  &quot;author&quot;: &quot;&quot;,<br>  &quot;license&quot;: &quot;ISC&quot;,<br>  &quot;devDependencies&quot;: {<br>    &quot;@babel/core&quot;: &quot;^7.14.3&quot;,<br>    &quot;@babel/plugin-proposal-export-default-from&quot;: &quot;^7.12.13&quot;,<br>    &quot;@babel/plugin-proposal-throw-expressions&quot;: &quot;^7.12.13&quot;,<br>    &quot;@babel/preset-env&quot;: &quot;^7.14.4&quot;,<br>    &quot;@babel/preset-react&quot;: &quot;^7.13.13&quot;,<br>    &quot;babel-loader&quot;: &quot;8.2.2&quot;,<br>    &quot;compression-webpack-plugin&quot;: &quot;8.0.0&quot;,<br>    &quot;copy-webpack-plugin&quot;: &quot;9.0.0&quot;,<br>    &quot;css-loader&quot;: &quot;5.2.6&quot;,<br>    &quot;html-webpack-plugin&quot;: &quot;5.3.1&quot;,<br>    &quot;mini-css-extract-plugin&quot;: &quot;1.6.0&quot;,<br>    &quot;optimize-css-assets-webpack-plugin&quot;: &quot;6.0.0&quot;,<br>    &quot;style-loader&quot;: &quot;2.0.0&quot;,<br>    &quot;terser-webpack-plugin&quot;: &quot;5.1.2&quot;,<br>    &quot;webpack&quot;: &quot;5.37.1&quot;,<br>    &quot;webpack-cli&quot;: &quot;4.7.0&quot;,<br>    &quot;webpack-dev-server&quot;: &quot;3.11.2&quot;,<br>    &quot;webpack-merge&quot;: &quot;5.7.3&quot;<br>  }<br>}</pre><blockquote>Alright , let’s add some babel configuration by adding the following code inside babel.config.js -</blockquote><pre>module.exports = {<br>  presets: [<br>    &#39;@babel/preset-env&#39;, <br>    &#39;@babel/preset-react&#39;<br>  ],<br>  plugins: [<br>    &#39;@babel/plugin-syntax-dynamic-import&#39;,<br>    &#39;@babel/plugin-proposal-throw-expressions&#39;,<br>    &#39;@babel/plugin-proposal-export-default-from&#39;,<br>  ],<br>};</pre><p>As mentioned in step 2, here we have added <strong>presets</strong> and <strong>plugins</strong> that help in compiling our codebase which the browser can understand.</p><h3>Step 4 — Adding index.html and index.js</h3><p>let&#39;s add some HTML code to see something on our browser. Add the following in ourindex.html inside public folder.</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>&lt;head&gt;<br>  &lt;meta charset=&quot;UTF-8&quot;&gt;<br>  &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;<br>  &lt;title&gt;React App From Scratch&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>  &lt;div id=&quot;root&quot;&gt;&lt;/div&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>Please add the following dummy code in our index.js inside src folder</p><pre>console.log(&#39;Hello World, Setting up react from Scratch&#39;);</pre><h3>Step 5 — Setting up webpack configuration</h3><p>Well to configure Webpack properly we will be using the following files —</p><ul><li>webpack.config.js to pick configuration based on environment.</li><li>webpack.base.config.js to write a common configuration that will be used in both prod and dev mode.</li><li>webpack.dev.config.js to write development config.</li><li>webpack.prod.config.js for production config.</li></ul><p>Alright, let’s add the config one by one, with the explanation of course :)</p><blockquote>Add the following code to <strong>webpack.config.js</strong> at root level-</blockquote><pre>module.exports =<br>  process.env.NODE_ENV === &#39;development&#39;<br>    ? require(&#39;./webpack/webpack.dev.config&#39;)<br>    : require(&#39;./webpack/webpack.prod.config&#39;);</pre><p>here we are picking up Webpack configuration based on the environment.</p><blockquote>Add the following code for common config to file <strong>webpack.base.config.js</strong> inside webpack folder.</blockquote><pre>const { merge } = require(&#39;webpack-merge&#39;);<br>const HtmlWebpackPlugin = require(&#39;html-webpack-plugin&#39;);<br>const MiniCssExtractPlugin = require(&#39;mini-css-extract-plugin&#39;);</pre><pre>module.exports = () =&gt; {<br>  return merge([<br>    {<br>      module: {<br>        rules: [<br>          {<br>            test: /\.js$/,<br>            exclude: /node_modules/,<br>            use: {<br>              loader: &#39;babel-loader&#39;,<br>            },<br>          },<br>          {<br>            test: /\.scss$/,<br>            exclude: /node_modules/,<br>            use: [<br>              process.env.NODE_ENV === &#39;production&#39;<br>                ? MiniCssExtractPlugin.loader<br>                : &#39;style-loader&#39;,<br>              &#39;css-loader&#39;<br>            ],<br>          },<br>        ],<br>      },<br>      plugins: [<br>        new HtmlWebpackPlugin({<br>          template: &#39;./public/index.html&#39;,<br>          filename: &#39;./index.html&#39;,<br>        }),<br>      ],<br>    },<br>  ]);<br>};</pre><p>Here in this config, we have two things, module and plugins We use module to write <strong>rules</strong> for a different set<strong> </strong>of files. Also, we are using babel-loader to transpile every js file and css-loader and style-loader to transpile and injecting the CSS.</p><p>Next, inside plugins, we have HtmlWebpackPlugin for creating the HTML and dynamically injecting CSS and js, and MiniCssExtractPlugin for on-demand CSS loading, you can read more about MiniCssExtractPlugin <a href="https://webpack.js.org/plugins/mini-css-extract-plugin/">here</a>.</p><p>Notice here we are using MiniCssExtractPlugin.loader for production only and style-loader for development mode, also we are using webpack.merge to merge out configurations.</p><blockquote>Up next let’s setup the development config by adding the following code towebpack.dev.config.js file inside webpack folder.</blockquote><pre>const webpack = require(&#39;webpack&#39;);<br>const { merge } = require(&#39;webpack-merge&#39;);<br>const webpackBaseConfig = require(&#39;./webpack.base.config&#39;);</pre><pre>const developmentConfig = () =&gt; {<br>  return merge([<br>    {<br>      mode: &#39;development&#39;,<br>      plugins: [<br>        new webpack.DefinePlugin({<br>          isDevelopment: true,<br>          &#39;process.env&#39;: {<br>            NODE_ENV: JSON.stringify(&#39;development&#39;),<br>          },<br>        }),<br>      ],<br>    },<br>  ]);<br>};</pre><pre>module.exports = () =&gt; merge(webpackBaseConfig(), developmentConfig());</pre><p>Here we are using webpack.DefinePlugin is used to set up some variables which can be referred to on UI. Also, in the last line, we are loading the base config and merging it with our development config using webpack.merge plugin.</p><blockquote>Last but not the least lets add the following to webpack.prod.config.js</blockquote><pre>const webpack = require(&#39;webpack&#39;);<br>const { merge } = require(&#39;webpack-merge&#39;);</pre><pre>// plugins<br>const TerserPlugin = require(&#39;terser-webpack-plugin&#39;);<br>const MiniCssExtractPlugin = require(&#39;mini-css-extract-plugin&#39;);<br>const OptimizeCssAssetsPlugin = require(&#39;optimize-css-assets-webpack-plugin&#39;);<br>const CompressionPlugin = require(&#39;compression-webpack-plugin&#39;);</pre><pre>const webpackBaseConfig = require(&#39;./webpack.base.config&#39;);</pre><pre>const prodConfig = () =&gt; {<br>  return merge([<br>    {<br>      mode: &#39;production&#39;,<br>      optimization: {<br>        minimize: true,<br>        runtimeChunk: &#39;single&#39;,<br>        minimizer: [new TerserPlugin()],<br>      },<br>      plugins: [<br>        new MiniCssExtractPlugin(),<br>        new OptimizeCssAssetsPlugin(),<br>        new webpack.DefinePlugin({<br>          isDevelopment: false,<br>          &#39;process.env&#39;: {<br>            NODE_ENV: JSON.stringify(&#39;production&#39;),<br>          },<br>        }),<br>        new CompressionPlugin(),<br>      ],<br>    },<br>  ]);<br>};</pre><pre>module.exports = () =&gt; merge(webpackBaseConfig(), prodConfig());</pre><p>Since v4, Webpack can handle the code optimization based on the mode but you can still set them manually. here we are using TerserPlugin for minification for our code inside optimization .</p><p>mode:’production’ sets the predefined optimization for production. You can also set it to development and none . check out this <a href="https://webpack.js.org/concepts/#mode">link</a> for more info on this.</p><p>Up next, We have added the plugins MiniCssExtractPlugin and OptimizeCssAssetsPlugin to compress and load-on-demand CSS, CompressionPlugin for code compression.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UM-kvM-EZxrbn0Hf9Ju49A.jpeg" /></figure><blockquote><strong>Congratulations</strong>, We have finally set up the <strong>Webpack</strong> and <strong>babel</strong>, our 90% job is done. Now in order to write code in React, we will need one last setup.</blockquote><h3>Step 5 — Adding React to the project</h3><p>To install React, run the following command in your terminal</p><pre>npm i react react-dom</pre><p>This will add two new dependencies inside your package.json.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*tKerQgsZpEpPi77lfN0lWA.png" /><figcaption>React Eco-system: React from Scratch</figcaption></figure><p>Finally, we are done with the setup, let’s add some React code to our index.js inside src folder.</p><pre>import React from &#39;react&#39;;<br>import ReactDOM from &#39;react-dom&#39;;</pre><pre>class App extends React.Component {<br>  render() {<br>    return &lt;h1&gt;React Ecosystem: setting up React from Scratch&lt;/h1&gt;;<br>  }<br>}</pre><pre>ReactDOM.render(&lt;App /&gt;, document.getElementById(&#39;root&#39;));</pre><p>Before we run this code, let’s just put this final piece to the puzzle but adding a script to run our code in development, Add the following start command inside scripts in your package.json</p><pre>&quot;start&quot;: &quot;set NODE_ENV=development &amp;&amp; webpack serve --open&quot;</pre><p>Perfect, now let’s run our code by running the following command in your terminal -</p><pre>npm run start</pre><p>this command will trigger the above-mentioned script and will open a new tab on your browser, which will look something like this-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*StPuLd_kcWhyZQwIur4iPw.png" /></figure><p>YEEESSSSS !!!!! We finally did it. Now you can write and test your code in the browser. We are still a long way from a production-grade react application but let’s celebrate this little milestone for now.</p><p>Up Next in this series, We will be setting up <a href="https://abhishek-gangwar.medium.com/how-to-configure-eslint-and-prettier-48470fa8a120">Code linting and code formatting</a>, check out this article series for more info.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*iPzAhSz_h5GYdKyr" /><figcaption>Photo by <a href="https://unsplash.com/@jentheodore?utm_source=medium&amp;utm_medium=referral">Jen Theodore</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=938dd19d5197" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>