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
- Compile with
tscto generate declarations. - 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.