package-publishing

Configure npm package.json exports, dual ESM/CJS builds, and publishing workflows.

14|5|Updated Jan 29, 2026
One-click install
npx skills add https://github.com/oakoss/agent-skills --skill package-publishing
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: package-publishing
Source: https://github.com/oakoss/agent-skills/tree/main/skills/package-publishing
Command: npx skills add https://github.com/oakoss/agent-skills --skill package-publishing

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill streamlines the process of configuring and publishing modern npm packages, ensuring correct package.json settings, dual ESM/CJS builds, and secure publishing workflows.

Core Features & Use Cases

  • package.json Configuration: Master the exports field, main, module, types, and files for robust package structure.
  • Dual ESM/CJS Builds: Configure your package to work seamlessly in both Node.js and browser environments.
  • Secure Publishing: Implement prepublishOnly checks and understand provenance for supply-chain security.
  • Use Case: You've built a new TypeScript library and need to publish it to npm. This Skill guides you through setting up your package.json to correctly define entry points, include type declarations, and ensure only necessary files are published.

Quick Start

Configure your package.json for dual ESM/CJS builds and set up a prepublishOnly script.

Frequently Asked Questions about package-publishing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I configure package.json exports for dual ESM and CJS builds?

To configure package.json exports for dual ESM and CJS builds, use the `exports` field to define separate entry points for `import` and `require`. This ensures your JavaScript package resolves correctly across different Node.js and browser environments.

What is the best way to publish a TypeScript npm package with type declarations?

The best way to publish a TypeScript npm package is to set the `types` field in `package.json` to point to your generated `.d.ts` files. This ensures consumers of your package automatically receive accurate TypeScript type declarations.

How do npm package lifecycle scripts like prepublishOnly secure the publishing workflow?

npm package lifecycle scripts like `prepublishOnly` secure the publishing workflow by running automated checks right before the package is uploaded. This prevents accidentally publishing broken builds or incorrect files to the npm registry.

Why should I use the package.json files field when publishing npm packages?

You should use the `files` field in package.json to explicitly whitelist the files included in your published npm package. This prevents unnecessary source files from bloating the package and ensures consumers only download the required ESM and CJS builds.

What is npm package provenance and when do I need it?

npm package provenance is a supply-chain security feature that links a published package to its exact build source code. You need it when publishing npm packages to provide downstream consumers with verifiable guarantees about the code origin.

How do I set up package.json main, module, and types fields for a JavaScript library?

To set up package.json for a JavaScript library, configure `main` for CommonJS entry, `module` for ESM entry, and `types` for TypeScript declarations. This combination ensures maximum compatibility across varied build tools and environments.