├── .gitignore ├── .prettierrc.json ├── .github └── workflows │ └── check-formatting.yml ├── package.json ├── CONTRIBUTING.md ├── README-zh_CN.md ├── README.md └── LICENSE.txt /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /.github/workflows/check-formatting.yml: -------------------------------------------------------------------------------- 1 | on: pull_request 2 | 3 | jobs: 4 | check-formatting: 5 | runs-on: ubuntu-latest 6 | steps: 7 | - uses: actions/checkout@v3 8 | - uses: actions/setup-node@v3 9 | with: 10 | node-version: 16 11 | cache: "npm" 12 | - run: npm ci 13 | - run: npm run format-check 14 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "modern-guide-to-packaging-js-library", 3 | "version": "0.0.1", 4 | "description": "Modern Guide to Packaging Your JavaScript Library", 5 | "scripts": { 6 | "format": "prettier --write .", 7 | "format-check": "prettier --check ." 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/frehner/modern-guide-to-packaging-js-library.git" 12 | }, 13 | "author": "Anthony Frehner", 14 | "license": "GPL-3.0-or-later", 15 | "homepage": "https://github.com/frehner/modern-guide-to-packaging-js-library#readme", 16 | "devDependencies": { 17 | "prettier": "^2.7.1" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Thank you for your interest in contributing to this guide! Here are some guidelines: 4 | 5 | ## Correcting spelling mistakes or other editorial changes 6 | 7 | For corrections to ~~speeling~~ spelling mistakes or other editorial changes that don't change the underlying suggestion, feel free to create a pull request to this repo without discussion. There is a check on all PRs that ensures that documents have been formatted correctly; to run this locally, you can do 8 | 9 | ```bash 10 | # install dependencies 11 | $ npm install 12 | 13 | # format documents 14 | $ npm run format 15 | ``` 16 | 17 | ## Requesting changes or updates to suggestions 18 | 19 | If you would like to request a change or update to a suggestion, please either: 20 | 21 | 1. Start a discussion or open an issue and bring at least one reference, or 22 | 2. Open a PR with the change and with references cited 23 | 24 | Note that in both cases, at least one reference is requested. For the sake of this guide, a reference could be (but is not limited to): 25 | 26 | - A link to official bundler documentation (perhaps informing why a setting is recommended) 27 | - A GitHub comment by a person working on a JS runtime (maybe saying why they need something a specific way) 28 | -------------------------------------------------------------------------------- /README-zh_CN.md: -------------------------------------------------------------------------------- 1 | # 打包 JavaScript 库的现代化指南 2 | 3 | [English](./README.md) | 简体中文 4 | 5 | ## 简介 6 | 7 | 本指南旨在提供一些大多数库都应该遵循的一目了然的建议。以及一些额外的信息,用来帮助你了解这些建议被提出的原因,或帮助你判断是否不需要遵循某些建议。这个指南仅适用于 **库(libraries)**,不适用于应用(app)。 8 | 9 | 要强调的是,这只是一些**建议**,并不是所有库都必须要遵循的。每个库都是独特的,它们可能有充足的理由不采用本文中的任何建议。 10 | 11 | 最后,这个指南不针对某一个特定的打包工具 —— 已经有许多指南来说明如何在配置特定的打包工具。相反我们聚焦于每个库和打包工具(或不用打包工具)都适用的事项。 12 | 13 | --- 14 | 15 | ## 输出 `esm`、`cjs` 和 `umd` 格式 16 | 17 |
18 | 支持全部的生态 19 | 20 | `esm` 是“EcmaScript module”的缩写。 21 | 22 | `cjs` 是“CommonJS module”的缩写。 23 | 24 | `umd` 是“Universal Module Definition”的缩写,它可以在 `