<?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 Andrew Palchykovsky on Medium]]></title>
        <description><![CDATA[Stories by Andrew Palchykovsky on Medium]]></description>
        <link>https://medium.com/@Andrew_Palchykovsky?source=rss-4fafb24111cf------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*2s9CYULgzUqaK4tAiyea7A@2x.jpeg</url>
            <title>Stories by Andrew Palchykovsky on Medium</title>
            <link>https://medium.com/@Andrew_Palchykovsky?source=rss-4fafb24111cf------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 12:19:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@Andrew_Palchykovsky/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 React components library using Stencil.js]]></title>
            <link>https://medium.com/@Andrew_Palchykovsky/how-to-create-react-components-library-using-stencil-js-be42637bd8b?source=rss-4fafb24111cf------2</link>
            <guid isPermaLink="false">https://medium.com/p/be42637bd8b</guid>
            <category><![CDATA[stenciljs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-components]]></category>
            <category><![CDATA[react-libraries]]></category>
            <dc:creator><![CDATA[Andrew Palchykovsky]]></dc:creator>
            <pubDate>Wed, 04 May 2022 16:12:21 GMT</pubDate>
            <atom:updated>2022-05-04T16:13:06.020Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*pI-ho_3VQOZXH_CvLof1Ug.jpeg" /></figure><p>In this post, I’m going to describe my experience of creating React library using <a href="https://stenciljs.com/">Stencil.js</a>.</p><h4>Project setup</h4><p>Firstly off, to create a wrapper for your custom elements to be used as first-class React components we need to create a monorepo that will hold 2 folders with your stencil project and react library project:</p><pre>mkdir react-stencil</pre><p>Here is a look how our project structure will look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/237/1*inI4JnPX6ulEC33a6xNzVQ.jpeg" /></figure><h4>Create a React Component Library</h4><p>The first time you want to create the component wrappers, you will need to have a React library package to write to.</p><pre>git clone <a href="https://github.com/ionic-team/stencil-ds-react-template">https://github.com/ionic-team/stencil-ds-react-template</a> core-components-react </pre><pre>cd core-components-react</pre><pre>npm install</pre><h4>Creating a Stencil component library</h4><p>After we need to go inside of the folder and create Stencil project:</p><pre>cd react-stencil</pre><pre>npm init stencil components stencil-library</pre><p><strong>Adding React Output Target</strong></p><p>Install @stencil/react-output-target dependency to your <strong>Stencil component library</strong> package:</p><pre>npm install @stencil/react-output-target</pre><p>Next, in your project’s stencil.config.ts, add the reactOutputTarget imports and configuration to the outputTargets array:</p><pre>import { Config } from &#39;@stencil/core&#39;;<br>import { <em>reactOutputTarget </em>as react } from &#39;@stencil/react-output-target&#39;;<br><br>export const config: Config = {<br>  namespace: &#39;stencil-library&#39;,<br>  outputTargets: [<br>    <em>react</em>({<br>      componentCorePackage: &#39;stencil-library&#39;,<br>      proxiesFile: &#39;../core-components/src/components/stencil-generated/index.ts&#39;,<br>      includeDefineCustomElements: true,<br>    }),<br>    {<br>      type: &#39;dist&#39;,<br>      esmLoaderPath: &#39;../loader&#39;,<br>    },<br>    {<br>      type: &#39;dist-custom-elements&#39;,<br>      generateTypeDeclarations: true,<br>    },<br>  ],<br>};</pre><p>The proxiesFile is the relative path to the file that will be generated with all of the React component wrappers. You will replace the file path to match your project&#39;s structure and respective names. You can generate any file name instead of index.ts.</p><p>Now, we are ready to run the build within Stencil component library to generate components wrappers.</p><pre>npm run build</pre><h4>Link packages</h4><p>Before you can successfully build a local version of your React component library, you will need to link the Stencil package to the Angular package.</p><p>From your Stencil project’s directory, run the following command:</p><pre>npm link</pre><p>From React project’s directory, run :</p><pre>npm link stencil-library</pre><p>where stencil-library is the name of your Stencil component library’s. You can check it in package.json where name should match with project’s folder name.</p><h4>Usage</h4><p>In this guide, we are not going to create an npm package. However, we will create a local build that will emulate the npm package.</p><p>Let’s navigate to core-components-react folder and create a build.</p><pre>npm run build</pre><p><em>If you are facing some issues during this build on Windows machine try to run the code which is above but using git bash.</em></p><p>This will create distfolder inside your core-components-react folder. We will copy this folder to node_modules of new React app but will change name to core-components-react .</p><p>Let&#39;s create react app which will use that:</p><pre>npx create-react-app my-react-app</pre><p>and in App.js we will import component from our library:</p><pre>import &#39;./App.css&#39;;<br>import {MyComponent} from &#39;core-components-react&#39;;<br><br>function <em>App</em>() {<br>  return (<br>    &lt;div className=&quot;App&quot;&gt;<br>      &lt;MyComponent first=&quot;Esta&quot; last=&quot;Chico&quot; /&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default <em>App</em>;</pre><p>To run this project successfully we need to copy stencil-library from node-modules of core-components-react to node-modules of my-react-app .</p><p>After, within our React app run:</p><pre>npm start</pre><p>As a result, we should receive this view:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kVqepq9u2eeh2K-u5fCBqA.png" /></figure><p>I hope this article will help you. See you soon.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be42637bd8b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>