<?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: Phani</title>
    <description>The latest articles on DEV Community by Phani (@itsmephani).</description>
    <link>https://dev.to/itsmephani</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%2F152222%2F71d2b342-9085-4a4b-ad43-1f6acb0642ae.jpeg</url>
      <title>DEV Community: Phani</title>
      <link>https://dev.to/itsmephani</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/itsmephani"/>
    <language>en</language>
    <item>
      <title>Publishing react components as NPM package.</title>
      <dc:creator>Phani</dc:creator>
      <pubDate>Thu, 11 Jun 2020 16:46:33 +0000</pubDate>
      <link>https://dev.to/itsmephani/react-ts-scss-gulp-npm-31h</link>
      <guid>https://dev.to/itsmephani/react-ts-scss-gulp-npm-31h</guid>
      <description>&lt;h2&gt; React + TS + SCSS + Gulp = NPM. &lt;/h2&gt;

&lt;p&gt;We all have a shared components folder in our project. Always 
   wondered how to use it across projects.
   So, after trying multiple methods and failing, following is the simplest
way worked out for me to publish React components as
NPM package.&lt;/p&gt;

&lt;h2&gt;Create react app with create-react-app command from terminal&lt;/h2&gt;
&lt;code&gt;npx create-react-app react-automazers --template typescript&lt;/code&gt;

&lt;h2&gt;Edit package.json to include&lt;/h2&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h2&gt;Add tsconfig.json to your project root&lt;/h2&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h2&gt;Add gulpfile.js to your project root&lt;/h2&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h2&gt;Signup with &lt;a href="https://www.npmjs.com/"&gt;https://www.npmjs.com/&lt;/a&gt; if you don’t have account already.&lt;/h2&gt;

&lt;h2&gt;Final steps for publishing NPM package&lt;/h2&gt;
&lt;p&gt;NPM will run prepare task given in package.json before publishing
the module. So let us put together all the steps we have done in prepare script.&lt;/p&gt;

&lt;code&gt;"prepare": "gulp",&lt;/code&gt;

&lt;p&gt;Prepare task will just run the gulp command.
Here are the steps that will happen with this gulp command
&lt;br&gt;Gulp will check for the default task in gulpfile.js
&lt;br&gt;We are running series of tasks in the default task
&lt;br&gt;. clean — Will remove existing output directory — core in our case.
&lt;br&gt;. compile — will compile all typescript to javascript.
&lt;br&gt;. sass — will compile all scss to css files
&lt;br&gt;. copy-css — will copy all the css files generated to output directory
&lt;/p&gt;




&lt;h2&gt;Let’s Publish&lt;/h2&gt;

&lt;p&gt;Run “npm login” from terminal to login into your npm.&lt;/p&gt;

&lt;p&gt;Finally run “npm publish” to publish to the world.&lt;/p&gt;




&lt;h2&gt;Congrats you have successfully published you npm package 🥳 🎉&lt;/h2&gt;




&lt;h2&gt;Note: As we are not updating typescript files manually to use .css files. Include .css files in your tsx files instead of .scss extension.&lt;/h2&gt;

&lt;p&gt;
gulp sass will automatically generate .css file from .scss file.
&lt;br&gt;run gulp sass:watch for automatically generating css from scss on update of file while development.
Complete code can be found @ &lt;a href="https://github.com/automazers/react-automazers"&gt;https://github.com/automazers/react-automazers&lt;/a&gt; &lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vJ70wriM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/github-logo-ba8488d21cd8ee1fee097b8410db9deaa41d0ca30b004c0c63de0a479114156f.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/automazers"&gt;
        automazers
      &lt;/a&gt; / &lt;a href="https://github.com/automazers/react-automazers"&gt;
        react-automazers
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;p&gt;React Automazers&lt;/p&gt;
&lt;p&gt;Reusable components&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;FormAutomazer&lt;/li&gt;
&lt;li&gt;DataTable&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;



&lt;/div&gt;
&lt;br&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/automazers/react-automazers"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;br&gt;


</description>
      <category>typescript</category>
      <category>react</category>
      <category>gulp</category>
      <category>npm</category>
    </item>
  </channel>
</rss>
