Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. TypeScript Mastery

Lesson 44 of 56 · Typescript

Publishing a TypeScript Library to npm

Duration: 20 minutes

Prepare package.json

{
  "name": "my-lib",
  "version": "1.0.0",
  "main": "dist/index.cjs.js",
  "module": "dist/index.esm.js",
  "types": "dist/index.d.ts",
  "files": ["dist"],
  "scripts": { "build": "tsc && rollup -c" }
}

Build steps

  1. Compile with tsc to generate declarations.
  2. Bundle with Rollup/Webpack for a ready‑to‑publish bundle.

Publishing

npm login
npm publish

Using publishConfig

"publishConfig": { "access": "public" }

Semantic Release (optional)

Automate version bump & changelog with semantic-release.

Info

Never publish source maps unless you want to expose source code.

Previous: Monorepos – Lerna, Yarn Workspaces, and NxNext: Advanced Generics – Variadic Tuple Types