<?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: Anubhav Sarkar</title>
    <description>The latest articles on DEV Community by Anubhav Sarkar (@deadwing7x).</description>
    <link>https://dev.to/deadwing7x</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%2F408028%2F62adea38-a9ae-4446-b348-53deff5df86d.jpg</url>
      <title>DEV Community: Anubhav Sarkar</title>
      <link>https://dev.to/deadwing7x</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/deadwing7x"/>
    <language>en</language>
    <item>
      <title>Setup a React App using Webpack, Babel and TypeScript</title>
      <dc:creator>Anubhav Sarkar</dc:creator>
      <pubDate>Fri, 05 Mar 2021 14:31:34 +0000</pubDate>
      <link>https://dev.to/deadwing7x/setup-a-react-app-using-webpack-babel-and-typescript-5927</link>
      <guid>https://dev.to/deadwing7x/setup-a-react-app-using-webpack-babel-and-typescript-5927</guid>
      <description>&lt;p&gt;This article is part of a two part series on how to configure a React app from scratch with Webpack and Babel and eventually add TypeScript to it. To read the first article in this series, click on the below link.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://dev.to/deadwing7x/setup-a-react-app-with-webpack-and-babel-4o3k"&gt;Setup a React app with Webpack and Babel&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  So you stumbled upon &lt;a href="https://www.typescriptlang.org/" rel="noopener noreferrer"&gt;TypeScript&lt;/a&gt; and loved how you will be able to add type safety along with a whole bunch of other things that it has to offer. So, let's modify last week's app and add TypeScript to it. In case you haven't read last week's article on how to setup a react app with webpack and babel, feel free to go through the below link and setup a basic react app to which we can add TypeScript.
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;To get the starter code click on this below link.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Link to the GitHub repo: &lt;a href="https://github.com/deadwing7x/react-with-webpack" rel="noopener noreferrer"&gt;react-with-webpack&lt;/a&gt;&lt;/p&gt;




&lt;h4&gt;
  
  
  Let's start with the required steps now.
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Install the following packages &lt;strong&gt;typescript&lt;/strong&gt;, &lt;br&gt;
&lt;strong&gt;@types/react&lt;/strong&gt; and &lt;strong&gt;@types/react-dom&lt;/strong&gt; using the following command. &lt;/p&gt;

&lt;p&gt;You can also replace the &lt;em&gt;--save-dev&lt;/em&gt; with a more subtle &lt;em&gt;-D&lt;/em&gt; to install any package as a dev dependency.&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

npm install typescript

npm install @types/react @types/react-dom --save-dev
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ol&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
    **@types/react:** contains type definations for React.

    **@types/react-dom:** contains type definations for React DOM.

2. We will need to let Babel know that we are including typescript in the project. So, let's go ahead and install the package **@babel/preset-typescript** as a dev dependency.

    ```


    npm install @babel/preset-typescript --save-dev


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

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Now we have a mean to let Babel know of the typescript files that we will be using. But we still need to load these files with webpack, right? For that we need another package named as &lt;strong&gt;ts-loader&lt;/strong&gt;.&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

npm install -D ts-loader
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ol&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
    Your **package.json** file should look something like this.

    &amp;lt;img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1614875520420/ugOzSsHPE.png" alt="package.json" /&amp;gt;

4. We have all the required packages now. It's time to make some changes in our *webpack.config.js* and *.babelrc* file.

    Replace the below code with the one present in your **.babelrc** file.

    ```


    {
        "presets": [
            "@babel/env",
            "@babel/react",
            "@babel/preset-typescript"
        ],
        "plugins": [
            "@babel/plugin-proposal-class-properties"
        ]
    }


&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;As you can see, we are adding a new preset which is the *@babel/preset-typescript* to our already existing set of presets.

Time to make changes to our **webpack.config.js** file now. Copy the below code and replace the existing code which is present in the file.

