<?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 ali yousefi on Medium]]></title>
        <description><![CDATA[Stories by ali yousefi on Medium]]></description>
        <link>https://medium.com/@aliyr7592?source=rss-22101e76887c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*HcYQi-osCdgJQncF_Ba1mA.png</url>
            <title>Stories by ali yousefi on Medium</title>
            <link>https://medium.com/@aliyr7592?source=rss-22101e76887c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 02:13:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aliyr7592/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 Create, test and publish a Vuejs Reusable component using Vue-cli]]></title>
            <link>https://medium.com/@aliyr7592/how-to-create-test-and-publish-a-vuejs-reusable-component-using-vue-cli-6fa013d63929?source=rss-22101e76887c------2</link>
            <guid isPermaLink="false">https://medium.com/p/6fa013d63929</guid>
            <category><![CDATA[vue]]></category>
            <category><![CDATA[npm]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[ali yousefi]]></dc:creator>
            <pubDate>Mon, 04 Feb 2019 10:21:41 GMT</pubDate>
            <atom:updated>2019-02-04T10:21:41.043Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PFZYKnjoqyfD2SHG" /><figcaption>Photo by <a href="https://unsplash.com/@chuttersnap?utm_source=medium&amp;utm_medium=referral">chuttersnap</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In this article, I wanna show you how simply create a component library Using Vue-cli, test it locally and publish it on npm as an npm package</p><p>first of all, create a Vue-cli project and name it vue-custom-checkbox :</p><pre>vue create vue-custom-checkbox</pre><p><strong>Hint</strong>: if you aren’t familiar with Vue-cli, visit <a href="https://cli.vuejs.org/guide/"><strong>official Vue-cli website</strong></a></p><p>after that, in components folder, create a new component and name it Checkbox :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1d8a253a3953d40cd4c023f24346997f/href">https://medium.com/media/1d8a253a3953d40cd4c023f24346997f/href</a></iframe><p>for the local test, use it on App.vue :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/51060b447149dcfd063baab48787a3be/href">https://medium.com/media/51060b447149dcfd063baab48787a3be/href</a></iframe><p>now our component is ready for external use.</p><h4>Step 1: Add the component to main.js</h4><p>in order to use our component, we need to import it to a javascript file and then export it.</p><p>Remember in this case, we don’t really <strong>have to </strong>import and export the component<strong>, </strong>but if we have more than one component, we should do this job, because we need to export them together in a single file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6eb062700e22fbe9591050a4cb2af1c1/href">https://medium.com/media/6eb062700e22fbe9591050a4cb2af1c1/href</a></iframe><h4>Step 2: Add the main package file to package.json</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/06d0e7f14e5c24f407659df8e93156d0/href">https://medium.com/media/06d0e7f14e5c24f407659df8e93156d0/href</a></iframe><p>every npm package should have the main property that should be imported into any project that we want to use.in other words, the only javascript file that will be used in other projects is the file that we pass into main property</p><p>if you have main style file that should be included, use style property</p><h4>Step 3: Test our package locally</h4><p>in order to do so, we use <a href="https://docs.npmjs.com/cli/link.html">npm link</a>, run this command on your component package :</p><pre>npm link</pre><p>then in the destination project :</p><pre>npm link vue-custom-checkbox</pre><p>these two commands, export our package as a global package on our global node_modules folder and add it into the destination project. so we can use our component in another project and test its functionality locally.<br>for Example, use Checkbox component destination project:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/85986eb9fe04005d2020e0c8004d1c25/href">https://medium.com/media/85986eb9fe04005d2020e0c8004d1c25/href</a></iframe><h4>Step 4: Publish to npm</h4><p>finally, publish our component package:</p><pre>npm publish</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6fa013d63929" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating React Component Library and testing it locally]]></title>
            <link>https://medium.com/@aliyr7592/when-i-wanted-to-make-a-react-component-library-in-order-to-reuse-my-code-i-read-many-articles-dc36c98a6cde?source=rss-22101e76887c------2</link>
            <guid isPermaLink="false">https://medium.com/p/dc36c98a6cde</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[component-libraries]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[components]]></category>
            <dc:creator><![CDATA[ali yousefi]]></dc:creator>
            <pubDate>Sat, 29 Sep 2018 20:21:49 GMT</pubDate>
            <atom:updated>2018-09-30T09:52:38.032Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sWZoXXRhOliuyKHRFtbxNQ.png" /></figure><p>When I wanted to make a React Component Library in order to reuse my code, I read many articles and packages to make a boilerplate for easily creating and testing my component library and I found some tutorials about it but most of them were using npm link to communicate between the playground app (the app that should be a platform for checking the result ) and our component library, and what I found is npm link has some problems with windows .</p><p>so in this article, we are going to make a react component library boilerplate without any use of npm link and stuff like that.</p><p>in this article, we are going to create two separate projects which one of them is our <strong>playground project</strong>, which is used for testing our component library and the second one is the main project that we use it to build up our library</p><p>the completed project can be found in this link : <a href="https://github.com/aliyr/React-library-boilerplate/">https://github.com/aliyr/React-library-boilerplate/</a></p><h3>step 1 : create the structure</h3><p>the first thing is that we create our main project folders.</p><p>open up your terminal and make these folders :</p><pre>&gt; mkdir react-library-boilerplate</pre><pre>&gt; cd react-library-boilerplate</pre><pre>&gt; mkdir boilerplate</pre><p><strong>note</strong> : we will make playground project from another way !</p><p>as mentioned before , we have been created two separate projects for creating our react component library and test it in playground project.</p><h3>step 2 : create boilerplate project</h3><p>the second and main step , we are going to create boilerplate project . simply run this command :</p><pre>&gt; npm init</pre><pre>package name: (boilerplate)</pre><pre>version: (1.0.0)</pre><pre>description: a boilerplate for easily creating and testing react component libs !</pre><pre>entry point: (index.js)</pre><pre>test command:</pre><pre>git repository:</pre><pre>keywords:</pre><pre>author: alious</pre><pre>license: (ISC)</pre><p>now, our project is created and ready to develop! for the second step, its’s time to install react and react-dom</p><pre>&gt; npm install react react-dom</pre><p>and also babel and webpack :</p><pre>&gt; npm install --save-dev babel-cli babel-core babel-loader babel-preset-env webpack-cli webpack <br>&gt; npm install babel-preset-react babel-preset-es2015</pre><p>next up, create 3 folder named dist , lib and src so our project should be like this :</p><pre>├--- boilerplate<br>      ├--- /src<br>      ├--- /lib<br>      ├--- /dist<br>      ├--- /node_modules<br>      └--- package.json</pre><p>the next step is to configure .babelrcand webpack.config.js in the root of the project and then simply copy and paste the code below to webpack.config.js :</p><pre>const webpack = require(&#39;webpack&#39;);</pre><pre>module.exports = {</pre><pre>    devtool:&#39;source-map&#39;,</pre><pre>    entry: &#39;./src/index.js&#39;,</pre><pre>    output: {</pre><pre>        path : __dirname + &quot;/dist&quot;,</pre><pre>        filename : &quot;bundle.js&quot;</pre><pre>    },</pre><pre>    devServer: {</pre><pre>        inline: false,</pre><pre>        contentBase: &quot;./dist&quot;,</pre><pre>    },</pre><pre>    module: {</pre><pre>    rules: [</pre><pre>         {</pre><pre>             test:/\.js$/,</pre><pre>             exclude:/node_modules/,</pre><pre>             loader: &quot;babel-loader&quot;,</pre><pre>          },</pre><pre>         {</pre><pre>         test:/\.css$/,</pre><pre>         loader : [&quot;style-loader&quot;,&quot;css-loader&quot;]</pre><pre>       }</pre><pre>      ]</pre><pre>},</pre><pre>plugins: [</pre><pre>    new webpack.DefinePlugin({</pre><pre>    &#39;process.env&#39;: {</pre><pre>    &quot;NODE_ENV&quot;: JSON.stringify(&#39;production&#39;)</pre><pre>    }</pre><pre>  })</pre><pre> ]</pre><pre>}</pre><p>and this code to .babelrc :</p><pre>{</pre><pre>&quot;presets&quot;: [</pre><pre>    &quot;es2015&quot;,</pre><pre>    &quot;react&quot;</pre><pre>   ]</pre><pre>}</pre><p>these codes up above , help us to transpile our code from es6 or above to es5 ( .babelrc) and get a production build from our project (webpack.config.js)</p><p>next up, in the /src folder, let’s create a component and name it Button.js :</p><pre>import React , {Component} from &#39;react&#39;;</pre><pre>class Button extends Component{</pre><pre>   constructor(props) {</pre><pre>      super(props);</pre><pre>   }</pre><pre>   render() {</pre><pre>      return(</pre><pre>         &lt;button&gt;hello {this.props.text}!&lt;/button&gt;</pre><pre>      )</pre><pre>   }</pre><pre>}</pre><p>there is nothing special about this component, but you can add more logics and JSX tags to it .</p><p>now, it’s time to build and transpile our component . to do so, we make two scripts for transpile and build operation , open up your package.json file and add these two commands to &quot;scripts&quot; :</p><pre>&quot;transpile&quot;: &quot;node_modules/.bin/babel ./src --presets babel-preset-es2015 -d lib&quot;,</pre><pre>&quot;build&quot;: &quot;webpack --progress --colors --p&quot;</pre><p>first command tells the babel to get all the files in /src folder and convert them to es5 and put them into /lib folder.</p><p>second command simply get a production build from our project.</p><p>for the next step, simply run npm run transpile . now we can see Button.js has been converted to ES5 and ready to use !</p><p>in order to make our boilerplate readable by another project (in our case, playground project), we have to make the component our main file, so open up the package.json file and change the &quot;main&quot;: &quot;index.js&quot; into component path, in our case it’s : lib/Button.js .</p><h3>step 3 : create playground project</h3><p>in the previous step, our boilerplate project was completed and ready to use, and in this step we are going to create a simple project which let us to test our component library :</p><p>let’s open up the terminal and navigate to main directory create a react project via create-react-app :</p><pre>&gt; npm init react-app playground<br>&gt; cd playground</pre><p>now, we need to import our boilerplate project to playground project, in order to do so, we have to add our boilerplate project path to dependencies of the playground project, so open up the package.json and add this to dependencies :</p><pre>&quot;dependencies&quot;: {</pre><pre>   ...</pre><pre>   &quot;boilerplate&quot;: &quot;file:../boilerplate&quot;,</pre><pre>   ...</pre><pre>},</pre><p>for the next step, we have to add the boilerplate to playground project node_modules , so run npm install to do so.</p><p>the last thing is to add our Button.js component to playground project and see what happens, in the App.js , let’s use Button :</p><pre>import React, { Component } from &#39;react&#39;;<br>...</pre><pre>import Button from &#39;boilerplate&#39;;</pre><pre>...</pre><pre>class App extends Component {</pre><pre>   render() {</pre><pre>      return (</pre><pre>         &lt;div className=&quot;App&quot;&gt;</pre><pre>            &lt;Button text=&quot;World&quot; /&gt;</pre><pre>         &lt;/div&gt;</pre><pre>      );</pre><pre>   }</pre><pre>}<br></pre><pre>export default App;</pre><p>now we can see our button component shows up !</p><p><strong>Note</strong> : every time you make change to your lib, you should run npm run transpile</p><h3>Step 4 : use gulp to enhance our project (optional)</h3><p>there is another problem which is what if we want to make multiple components and use them to our playground project?</p><p>so, there is a two solutions :</p><p>1 -make all components in one file and then export and transpile them</p><p>2 -make every component a separate file and concatenate them to one file</p><p>the first one is not a good solution for us because if we have lots of components, that will be so hard for reading and editing the code. so the second one is far better. in order to concatenate our files to a single file, we need to use an automation tool that helps us to do all the process automatically. now, let’s install our required packages in the boilerplate project:</p><pre>&gt; npm i --save-dev gulp gulp-concat gulp-babel</pre><p><strong>Hint </strong>: before using gulp, make sure you have been installed gulp-cli globally on your machine.</p><p>for the next step, create gulpfile.js , so we can put our configuration in it.</p><p>then in the gulpfile.js , put these codes .</p><pre>const gulp = require(&#39;gulp&#39;);</pre><pre>const babel = require(&#39;gulp-babel&#39;);</pre><pre>const concat = require(&#39;gulp-concat&#39;);</pre><pre>gulp.task(&#39;default&#39;, () =&gt;</pre><pre>   gulp.src(&#39;src/*.pl.js&#39;)</pre><pre>   .pipe(babel({</pre><pre>      presets: [</pre><pre>         &quot;es2015&quot;,</pre><pre>         &quot;react&quot;</pre><pre>      ]</pre><pre>   }))</pre><pre>   .pipe(concat(&#39;all.js&#39;))</pre><pre>   .pipe(gulp.dest(&#39;lib&#39;))</pre><pre>);</pre><p>this default task simply gets all the files from src folder and .pl.js extension, then convert them to ES5 using gulp-babel and finally concatenate them into all.js file and put it into lib folder.</p><p><strong>Hint 1</strong>: there is nothing special about the extension that i use, you can change it to what ever you want.</p><p><strong>Hint 2 : </strong>after that, you should create every component with the extension that you created before and change the previous component extension into it. in our case, it’s<strong> </strong>.pl.js .</p><p>now, let’s create a new component and name it Header.pl.js :</p><pre>import React , {Component} from &#39;react&#39;;</pre><pre>export class Header extends Component{</pre><pre>   constructor(props) {</pre><pre>      super(props);</pre><pre>   }</pre><pre>   render() {</pre><pre>      return(</pre><pre>         &lt;h1&gt;this is {this.props.text}!&lt;/h1&gt;</pre><pre>      )</pre><pre>   }</pre><pre>}</pre><p><strong>Hint </strong>: you should use export the component instead of export default, because all the components will be stick together and we mustn&#39;t have multiple export default in a single file.</p><p>after that, we should run the gulp command :</p><pre>&gt; gulp default</pre><p>so our components are ready to use via all.js .</p><p>the last thing we want to do, is to change our main project file to all.js , so open up the package.json file and change this into it.</p><p>so we can use multiple components as a single file without any filthy</p><p>hope you enjoy this article and it works for you</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dc36c98a6cde" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>