call(back)

How Do You Build an npm Package?

How do you build an npm package?

Answer out loud in under a minute: a definition, one concrete example, and one pitfall or trade-off.

Hints

Hint 1

Walk from package.json to npm publish, naming the fields that decide what consumers get.

Solution

Show the approach

Answer

package.json with name, version, exports, types and a files allow-list. Build to ESM, plus CommonJS if consumers need it, with type declarations. Frameworks go in peerDependencies. Check the contents with npm pack --dry-run, then npm publish, and bump by semver.

Asked at