```
&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;const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");

module.exports = {
    entry: "./src/index.tsx",
    output: { path: path.join(__dirname, "build"), filename: "index.bundle.js" },
    mode: process.env.NODE_ENV || "development",
    resolve: {
        extensions: [".tsx", ".ts", ".js"],
    },
    devServer: { contentBase: path.join(__dirname, "src") },
    module: {
        rules: [
            {
                test: /\.(js|jsx)$/,
                exclude: /node_modules/,
                use: ["babel-loader"],
            },
            {
                test: /\.(ts|tsx)$/,
                exclude: /node_modules/,
                use: ["ts-loader"],
            },
            {
                test: /\.(css|scss)$/,
                use: ["style-loader", "css-loader"],
            },
            {
                test: /\.(jpg|jpeg|png|gif|mp3|svg)$/,
                use: ["file-loader"],
            },
        ],
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: path.join(__dirname, "src", "index.html"),
        }),
    ],
};
&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;
5. Time to use TypeScript. But wait, we need something to specify that this directory is a TypeScript project, right! We also need to provide the compiler options in which our TypeScript files will be compiled. For that we will need a new file named as **tsconfig.json**.

    Let's go ahead and create that file.

    ```


    touch tsconfig.json


&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;For now, remove the existing code from the **tsconfig.json** file and replace it with the below code.

```
&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;{
    "compilerOptions": {
        "target": "es5",
        "lib": [
            "dom",
            "dom.iterable",
            "esnext"
        ],
        "allowJs": true,
        "skipLibCheck": true,
        "esModuleInterop": true,
        "allowSyntheticDefaultImports": true,
        "strict": true,
        "forceConsistentCasingInFileNames": true,
        "noFallthroughCasesInSwitch": true,
        "module": "esnext",
        "moduleResolution": "node",
        "resolveJsonModule": true,
        "isolatedModules": true,
        "noEmit": false,
        "jsx": "react-jsx"
    },
    "include": [
        "src"
    ]
}
&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;
    Let's go over the attributes now.

    **"target": "es5" =&amp;gt;** will compile es6 or above code to es5 so that it is compatible with browsers.

    **"include": [src]" =&amp;gt;** specifies that only the files in the *src* folder should be included.

    **"sourceMap": true =&amp;gt;** Generates corresponding ‘.map’ file so that it can be used in the production code for debugging.

    **"strict": true =&amp;gt;** enables a wide range of type checking behavior that results in stronger guarantees of program correctness.

    **"allowJs": true =&amp;gt;** allows JavaScript files to be imported inside your project, instead of just .ts and .tsx files.

    To learn more about the various attributes used in the file visit this [link](https://www.typescriptlang.org/tsconfig).

6. Last but not the least, its time to rename our JavaScript files (**.js**) to TypeScript - React (**.tsx**).

      &amp;lt;img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1614876953079/38HnYETS7.png" alt="react-with-typescript" /&amp;gt;

     *renamed index.js &amp;amp; App.js to index.tsx &amp;amp; App.tsx respectively*

7. Go ahead and run the below command to start the app.

    ```


    npm run start


&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;The app will be served at **http://localhost:8080**.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Well, you have successfully added TypeScript to your project. Go ahead and make use of its functionalities to build great webapps.&lt;/p&gt;

&lt;p&gt;Have a great day. Thanks for reading the entire thing.&lt;/p&gt;

&lt;p&gt;Here's the link to the &lt;a href="https://github.com/deadwing7x/react-with-webpack-typescript" rel="noopener noreferrer"&gt;Github Repo&lt;/a&gt; in case you have faced some issue during the entire process. Feel free to make some tweaks if you find something breaking because of updates to any of the packages.&lt;/p&gt;

