A Webpack plugin that generates a minimal package.json containing only the external dependencies actually used by your bundle. Version 2.7.0 is current, with regular updates. It works with Webpack 4 and 5, and is typically paired with webpack-node-externals. Key differentiators: automatic version resolution from node_modules, support for excluding dependencies, forcing a Webpack version in mixed environments (e.g., Nx), and flexibility to add non-code dependencies with explicit version prefixes. Ships TypeScript types.
npm install generate-package-json-webpack-pluginVerified import paths — ran on the pinned version, not inferred.
Minimal Webpack config using the plugin with webpack-node-externals and an excluded dependency.
Update to use options object: new GeneratePackageJsonPlugin(basePackage, { useInstalledVersions: true, ... })Set options.useInstalledVersions: false if you want to use a separate versions package.json file.
new GeneratePackageJsonPlugin(basePackage, { versionsPackageFiles: ['path/to/versions.json'] })Use webpack-node-externals or manually externalize node_modules.
Set forceWebpackVersion: 'webpack4' or 'webpack5' in options.
Use `import GeneratePackageJsonPlugin from 'generate-package-json-webpack-plugin'` or `const GeneratePackageJsonPlugin = require('generate-package-json-webpack-plugin')`.Run `npm install webpack --save-dev`.
Ensure you have externalized node_modules using webpack-node-externals or similar, and that your code imports at least one external module.
Update to plugin version >=2.3.0 or ensure the module's package.json is accessible.