<?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 Harshwardhan Rathore on Medium]]></title>
        <description><![CDATA[Stories by Harshwardhan Rathore on Medium]]></description>
        <link>https://medium.com/@harshwardhan_ra?source=rss-da1d97bab752------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*MMZlt-mQ3avQX1wPBF_A_g.jpeg</url>
            <title>Stories by Harshwardhan Rathore on Medium</title>
            <link>https://medium.com/@harshwardhan_ra?source=rss-da1d97bab752------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 19:40:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@harshwardhan_ra/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[How to write/upgrade your webpack plugin for adding support for webpack 4.]]></title>
            <link>https://medium.com/front-end-weekly/how-to-write-upgrade-your-webpack-plugin-for-adding-support-for-webpack-4-9e6f1ab81677?source=rss-da1d97bab752------2</link>
            <guid isPermaLink="false">https://medium.com/p/9e6f1ab81677</guid>
            <category><![CDATA[webpack-plugin]]></category>
            <category><![CDATA[webpack]]></category>
            <category><![CDATA[webpack4]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Harshwardhan Rathore]]></dc:creator>
            <pubDate>Sat, 30 Dec 2017 17:46:40 GMT</pubDate>
            <atom:updated>2018-12-10T13:25:52.651Z</atom:updated>
            <content:encoded><![CDATA[<p>Webpack 4 alpha.2 is out and it’s time that your plugin supports webpack 4.</p><p>If you are new to writing webpack plugin, then please click <a href="https://medium.com/@Uneducated/how-to-write-your-first-webpack-plugin-c5d6a175f2dc">here</a>. This post require a basic knowledge of writing webpack plugin.</p><p>Done? Awesome, now that you have a basic understanding of how to write a <strong>webpack</strong> plugin from scratch lets start and see what has really changed in <strong>webpack 4</strong> and what pieces you need to change to support <strong>webpack 4.</strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Ff%2F788447%3Fas_embed%3Dtrue&amp;dntp=1&amp;display_name=Upscribe&amp;url=https%3A%2F%2Fupscri.be%2F788447%2F&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/18214d8333adbb5668f31791a3202b60/href">https://medium.com/media/18214d8333adbb5668f31791a3202b60/href</a></iframe><p>Remember the amazing <strong>HelloWorld</strong> plugin that we wrote <a href="https://medium.com/@Uneducated/how-to-write-your-first-webpack-plugin-c5d6a175f2dc">here</a>, we are going to make changes to the same file to support <strong>webpack 4</strong>.</p><p>The only piece the has changed in <strong>webpack 4</strong> is how you plug into the <strong>Tapable</strong> instance.</p><p>Earlier(Webpack 3):</p><pre>apply(compiler) {<br>  compiler.plugin(&quot;done&quot;, () =&gt; {<br>    console.log(&quot;Hello world&quot;);<br>})</pre><p>Here we are listening the “done” event on the <strong>Tapable</strong> instance “<em>compiler</em>” using compiler.plugin(&quot;done&quot;, fn) where fn represents the function that you want to execute on the done event.</p><p>Webpack4 version:</p><pre>apply(compiler) {<br>  compiler.hooks.done.tap(&quot;HelloWorld&quot;, () =&gt; {<br>   console.log(&quot;Hello world&quot;);<br>})</pre><p>Here the compiler has the method named hooks on which we can chain the event name we want to listen to and then we are taping on this instance using .tap method.</p><p>The tap method expects two arguments, first one is of type string which should be the <em>name of your plugin class</em> which in our case is “<strong>HelloWorld</strong>” and second one is the function that we want to execute on “<strong>done</strong>” event.</p><p>That’s pretty much it, everything else in our plugin code remains the same. So after the above modification our final code for “<strong>HelloWorld</strong>” plugin should look like this.</p><pre>class HelloWorld {<br>  constructor(options) {<br>    this.options = options;<br>  }<br>  <br>  apply(compiler) {<br>    compiler.hooks.done.tap(&quot;HelloWorld&quot;, () =&gt; {<br>      console.log(this.options.message);<br>  })<br>}</pre><pre>module.exports = HelloWorld;</pre><p>Let me know if you face any trouble in adding support for webpack 4.</p><p><a href="https://github.com/HarshwardhanSingh/webpack-bundle-size-check-plugin/tree/add-webpack-4-support">Here</a> is my webpack plugin after adding the support for webpack 4. Check out the same plugin for webpack 3 <a href="https://github.com/HarshwardhanSingh/webpack-bundle-size-check-plugin/tree/master">here</a>.</p><h3>Testing your new plugin.</h3><p>For testing if your changes are working as expected you need to upgrade webpack in your app to 4.0.0-alpha.2 For this you need to do 2 things.</p><ol><li>Update you package.json file with the new version and run npm install</li></ol><pre>&quot;webpack&quot;: &quot;^4.0.0-alpha.2&quot;</pre><p>2. In the new <strong>webpack</strong> the <strong>webpack-cli</strong> has been moved to a different package so if you want to use webpack command in console, you need to add this package separately.</p><pre>npm install --save-dev webpack-cli</pre><p>Now your test app is ready for your upgraded plugin.</p><p>Thanks for reading. Please 👏 if you liked this post and let me know if you face any trouble in the process. I will be more than happy to help.</p><p>Follow me on <a href="https://twitter.com/_harshwardhan94">Twitter</a> and <a href="https://github.com/HarshwardhanSingh">Github</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9e6f1ab81677" width="1" height="1" alt=""><hr><p><a href="https://medium.com/front-end-weekly/how-to-write-upgrade-your-webpack-plugin-for-adding-support-for-webpack-4-9e6f1ab81677">How to write/upgrade your webpack plugin for adding support for webpack 4.</a> was originally published in <a href="https://medium.com/front-end-weekly">Frontend Weekly</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to write your first webpack plugin?]]></title>
            <link>https://medium.com/front-end-weekly/how-to-write-your-first-webpack-plugin-c5d6a175f2dc?source=rss-da1d97bab752------2</link>
            <guid isPermaLink="false">https://medium.com/p/c5d6a175f2dc</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[webpack]]></category>
            <category><![CDATA[webpack-3]]></category>
            <category><![CDATA[open-source-software]]></category>
            <dc:creator><![CDATA[Harshwardhan Rathore]]></dc:creator>
            <pubDate>Fri, 29 Dec 2017 15:06:40 GMT</pubDate>
            <atom:updated>2018-01-05T08:38:24.800Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Check the second part <a href="https://medium.com/@Uneducated/how-to-write-upgrade-your-webpack-plugin-for-adding-support-for-webpack-4-9e6f1ab81677">here</a></blockquote><p>You won’t face a situation where your project have some specific requirement for which there is no plugin available. But if you find yourself in a situation where there is no other way but to write a custom plugin yourself then don’t worry it’s not that hard.</p><p>In this post I will show you how to write your own webpack-plugin from scratch. So let’s get started.</p><p>You should keep these point in mind while writing a webpack plugin.</p><ol><li>Webpack follows Object oriented approach and so should your plugin.</li><li>Your plugin class should have an “apply” method which accepts an argument “compiler”.</li></ol><p>Now that we have our basic requirement in place, lets create a plugin.</p><ol><li>Create a file HelloWorld. This will the main file which will have your plugin class. As I explained above it should have an apply method which accepts compiler as it’s argument.</li></ol><pre>class HelloWorld {<br>  apply(compiler) {<br>    <br>  }<br>}</pre><p>The compiler is an instance of <strong>Tapable</strong> on which you can listen to different events and execute your code. If you want to check all the event hooks available in webpack check <a href="https://webpack.js.org/api/compiler/#event-hooks">here</a>.</p><p>2. In this example for simplicity I am going to listen to “done” event and display a message using console.log</p><pre>class HelloWorld {<br>  apply(compiler) {<br>    compiler.plugin(&quot;done&quot;, () =&gt; {<br>      console.log(&quot;Hello world&quot;);<br>  })<br>}</pre><p>3. Import this into your test app which is using webpack and add this plugin to your plugins array like this.</p><pre>const HelloWorld = require(&#39;relative/path/to/above/created/file&#39;)</pre><pre>plugins: [<br>  new HelloWorld()<br>]</pre><p>4. Run webpack or webpack-dev-server you will see your “Hello world” statement just before the emitted chunks.</p><p>5. If you want to pass some configuration to your plugin, all you need to do is add constructor to your HelloWorld class which accepts the passed arguments.</p><pre>class HelloWorld {<br>  constructor(options) {<br>    this.options = options;<br>  }<br>  <br>  apply(compiler) {<br>    compiler.plugin(&quot;done&quot;, () =&gt; {<br>      console.log(this.options.message);<br>  })<br>}</pre><p>6. Now pass this message from the webpack config file.</p><pre>const HelloWorld = require(&#39;relative/path/to/above/created/file&#39;)</pre><pre>plugins: [<br>  new HelloWorld({<br>    message: &quot;Hello world from the config&quot;<br>  })<br>]</pre><p>and voila! you have created your first webpack plugin. Now I know this was a simple example but try to hook into different event and see what you can build. There are endless possibilities.</p><p>You can check out my Webpack plugin for reference which I created just today at <a href="https://github.com/HarshwardhanSingh/webpack-bundle-size-check-plugin">Github</a>. This plugin helps keep you track of your bundle size and you can configure it according to your needs, check <a href="https://github.com/HarshwardhanSingh/webpack-bundle-size-check-plugin">github readme</a> for more info.</p><p>Feel free to ask if you face any difficulty.</p><p>Thanks for reading. :) Please 👏 if you like this post.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c5d6a175f2dc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/front-end-weekly/how-to-write-your-first-webpack-plugin-c5d6a175f2dc">How to write your first webpack plugin?</a> was originally published in <a href="https://medium.com/front-end-weekly">Frontend Weekly</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Higher Order Component(HOC) design pattern in React.]]></title>
            <link>https://medium.com/front-end-weekly/higher-order-component-hoc-design-pattern-in-react-9a6ba4eec59d?source=rss-da1d97bab752------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a6ba4eec59d</guid>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[es6]]></category>
            <dc:creator><![CDATA[Harshwardhan Rathore]]></dc:creator>
            <pubDate>Wed, 27 Dec 2017 13:38:02 GMT</pubDate>
            <atom:updated>2018-11-09T16:39:22.754Z</atom:updated>
            <content:encoded><![CDATA[<p>This post is about how you can make use of HOC design pattern to write better code which is easy to maintain and understand even by a new developer.</p><p>Topics we are going to cover in this post:</p><ol><li>What are HOC and how to write one?</li><li>What are the benefits of following HOC pattern?</li></ol><p>In this post I will explain the above to points with a real world example. We are going to write a small feature (Login form).</p><p>So what is Higher Order Component? A Higher order component is a function that takes a component as an argument and returns a new component.</p><p>Consider you are writing a user login feature for your awesome app. So you will write something like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8e57325180c5e6fa4867a199bf181ab2/href">https://medium.com/media/8e57325180c5e6fa4867a199bf181ab2/href</a></iframe><p>As you can see the representation part of this form is just a form with two input fields and a submit button.</p><p>Now consider a situation where you have to add exact same functionality but with different ui in a different part of your app. You would like to re-use this component but the representation is entirely different.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Ff%2F788447%3Fas_embed%3Dtrue&amp;dntp=1&amp;display_name=Upscribe&amp;url=https%3A%2F%2Fupscri.be%2F788447%2F&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/18214d8333adbb5668f31791a3202b60/href">https://medium.com/media/18214d8333adbb5668f31791a3202b60/href</a></iframe><p><strong>How would you solve that problem?</strong> Chances are you might end up creating two stateless component for the two forms and pass the handlers as props to these components, which is a right approach to go with but that doesn’t look so clean does it? Have a look how can we solve the same problem with an HOC.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/59f3dc0288df1479bf8c01687d12c1b3/href">https://medium.com/media/59f3dc0288df1479bf8c01687d12c1b3/href</a></iframe><p>and that’s it. Now it doesn’t matter how many login forms you need in you app you just need to wrap that new shiny login form with this `LoginHOC` and you will have access to all the props that you are passing from HOC. Even if there is some other feature that you want to add you have to add it in your LoginHOC and everything will work just fine.</p><p>If you are following any other pattern to tackle the same problem, you should try using HOC pattern in your app and I am sure you won’t regret it.</p><p>Thanks for reading now make something great :).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9a6ba4eec59d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/front-end-weekly/higher-order-component-hoc-design-pattern-in-react-9a6ba4eec59d">Higher Order Component(HOC) design pattern in React.</a> was originally published in <a href="https://medium.com/front-end-weekly">Frontend Weekly</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Power of Constructor function in Javascript]]></title>
            <link>https://medium.com/@harshwardhan_ra/the-power-of-constructor-function-in-javascript-a45548f53a44?source=rss-da1d97bab752------2</link>
            <guid isPermaLink="false">https://medium.com/p/a45548f53a44</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Harshwardhan Rathore]]></dc:creator>
            <pubDate>Sun, 21 May 2017 15:19:45 GMT</pubDate>
            <atom:updated>2017-05-21T16:16:35.504Z</atom:updated>
            <content:encoded><![CDATA[<pre>var john = new Person(fname, lname, age)</pre><p>to most of you this code would look familiar but for a Javascript beginner this thing is new. If you come from an Object Oriented programming language like ruby or C++ , your first though would be that “Person” is a class which it isn’t. “Person” is a function which you call with a new keyword. It returns nothing but creates a new object, assign the parameters passed to it to the properties of that object and assign it to the variable john in this case. You can also call it a prototype object for newly created john object.</p><p>The code for this constructor function is shown below. It takes some argument and assign these values to this new object, john in this case.</p><pre>function Person(fname, lname, age) {<br>    this.fname = fname;<br>    this.lname = lname;<br>    this.age = age;<br>}</pre><p>One main thing to note here is that constructor function never returns a value. These are the functions which are used only to create new Objects and does not return any value. The moment you put a return in a constructor function, it is no longer a constructor function.</p><p>So the line var harsh = new Person(&#39;harsh&#39;, &#39;rathore&#39;, 23) will create a fresh new object with props {fname: &#39;harsh&#39;, lname: &#39;rathore&#39;, age:23} and will assign it to variable harsh . Alternatively you could create this object like</p><pre>var harsh = {<br>   fname: &#39;harsh&#39;,<br>   lname: &#39;rathore&#39;,<br>   age: 23<br>}</pre><p>Clearly using constructor function is neat, easy and expressive syntax.</p><p>The one advantage that constructor function gives is, it sets base object “Person” in this case as the prototype for all the objects created using this constructor function. So if you want to create some methods on all the objects, or on some objects created from this “Person” constructor function all you need to do it declare this method on this “Person” constructor function and you are done.</p><pre>Person.prototype.fullName = function() {<br>    console.log(this.fname + &#39; &#39; + this.lname);<br>}</pre><p>This reduces the code that you have to write and the size of your script as no matter how many objects you have created from “Person” constructor there will be only single fullName function. You can call this fullName method on any object created from “Person” constructor function and it will work, because all these objects have same prototype as of “Person”.</p><p><strong>So what happens when you call </strong><strong>fullName on any object created from “Person” constructor function?</strong></p><p>The Javascript engine will search it on that particular object and will not find it there, so now it will go down the prototype chain and will search it on the prototype of harsh object, which is same as that of “Person”, as we have defined it on the prototype of “Person” it will find it sitting on its prototype and will return the expected result. Isn’t it amazing.</p><p>Try to use constructor function whenever you have to create multiple objects with same set of properties and you will be amazed by its power.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a45548f53a44" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>