&lt;p&gt;&lt;span&gt;Cover Photo by &lt;a href="https://unsplash.com/@cristina_gottardi?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText" rel="noopener noreferrer"&gt;Cristina G&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>webpack</category>
      <category>babel</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Setup a React app with Webpack and Babel</title>
      <dc:creator>Anubhav Sarkar</dc:creator>
      <pubDate>Fri, 26 Feb 2021 03:19:48 +0000</pubDate>
      <link>https://dev.to/deadwing7x/setup-a-react-app-with-webpack-and-babel-4o3k</link>
      <guid>https://dev.to/deadwing7x/setup-a-react-app-with-webpack-and-babel-4o3k</guid>
      <description>&lt;p&gt;This article is part of a two part series on how to configure a React app from scratch with Webpack and Babel and eventually add TypeScript to it. To read the second article in this series, click on the below link.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://dev.to/deadwing7x/setup-a-react-app-using-webpack-babel-and-typescript-5927"&gt;Setup a React app with Webpack, Babel and TypeScript&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  So you want to start with a new React app or would like to add &lt;b&gt;&lt;a href="https://reactjs.org/" rel="noopener noreferrer"&gt;React&lt;/a&gt;&lt;/b&gt; to an already existing project, but don't want to use the create-react-app. Well you have come to the right place. I am here to guide you today on how to setup a react app from scratch with &lt;b&gt;&lt;a href="https://webpack.js.org/" rel="noopener noreferrer"&gt;Webpack&lt;/a&gt;&lt;/b&gt; and &lt;b&gt;&lt;a href="https://babeljs.io/" rel="noopener noreferrer"&gt;Babel&lt;/a&gt;&lt;/b&gt;.
&lt;/h4&gt;

&lt;h4&gt;
  
  
  To create a new react app using Webpack and Babel, the first thing which we would need to install is Node JS. You can install the latest version for your machine by going to this &lt;a href="https://nodejs.org/en/" rel="noopener noreferrer"&gt;link&lt;/a&gt;.
&lt;/h4&gt;

&lt;p&gt;Once you have Node JS installed, we can start with the below steps.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Create a new folder. You could use the following commands to create a new folder. Once the folder is created navigate to the folder using the &lt;em&gt;cd&lt;/em&gt; command.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir &amp;lt;folder_name&amp;gt;

cd &amp;lt;folder_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;While you are inside the folder, create a new package.json file, using the command given below.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm init -y
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;This above command generates a package.json file, no questions asked. You could use the below command to generate the file by manually providing all the information.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm init
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;It asks for these few details at the time of creation.&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a. package name (name for your app)
b. version (1.0.0 - initially)
c. description (a small description for your app)
d. entry point (entry point for the module)
e. test (any test command)
f. author (author of the app)
g. git (git repository url and type)
h. license (MIT/ ISC etc.)
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Once the package.json file is created, go ahead and create a '&lt;em&gt;src&lt;/em&gt;' folder. This is where our code will live.&lt;/p&gt;

&lt;p&gt;Now use the touch command to generate these two files:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;touch index.html - (the page which is rendered and visible to the user)

touch index.js - (the entry point for our application)
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Setup an index.html file with the below code and save it.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&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;meta name="viewport"
            content="width=device-width, initial-scale=1, shrink-to-fit=no"
        /&amp;gt;
        &amp;lt;meta name="theme-color" content="#000000" /&amp;gt;
        &amp;lt;title&amp;gt;React with Webpack and Babel&amp;lt;/title&amp;gt;
    &amp;lt;/head&amp;gt;
    &amp;lt;body&amp;gt;
        &amp;lt;noscript&amp;gt;
            You need to enable JavaScript to run this app.
        &amp;lt;/noscript&amp;gt;
        &amp;lt;div id="root"&amp;gt;
            &amp;lt;!-- This div is where our app will run --&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;h4&gt;
  
  
  Note: The file should look like the screenshot below.
&lt;/h4&gt;

&lt;p&gt;Leave the &lt;strong&gt;index.js&lt;/strong&gt; as it is for now. We will configure it after installing all the required packages.&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1614272092314%2FJ4LGQZpEM.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1614272092314%2FJ4LGQZpEM.png" alt="index.html"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Now let's add Webpack to our project.&lt;/p&gt;

&lt;p&gt;Install these packages through npm or yarn, whichever you prefer.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install webpack webpack-cli webpack-dev-server --save-dev
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;&lt;strong&gt;webpack&lt;/strong&gt; allows us to configure our app, &lt;strong&gt;webpack-cli&lt;/strong&gt; helps us to use webpack on command line, &lt;strong&gt;webpack-dev-server&lt;/strong&gt; is used to live reload the webpage so that we can view our changes without refreshing the page manually.&lt;/p&gt;

