Leanpub Header

Skip to main content

Creating NPM Package with React TypeScript

React TypeScript Guide to Create, Test, and Publish NPM Libraries

Build and Publish Your Own React NPM Package!

Want to share your React components with the world? CodeSweetly’s Creating NPM Package with React TypeScript book walks you through the entire process—from setup to publishing—so you can confidently create and distribute your own reusable React packages.

✔️ Set up a React-based NPM package

✔️ Write clean, modular, and reusable components

✔️ Configure compiling tools for package optimization

✔️ Publish your package and manage updates like a pro

No fluff—just clear, step-by-step guidance. Start building and sharing your React creations today! Printed copies of this book are also available on Amazon.

Minimum price

$15.00

$15.00

You pay

$15.00

Author earns

$12.00
$

...Or Buy With Credits!

You can get credits with a paid monthly or annual Reader Membership, or you can buy them here.
PDF
EPUB
WEB
115
Pages
About

About

About the Book

Updated for 2026


Learn how to build, test, and publish modern NPM packages with React and TypeScript.


Creating NPM Package is a practical, step-by-step guide to designing, developing, and automating the release of professional NPM libraries. Whether you are new to open-source or an experienced developer seeking to improve your team’s tools, this book will help you publish with confidence.


Inside, you’ll learn how to:


  • Set up and organize a scalable NPM package
  • Write React and TypeScript components that are easy to maintain
  • Create reliable testing workflows
  • Automate versioning and releases with semantic-release in a CI workflow
  • Set up NPM Trusted Publishing for secure, token-free releases
  • Use best practices for modern package development


You don’t need any previous publishing experience.


This beginner-friendly guide walks you through creating, testing, and publishing NPM packages. Concepts are demonstrated through a hands-on project, allowing you to build as you learn.


By the end of the book, you will have a complete, automated NPM publishing workflow aligned with current best practices.


This book is for you if you want to:


✔ Publish your own React component libraries

✔ Improve your CI/CD release process

✔ Learn semantic-release the practical way

✔ Use modern React and TypeScript patterns


Get your copy today and start building and sharing React components with developers around the world.

Bundle

Bundles that include this book

Author

About the Author

CodeSweetly

Learning to be a software developer can sometimes feel overwhelming or tedious, but CodeSweetly is here to help.

Unlike other resources, CodeSweetly helps you become a confident developer by simplifying technical concepts and presenting them in a way that supports your unique learning style, so you can focus on coding sweetly.

We break down programming topics with clear tutorials, examples, cheat sheets, and illustrations made to make complex ideas easier to grasp. Our approach centers on clarity and simplicity for your success.

Whether you’re new to coding or a pro, CodeSweetly makes learning to code easier and more enjoyable.

Contents

Table of Contents

Introduction

  1. Welcome to NPM Package!
  2. How This Book Can Help You
  3. The Roadmap
  4. Dependencies
  5. Prerequisite
  6. Questions and Comments
  7. Let’s Get It Started!

Project Configuration

  1. 1. Set Up Your System
  2. 2. Create a Project Directory
  3. 3. Create a package.json File
  4. 4. Initialize a Git Repository
  5. 5. Specify the Files Git Should Ignore
  6. 6. Stage and Commit Your Project’s Changes to Git
  7. 7. Configure a GitHub Remote Repository
  8. 8. Push Your Local Git Directory to the Remote Repo
  9. 9. Install React and TypeScript
  10. 10. Configure the TypeScript Compiler

Testing React Component

  1. 1. Install the Testing Tools
  2. 2. Specify Jest as Your Project’s Test Runner Tool
  3. 3. Configure Jest to Test TypeScript Code
  4. 4. Configure Jest to Compile TypeScript Files
  5. 5. Configure Jest’s Testing Environment
  6. 6. Create Your Code Files
  7. 7. Write Your Test Case
  8. 8. Develop Your React Component
  9. 9. Run the Test

Commit Message Configuration

  1. Conventional Commits Message Syntax
  2. Enforcing the Conventional Commits Format
  3. Setting Up Husky
  4. Creating a Hook to Auto-Lint Commit Messages

Setting Up Commitlint GitHub Action

  1. 1. Create a Commitlint GitHub Action Workflow File
  2. 2. Define the Commitlint GitHub Action Workflow
  3. 3. Test the Commitlint GitHub Action Workflow

Styling React Components

  1. 1. Create the Stylesheet
  2. 2. Apply CSS Styles to Your Component
  3. 3. Load CSS Files into Jest’s JSDOM
  4. 4. Run the Test

Compiling React to JavaScript

  1. How to Compile Both ECMAScript and CommonJS Modules

Distinguishing Source and Distribution Code

Specify Items to Compile

Defining Package’s Entry Point

Specifying Package’s Declaration File

Local Testing of Unpublished Package

  1. 1. Link-Install Your Package Globally in Your System
  2. 2. Create a NextJS Demo Website for Testing Your Package
  3. 3. Install Your Package from Your System’s Global Folder to the Test-App
  4. 4. Configure Turbopack to Resolve Symlinks
  5. 5. Use the Link-Installed Package in Your Test-App
  6. 6. Unlink Your Package from the Test-App
  7. 7. Unlink Your Package from the Global Folder

Creating README

Creating LICENSE

Publishing Package to NPM

  1. 1. Search Engine Optimization (SEO)
  2. 2. Specify the Files You Want to Publish to NPM
  3. 3. Confirm the Files NPM Will Publish
  4. 4. Confirm That Your Package Have Passing Tests
  5. 5. Compile Any Pending Code
  6. 6. Stage and Commit Any Recent Changes
  7. 7. Push Your Local Git Directory to the Remote Repo
  8. 8. Sign In or Sign Up on the NPM Website
  9. 9. Log In to NPM via the Terminal
  10. 10. Confirm If Your Package’s Name Is Available
  11. 11. Publish Your Package!

Local Testing of the Published Package

  1. 1. Install the Package
  2. 2. Import the Package
  3. 3. Run Your Local Server

Production Testing of the Published Package

  1. 1. Stage and Commit Your Changes
  2. 2. Set up a GitHub Remote Repository for Your Next.js Test App
  3. 3. Push Your Local Git Directory to the Remote Repo
  4. 4. Sign In or Create an Account on the Vercel Website
  5. 5. Deploy Your Project to Vercel
  6. 6. Test the Package on Your Live Demo Website

Updating Package’s Versions

  1. Example 1: Updating to a Patch Version
  2. Example 2: Updating to a Minor Version
  3. Example 3: Updating to a Major Version

Automating Version Management

  1. 1. Create a Release GitHub Action Workflow File
  2. 2. Define the Release GitHub Action Workflow
  3. 3. How to Overwrite semantic-release’s Default Configurations
  4. 4. Remove the dist Folder Before Building in the Development Environment
  5. 5. Notify Developers That the Package Uses Automated Version Management

NPM Trusted Publishing Configuration

  1. Add a New Feature
  2. Update an Existing Feature

Automating GitHub Releases

  1. Add the Preset Library to Your Release Workflow
  2. Configure semantic-release to Automatically Publish the Package’s Release Notes

Epilogue

  1. What’s Next?
  2. One Last Favor

Get the free Community Edition

You can get the free Community Edition in PDF or EPUB just by sharing your name and email address with the author, or you can just click this link to read a shorter sample online...

 

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $14 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub