frehner / modern-guide-to-packaging-js-library

A guide to help ensure your JavaScript library is the most compatible, fast, and efficient library you can make.
GNU General Public License v3.0
1.44k stars 38 forks source link
javascript javascript-library npm

The Modern Guide to Packaging your JavaScript library

English | 简体中文

Context about this guide

This guide is written to provide at-a-glance suggestions that most libraries should follow, while also giving additional information if you want to understand why a suggestion is made or if you feel like you need to deviate from these suggestions. This guide is meant for libraries and not for applications (apps).

To emphasize, this is a list of suggestions and is not meant to be definitive list that all libraries must follow, or to provide flame bait for libraries that do not follow these suggestions. Each library is unique and there are probably good reasons a library may chose to not implement any given suggestion.

Finally, this guide is not meant to be specific to any particular bundler - there already exist many guides on how to set configs in specific bundlers. Instead, we want to focus on things that apply to every library and bundler (or lack of bundler).


Tooling

Use tools to validate important settings - [publint.dev](https://publint.dev/) validates important settings with your `package.json` and suggests improvements if it finds them - [arethetypeswrong](https://arethetypeswrong.github.io) validates that your TypeScript types are output and configured correctly

Output to esm, cjs, and umd formats

Supporting the whole ecosystem `esm` is short for "EcmaScript module." `cjs` is short for "CommonJS module." `umd` is short for "Universal Module Definition," and can be run by a raw ` Githubissues.
  • Githubissues is a development platform for aggregating issues.