package.json-minifier
v0.0.6
Published
package.json minifier
Readme
package.json minifier
Creates a consumer-facing package.json after build files have been copied to dist.
npx package.json-minifier
npx package.json-minifier --output-path build/package.json
npx package.json-minifier --prettyIt removes source-only fields and non-install scripts, warns about unknown top-level fields, and rejects files. Only preinstall, install, and postinstall scripts remain.
Use the API when the output needs project-specific changes:
const fs = require('node:fs');
const { minifyPackageJson } = require('package.json-minifier');
const input = JSON.parse(fs.readFileSync('package.json', 'utf8'));
const output = minifyPackageJson(input, {
stripPackagePathPrefix: './dist/',
includeFields: ['react-native']
});
fs.writeFileSync('dist/package.json', JSON.stringify(output));stripPackagePathPrefixremoves one exact leading prefix from entry-point fields:./dist/index.jsbecomes./index.js. Non-matching paths are unchanged.includeFieldscan retain non-standard or normally omitted fields, including their nested values.- Unknown fields use
warnUnknownField, which warns and returnstrue, by default. A customonUnknownFieldmust returntrueto handle the field; a falsy return throws an error. - Less commonly needed helpers and policy constants are documented by the bundled TypeScript declarations.
