https://github.com/kirandash/clean-package-dot-json
Clean package.json before publishing your package by removing unnecessary properties.
https://github.com/kirandash/clean-package-dot-json
cleanup npm open-source prepack prepublish
Last synced: 4 months ago
JSON representation
Clean package.json before publishing your package by removing unnecessary properties.
- Host: GitHub
- URL: https://github.com/kirandash/clean-package-dot-json
- Owner: kirandash
- License: mit
- Created: 2023-06-09T17:52:03.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-06-11T10:30:15.000Z (almost 3 years ago)
- Last Synced: 2025-10-04T09:54:10.894Z (8 months ago)
- Topics: cleanup, npm, open-source, prepack, prepublish
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/clean-package-dot-json
- Size: 79.1 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
clean-package-dot-json
Clean `package.json` in `prepack` hook before publishing your package by removing unnecessary properties.
Feel free to reach me on other social platforms! 😊
YouTube || Discord || Instagram || Twitter || TikTok || Blog || Facebook
🙏 Support
Please ⭐️ star this project and share it with others to show your support. [Follow me](https://github.com/kirandash) ❤️ for updates on future projects and tutorials!
---
## Purpose?
`package.json` most of the time gets filled up with development related information ex: `devDependencies` and configuration like [`eslintConfig`](https://eslint.org/docs/latest/user-guide/configuring/), [`prettier`](https://prettier.io/docs/en/configuration.html), [`lint-staged`](https://github.com/okonet/lint-staged), [`simple-git-hooks`](https://github.com/toplenboren/simple-git-hooks), etc.
If you are building npm package or micropackages where every byte matters then you can use `clean-package-dot-json` in a prepack hook to remove unnecessary properties from `package.json`.
## Install
```
npm install --save-dev clean-package-dot-json
```
## Usage
Add `clean-package-dot-json` to the [`prepack` hook](https://docs.npmjs.com/cli/v8/using-npm/scripts#:~:text=on%20npm%20publish.-,prepack,-Runs%20BEFORE%20a), which runs before `npm publish` and `npm pack`.
```json5
// package.json
{
name: 'my-package',
// ...
scripts: {
// ...
prepack: 'node ./node_modules/.bin/clean-package-dot-json',
},
}
```
### Flags
| Flag | Description |
| ------------------------------ | ------------------------------------------------------------------------------------------ |
| `-i, --ignore ` | Property names to ignore during cleanup. Accepts multiple flags or a comma-delimited list. |
| `-v, --verbose` | Verbose logs. |
| `-d, --dry` | Dry run mode. Instead of writing to disk, it will log it. |
### Default ignored properties
By default, these properties are ignored in `package.json`:
#### [npm](https://docs.npmjs.com/cli/v8/configuring-npm/package-json)
- `name`
- `version`
- `private`
- `publishConfig`
- `scripts.preinstall`
- `scripts.install`
- `scripts.postinstall`
- `scripts.dependencies`
- `files`
- `bin`
- `browser`
- `main`
- `man`
- `dependencies`
- `peerDependencies`
- `peerDependenciesMeta`
- `bundledDependencies`
- `optionalDependencies`
- `engines`
- `os`
- `cpu`
- `description`
- `keywords`
- `author`
- `contributors`
- `license`
- `homepage`
- `repository`
- `bugs`
- `funding`
#### CDNs
- [`jsdelivr`](https://www.jsdelivr.com/features#publishing-packages)
- [`unpkg`](https://unpkg.com/)
#### [Node.js](https://nodejs.org/api/packages.html#nodejs-packagejson-field-definitions)
- `type`
- `exports`
- `imports`
#### [VSCode Extension Manifest](https://code.visualstudio.com/api/references/extension-manifest)
- `sponsor`
- `publisher`
- `displayName`
- `categories`
- `galleryBanner`
- `preview`
- `contributes`
- `activationEvents`
- `badges`
- `markdown`
- `qna`
- `sponsor`
- `extensionPack`
- `extensionDependencies`
- `extensionKind`
- `icon`
#### [Angular Package Format](https://angular.io/guide/angular-package-format#legacy-resolution-keys)
- `fesm2020`
- `fesm2015`
- `esm2020`
- `es2020`
#### [TypeScript](https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html)
- `types`
- `typings`
- `typesVersions`
#### Bundlers (Webpack, Rollup, esbuild)
- [`module`](https://stackoverflow.com/questions/42708484/what-is-the-module-package-json-field-for)
- [`sideEffects`](https://webpack.js.org/guides/tree-shaking/)