&lt;p&gt;Once those packages have been installed, the packages should be visible in the &lt;strong&gt;devDependencies&lt;/strong&gt; section like below.&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1614272231627%2FMbQFdCKDw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1614272231627%2FMbQFdCKDw.png" alt="package.json"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;P.S&lt;/strong&gt;: You may want to remove the caret(ˆ) from the version of the packages, as we don't know whether the new updates might bring breaking changes or not. It's always better to manually update the versions.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;It's time to add a new file again. Use the touch command as you did above to add the &lt;strong&gt;webpack.config.js&lt;/strong&gt;. It should be installed at the root directory.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;touch webpack.config.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Let's go ahead and install the &lt;strong&gt;path&lt;/strong&gt; package as a &lt;strong&gt;devDependency&lt;/strong&gt; since we need to work with paths in our app. We wouldn't want to inject the index.js file inside the HTML file. Go ahead and install the &lt;strong&gt;html-webpack-plugin&lt;/strong&gt; to help us do that automatically.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install path html-webpack-plugin --save-dev
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;This is how your package.json should look at the moment.&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1614275861704%2FTDf6PiyME.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1614275861704%2FTDf6PiyME.png" alt="updated package json"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Replace the contents of &lt;strong&gt;index.js&lt;/strong&gt; with the below content.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; (function helloWorld() {
      console.log('Hello World');
 }());

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


&lt;p&gt;Once this is done, let's run webpack and see what happens. Use the command provided below.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; npm run webpack
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;&lt;strong&gt;Webpack&lt;/strong&gt; will automatically take the &lt;strong&gt;src/index.js&lt;/strong&gt; file, compile it and output it to &lt;strong&gt;dist/main.js&lt;/strong&gt; &lt;br&gt;
and minify the code.&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1614276794324%2F2Qo-UPmGU.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1614276794324%2F2Qo-UPmGU.png" alt="npm run  webpack"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;npm run webpack output&lt;/em&gt;&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1614277179543%2F6z2oTupxc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1614277179543%2F6z2oTupxc.png" alt="main js location"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;main.js added to dist folder&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;We can now go ahead and run the &lt;strong&gt;npm start&lt;/strong&gt; command to run the app.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; npm start
&lt;/code&gt;&lt;/pre&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1614277631255%2FazLDjvJHL.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1614277631255%2FazLDjvJHL.png" alt="npm start"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;npm start output&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Naviage to &lt;em&gt;localhost:8080&lt;/em&gt; and you should be able to see a screen just like below.&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1614277651320%2FU5seKF0jW.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1614277651320%2FU5seKF0jW.png" alt="localhost initial"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;localhost started on the default browser&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;To stop the server press, &lt;strong&gt;Ctrl + C&lt;/strong&gt; on Windows and &lt;strong&gt;Command + C&lt;/strong&gt; on Mac.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Copy the code below and paste it in the &lt;strong&gt;webpack.config.js&lt;/strong&gt; file.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");

module.exports = {
    entry: path.join(__dirname, "src", "index.js"),
    output: { path: path.join(__dirname, "build"), filename: "index.bundle.js" },
    mode: process.env.NODE_ENV || "development",
    resolve: { modules: [path.resolve(__dirname, "src"), "node_modules"] },
    devServer: { contentBase: path.join(__dirname, "src") },
    plugins: [
        new HtmlWebpackPlugin({
            template: path.join(__dirname, "src", "index.html"),
        }),
    ],
};
&lt;/code&gt;&lt;/pre&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1614279854359%2FxjEW3e_CU.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1614279854359%2FxjEW3e_CU.png" alt="webpack config js"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;webpack.config.js&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Let's go over the various components in the file.&lt;/p&gt;

&lt;p&gt;a. &lt;strong&gt;entry and output&lt;/strong&gt;: tells our server what has to be compiled and from where. Also tells the server where the compiled version should be outputted.&lt;/p&gt;

&lt;p&gt;b. &lt;strong&gt;mode&lt;/strong&gt;: this is the mode of our output, which is set to ‘development’ for now. Should be changed to 'production' when the app is build for production.&lt;/p&gt;

&lt;p&gt;c. &lt;strong&gt;resolve&lt;/strong&gt;: used so that we can import anything from the &lt;em&gt;src&lt;/em&gt; folder in relative paths rather than the absolute ones, same goes for node_modules as well.&lt;/p&gt;

&lt;p&gt;d. &lt;strong&gt;devServer&lt;/strong&gt;: this tells the webpack-dev-server what files are needed to be served. Everything from our src folder needs to be served (outputted) in the browser.&lt;/p&gt;

&lt;p&gt;e. &lt;strong&gt;plugins&lt;/strong&gt;: here we set what plugins we need in our app. As of this moment we only need the html-webpack-plugin which tells the server that the index.bundle.js should be injected (or added if you will) to our index.html file&lt;/p&gt;

&lt;p&gt;If we now run the earlier command, we will see some differences.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; npm run webpack
&lt;/code&gt;&lt;/pre&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1614280215803%2Fz_Hy6fRRv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1614280215803%2Fz_Hy6fRRv.png" alt="npm run webpack"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;npm run webpack output&lt;/em&gt;&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1614280239289%2FiNR2hRCJX.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1614280239289%2FiNR2hRCJX.png" alt="build folder"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;build folder with index.build.js and index.html&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If you start the app now, using the &lt;em&gt;npm start&lt;/em&gt; command, you would see a blank screen on the browser, without any content.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; npm start
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Open the developer tools on your browser and you should be able to see the entire code of the &lt;em&gt;index.html&lt;/em&gt; file in the Elements tab. Check the Console tab to see Hello World logged over there. The webpack-dev-server took everything from the &lt;strong&gt;src&lt;/strong&gt; folder and outputted it to our browser.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;We have configured the app to build everything from the &lt;strong&gt;src&lt;/strong&gt; folder and output it to the browser. It's time to add React and spice things up a little. &lt;/p&gt;

&lt;p&gt;Follow the following steps to add React and Babel to the project. Run the following command to add &lt;br&gt;
  &lt;strong&gt;react&lt;/strong&gt; and &lt;strong&gt;react-dom&lt;/strong&gt; to the project.&lt;/p&gt;

&lt;p&gt;Add &lt;strong&gt;react&lt;/strong&gt; and &lt;strong&gt;react-dom&lt;/strong&gt; as normal dependencies.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  npm install react react-dom --save
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;At this moment in our development, if we were to add React code inside our JS file, &lt;strong&gt;Webpack&lt;/strong&gt; will give us an error. It doesn’t know how to compile React inside the &lt;strong&gt;bundle.js&lt;/strong&gt; file.&lt;/p&gt;

&lt;p&gt;Modify the &lt;strong&gt;index.js&lt;/strong&gt; file as follows:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';
import ReactDOM from 'react-dom';

const HelloWorld = () =&amp;gt; {
    return (
        &amp;lt;h1&amp;gt;
            Hello World
        &amp;lt;/h1&amp;gt;
    );
}

ReactDOM.render(&amp;lt;HelloWorld /&amp;gt;, document.getElementById("root"));
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Let's start the server now and see what is rendered.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm start
&lt;/code&gt;&lt;/pre&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1614281949158%2FXXS5UzuA7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1614281949158%2FXXS5UzuA7.png" alt="babel loader error"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;webpack error for not having **appropriate loaders for react&lt;/em&gt;**&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;This is where &lt;strong&gt;Babel&lt;/strong&gt; comes to our aid. Babel will tell &lt;strong&gt;Webpack&lt;/strong&gt; how to compile our React code.&lt;/p&gt;

&lt;p&gt;Let’s add a bunch of Babel packages to our app as &lt;strong&gt;devDependencies&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  npm install --save-dev @babel/core @babel/node @babel/preset-env @babel/preset-react babel-loader
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Some two pointers about these packages.&lt;/p&gt;

