Registry / devops / esbuild-plugin-package-json

esbuild-plugin-package-json

JSON →
library2.0.0jsnpmunverified

An esbuild plugin that prepares package.json for publishing by removing unnecessary fields (e.g., scripts, devDependencies) and copying it to the output folder. Version 2.0.0 is the latest stable release, with active development. It is designed for developers who want to publish clean packages directly from esbuild builds. Differentiators include zero configuration defaults and support for custom output paths.

npm install esbuild-plugin-package-json
INSTALL
IMPORT
SIG · ESBUILD-PLUGIN-PAC
E
esbuild-plugin-package-json
devopsjavascriptv2.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

packageJsonPlugin
import { packageJsonPlugin } from 'esbuild-plugin-package-json'
import packageJsonPlugin from 'esbuild-plugin-package-json'
This package uses named export; default import will not work.
packageJsonPlugin
const { packageJsonPlugin } = require('esbuild-plugin-package-json')
const packageJsonPlugin = require('esbuild-plugin-package-json')
CommonJS users must destructure the named export.
type PackageJsonPluginOptions
import type { PackageJsonPluginOptions } from 'esbuild-plugin-package-json'
TypeScript users can import the options type for plugin configuration.

Demonstrates basic usage of the plugin with esbuild, configuring the lifecycle and output directory.

import { packageJsonPlugin } from 'esbuild-plugin-package-json'; import esbuild from 'esbuild'; await esbuild.build({ entryPoints: ['src/index.ts'], outdir: 'dist', bundle: true, plugins: [ packageJsonPlugin({ lifecycle: 'onEnd', overrideOut: 'dist', // overridePackageJson: './src', // optional custom path }), ], });
Debug
Known issues
breakingVersion 2.0.0 changed the export from default to named export. Old code using `import packageJsonPlugin from 'esbuild-plugin-package-json'` will break.
fix
Use `import { packageJsonPlugin } from 'esbuild-plugin-package-json'` instead.
affects: >=2.0.0
gotchaIf `overrideOut` is not set, the plugin copies package.json to esbuild's default output directory, which may not be desired if multiple output paths are configured.
fix
Explicitly set `overrideOut` to your intended output directory.
affects: >=0.0.1
gotchaThe plugin only removes specific fields (scripts, devDependencies) by default. Other fields like 'private' are not automatically removed.
fix
Manually specify additional fields to remove in your own build script.
affects: >=0.0.1
gotchaUsing `lifecycle: 'onStart'` may cause the package.json to be copied before the build produces the final output, potentially leading to outdated files.
fix
Use the default `onEnd` lifecycle to ensure the build is complete.
affects: >=0.0.1
Errors
Common errors & fixes
Error: Cannot find module 'esbuild-plugin-package-json'
The package is not installed or is missing from node_modules.
fix
Run `npm install -D esbuild-plugin-package-json` to install it as a dev dependency.
TypeError: packageJsonPlugin is not a function
Using a default import when the package exports a named function.
fix
Use `import { packageJsonPlugin } from 'esbuild-plugin-package-json'` instead of `import packageJsonPlugin from ...`.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies
esbuildrequiredesbuild is required as a peer dependency to use this plugin.
Agent activity
2 hits · last 30 days
node
2
Resources
esbuild-plugin-package-json — npm install esbuild-plugin-package-json · libregistry