Skip to main content

@ovineko/clean-pkg-json

Zero-config tool to clean package.json before publishing and restore it after.

Removes dev-only fields (devDependencies, scripts, eslintConfig, etc.) keeping only what's needed in the published package.

Install

pnpm add -D @ovineko/clean-pkg-json

Usage

clean-pkg-json clean # backup + clean
clean-pkg-json restore # restore from backup

With npm lifecycle hooks

{
"scripts": {
"prepack": "clean-pkg-json clean",
"postpack": "clean-pkg-json restore"
}
}

How it works

clean creates package.json.backup, then removes all fields not in the whitelist.

restore replaces package.json from backup and deletes the backup file.

Whitelisted fields

CategoryFields
Identityname, version, description, keywords, author, license
Entry pointsmain, module, types, exports, bin
Publishingfiles, type, engines, publishConfig, repository, bugs, homepage, sideEffects, funding
Dependenciesdependencies, peerDependencies, peerDependenciesMeta, optionalDependencies, bundledDependencies, bundleDependencies

Whitelisted scripts

Only npm lifecycle hooks survive: preinstall, install, postinstall.