Kick off your book project in 3 hours! Live workshop on Zoom. You’ll leave with a real book project, progress on your first chapter, and a clear plan to keep going. Saturday, May 16, 2026. Learn more…

Leanpub Header

Skip to main content

Creating NPM Package with Vanilla JavaScript

Build, Test & Publish Vanilla JavaScript Libraries Like a Pro

This book is 100% completeLast updated on 2026-04-30

Want to Publish Your Own NPM Package Like a Pro?

Learn how to build, test, and share your vanilla JavaScript code with the world—step by step.

CodeSweetly’s “Creating NPM Package” breaks down the library publishing process into simple, actionable steps—from project setup to automated publishing and version management.

  • Build with confidence
  • Test like a pro
  • Publish with ease
  • Perfect for devs who want to level up their open-source game.

Ready to ship like a pro? Get the book now. Printed copies are also available on Amazon.

Minimum price

$10.99

$10.99

You pay

Author earns

$
PDF
EPUB
WEB
107
Pages
About

About

About the Book

Updated for 2026

Do you want to publish high-quality JavaScript packages to NPM without struggling with complicated setups or unreliable release scripts?

Creating NPM Package is a hands-on, step-by-step guide that walks you through every stage of building a modern JavaScript library, from setting up your project to automating production releases.

This new edition includes the latest best practices, such as using semantic-release for automated versioning and release notes, setting up secure NPM Trusted Publishing, and a new chapter on making your JavaScript codebase more modular and scalable.

If you’ve ever asked yourself questions like these:

  • How should I structure my JavaScript library?
  • How do I automate versioning and changelogs without manual work?
  • How do I securely publish using modern CI workflows?
  • How do I scale my library beyond a single file?

This book gives you clear, practical answers to all of these questions.

What You’ll Learn Inside

  • Configure a clean, scalable JavaScript project
  • Define correct entry points
  • Modularize your JavaScript codebase for maintainability
  • Test your package before and after publishing
  • Automate version management and release notes using semantic-release
  • Implement NPM Trusted Publishing for secure, tokenless releases
  • Create professional README and LICENSE files
  • Publish and validate your package in both local and production environments

This book is more than just a tutorial. It gives you a repeatable system you can use for different projects.

Why Choose This Book

  • Clear, simplified explanations without unnecessary theory
  • Real-world workflows used by professional library authors
  • Automation-first approach to eliminate manual release headaches
  • It focuses on the steps for building and publishing libraries, not just on JavaScript programming itself.

Who This Book Is For

  • JavaScript developers ready to publish reusable libraries
  • Open-source contributors aiming to adopt professional workflows
  • Teams requiring consistent and maintainable package configurations

Whether you’re publishing your first open-source project or improving a professional release process, this book will help you deliver clean, automated JavaScript libraries without extra complexity.

Start building smarter today. Start publishing like a pro. You can buy a printed copy at Amazon.

Bundles

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. Setting Up Your System
  2. 2. Creating a Project Directory
  3. 3. Creating a package.json File
  4. 4. Initializing a Git Repository
  5. 5. Specifying the Files Git Should Ignore
  6. 6. Staging and Committing Your Project’s Changes to Git
  7. 7. Configuring a GitHub Remote Repository
  8. 8. Uploading Your Local Git Directory to the Remote Repo

Testing JavaScript Code

  1. 1. Installing the Testing Tool
  2. 2. Specifying Jest as Your Project’s Test Runner Tool
  3. 3. Configuring Jest to Support ECMAScript Modules
  4. 4. Configuring Babel to Use the @babel/preset-env Preset
  5. 5. Configuring Jest’s Testing Environment
  6. 6. Creating Your Code Files
  7. 7. Writing Your Test Case
  8. 8. Developing Your JavaScript Code
  9. 9. Running 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 a Library’s Elements

  1. 1. Create the Stylesheet
  2. 2. Apply CSS Styles to Your Elements
  3. 3. Run the Test

Defining Package’s Entry Point

Local Testing of Unpublished Package

  1. Link-Install Your Package Globally in Your System
  2. Creating a Directory for the Demo Website
  3. Creating a package.json File
  4. Initializing a Git Repository
  5. Specifying the Files Git Should Ignore
  6. Installing Your Package from Your System’s Global Folder to the Test App
  7. Using the Link-Installed Package in the Test App
  8. Creating the Demo Website’s Homepage
  9. Installing the Parcel Build Tool
  10. Specifying Parcel as Your Website’s Development Server
  11. Unlinking Your Package from the Test App
  12. Unlinking Your Package from the Global Folder

Creating README

Creating LICENSE

Publishing Package to NPM

  1. 1. Search Engine Optimization (SEO)
  2. 2. Confirm That Your Package Have Passing Tests
  3. 3. Stage and Commit Your Project’s Changes to Git
  4. 4. Specify the Files You Want to Publish to NPM
  5. 5. Confirm the Files NPM Will Publish
  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. Installing the Package
  2. 2. Importing the Package
  3. 3. Running Your Local Server

Production Testing of the Published Package

  1. 1. Staging and Committing Your Changes
  2. 2. Setting Up a GitHub Remote Repository for Your Demo Test App
  3. 3. Uploading Your Local Git Directory to the Remote Repo
  4. 4. Signing In or Creating an Account on the Vercel Website
  5. 5. Deploying Your Project to Vercel’s Server
  6. 6. Testing the Package on the 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. 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

Modularizing JavaScript Codebase

  1. 1. Identify Independent Elements
  2. 2. Split the Elements You Want to Extract into Their Separate Modules
  3. 3. Import the Extracted Elements into the tweetButton.js File
  4. 4. Configure Jest to Strip the Extension from Import Statements
  5. 5. List the New Modules as Files You Want to Publish on NPM
  6. 6. Release the Latest Version of the Project

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...

 

Other books by this author

Other books by this author

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 $15 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