&lt;p&gt;a. &lt;strong&gt;&lt;a class="mentioned-user" href="https://dev.to/babel"&gt;@babel&lt;/a&gt;/core&lt;/strong&gt;: used to compile &lt;strong&gt;ES6&lt;/strong&gt; and above to &lt;strong&gt;ES5&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;b. &lt;strong&gt;&lt;a class="mentioned-user" href="https://dev.to/babel"&gt;@babel&lt;/a&gt;/preset-env&lt;/strong&gt;: determines which transformations or plugins to use and polyfills (i.e it provides modern functionality on older browsers that do not natively support it) based on the browser matrix you want to support.&lt;/p&gt;

&lt;p&gt;c. &lt;strong&gt;&lt;a class="mentioned-user" href="https://dev.to/babel"&gt;@babel&lt;/a&gt;/preset-react&lt;/strong&gt;: compiles the React code into ES5 code.&lt;/p&gt;

&lt;p&gt;d. &lt;strong&gt;babel-loader&lt;/strong&gt;: a Webpack helper that transforms your JavaScript dependencies with Babel (i.e. will transform the import statements into require ones)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You will probably need to add some styles to the project, as well as have the ability to display images on the webpage.&lt;/p&gt;

&lt;p&gt;Go ahead and add these few packages as &lt;strong&gt;devDependencies&lt;/strong&gt;. (Remove the sass-loader and node-sass if know you won't be working with SCSS files).&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; npm install style-loader css-loader sass-loader node-sass image-webpack-loader --save-dev 
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;a. &lt;strong&gt;style-loader&lt;/strong&gt;: will add styles to the DOM (injects a &lt;strong&gt;style&lt;/strong&gt; tag inside the HTML file).&lt;/p&gt;

&lt;p&gt;b. &lt;strong&gt;css-loader&lt;/strong&gt;: lets us import CSS files in our project.&lt;/p&gt;

&lt;p&gt;c. &lt;strong&gt;sass-loader&lt;/strong&gt;: lets us import SCSS files in our project.&lt;/p&gt;

&lt;p&gt;d. &lt;strong&gt;node-sass&lt;/strong&gt;: compiles SCSS files into normal CSS files.&lt;/p&gt;

&lt;p&gt;e. &lt;strong&gt;image-webpack-loader&lt;/strong&gt;: lets us load images in our project.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Next thing to do is add a configuration file for Babel. For this we need to create a file named &lt;strong&gt;.babelrc&lt;/strong&gt; in which we will configure Babel. Create this file in the root directory.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;touch .babelrc
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Add these lines to let &lt;strong&gt;babel-loader&lt;/strong&gt; know what to use to compile the code.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "presets": [
        "@babel/env",
        "@babel/react"
    ]
}
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;After these steps, we will need to add something to our project so we can import all sorts of files such as images. We will also need to add a plugin that will let us work with classes and much more. Let us add class properties in our classes. Basically, it will let us work with Object Oriented Programming.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install file-loader @babel/plugin-proposal-class-properties --save-dev
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Once that is done, we need to make some changes inside webpack.config.js so that Webpack will now use Babel. We’ll also configure Webpack to listen for style files and we are going to change the require statements to import ones.&lt;/p&gt;

&lt;p&gt;Change your &lt;strong&gt;webpack.config.js&lt;/strong&gt; to the below code:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");

module.exports = {
    entry: path.join(__dirname, "src", "index.js"),
    output: { path: path.join(__dirname, "build"), filename: "index.bundle.js" },
    mode: process.env.NODE_ENV || "development",
    resolve: { modules: [path.resolve(__dirname, "src"), "node_modules"] },
    devServer: { contentBase: path.join(__dirname, "src") },
    module: {
        rules: [
            { 
                test: /\.(js|jsx)$/, 
                exclude: /node_modules/, 
                use: ["babel-loader"] 
            },
            {
                test: /\.(css|scss)$/,
                use: ["style-loader", "css-loader"],
            },
            { 
                test: /\.(jpg|jpeg|png|gif|mp3|svg)$/,
                use: ["file-loader"] 
            },
        ],
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: path.join(__dirname, "src", "index.html"),
        }),
    ],
};
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Your &lt;strong&gt;webpack.config.js&lt;/strong&gt; should look like this now.&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1614286830506%2FO3OTspneT.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1614286830506%2FO3OTspneT.png" alt="new webpack config"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Match the package.json in your project with the below image.&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1614286555018%2FnhX6hTBCC.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1614286555018%2FnhX6hTBCC.png" alt="final package json"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Another thing that we will have to still add is the &lt;a class="mentioned-user" href="https://dev.to/babel"&gt;@babel&lt;/a&gt;/plugin-proposal-class-properties to the .babelrc file. Babel will know how to deal with class properties.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "presets": [
        "@babel/env",
        "@babel/react"
    ],
    "plugins": [
        "@babel/plugin-proposal-class-properties"
    ]
}
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;We have reached the end of this tutorial. Now let's run the previous commands and they shouldn't give us any error.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run webpack

npm start
&lt;/code&gt;&lt;/pre&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1614286968507%2FLlX_5oUoE.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1614286968507%2FLlX_5oUoE.png" alt="final render"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;final output on browser&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If you have reached this step, make sure to remind yourself that you are awesome. You have learned something new today. Have a great day. Thanks for reading the entire thing.&lt;/p&gt;

&lt;p&gt;Here's the link to the  &lt;a href="https://github.com/deadwing7x/react-with-webpack" rel="noopener noreferrer"&gt;Github Repo&lt;/a&gt; in case you have faced some issue during the entire process. Feel free to make some tweaks if you find something breaking because of updates to any of the packages.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;span&gt;Photo by &lt;a href="https://unsplash.com/@tamofoto?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText" rel="noopener noreferrer"&gt;Tamara Bitter&lt;/a&gt; on &lt;a href="https://unsplash.com/@deadwing7x/likes?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>babel</category>
      <category>webpack</category>
    </item>
    <item>
      <title>Portfolio Website</title>
      <dc:creator>Anubhav Sarkar</dc:creator>
      <pubDate>Sun, 21 Feb 2021 17:12:13 +0000</pubDate>
      <link>https://dev.to/deadwing7x/portfolio-website-4jb9</link>
      <guid>https://dev.to/deadwing7x/portfolio-website-4jb9</guid>
      <description>&lt;p&gt;Hello everyone. I took a dig at Next JS along with Tailwind CSS and tried to create a portfolio website for myself with React. The website is hosted at &lt;a href="https://anubhav7x.com"&gt;https://anubhav7x.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Please take a look at it and provide your feedbacks. &lt;/p&gt;

&lt;p&gt;Looking forward to some informational reviews.&lt;/p&gt;

&lt;p&gt;Thanks in advance 😉😎&lt;/p&gt;

</description>
      <category>react</category>
      <category>typescript</category>
      <category>tailwindcss</category>
      <category>nextjs</category>
    </item>
    <item>
      <title>GitHub app fails after deploying to production</title>
      <dc:creator>Anubhav Sarkar</dc:creator>
      <pubDate>Fri, 28 Aug 2020 17:37:19 +0000</pubDate>
      <link>https://dev.to/deadwing7x/github-app-fails-after-deploying-to-production-8pb</link>
      <guid>https://dev.to/deadwing7x/github-app-fails-after-deploying-to-production-8pb</guid>
      <description>&lt;p&gt;So I have this github app, which manages to update file content and create new files when I use it on my localhost. But as soon as I deploy the app to production, it fails and gives an error saying 403 forbidden "Resource not accessible by integration". Any help on this topic will be hugely appreciated. I have been blocked for a week now and this frustrating.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; Managed to get it up and running. Needed a Personal Access Token to be genarated and passed on to the Authorization Header while making the service call.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://stackoverflow.com/questions/63638496/any-idea-why-my-github-app-manages-to-update-the-file-content-using-the-same-ser"&gt;https://stackoverflow.com/questions/63638496/any-idea-why-my-github-app-manages-to-update-the-file-content-using-the-same-ser&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
