Plug'n'Play package.json webpack plugin
A webpack plugin to generate a package.json file with external modules as dependencies
Inspired by generate-package-json-webpack-pluginInstall
yarn add --dev pnp-package-json-webpack-plugin
Usage
This plugin generates a package.json asset from modules marked in
externals
with pinned
versions using resolutions from the
PnP API. This allows for lightweight,
mostly-stable builds in Yarn workspace environments.
In your webpack configuration:
const PnpPackageJsonPlugin = ; const basePackageValues = name: 'my-nodejs-module' version: '1.0.0' main: './index.js' engines: node: '>= 14.0.0' ; moduleexports = // ... plugins: basePackageValues ;
Please be aware that the file created should not be viewed as a replacement for
a lockfile such as yarn.lock
. The version of each external pinned by the
plugin will be stable, but it offers no control over child dependencies
installed later.
Configuration
basePackageValues
Type: Object|Function
Default:
Specifies an object or function customizing the outputted package.json.
Object
webpack.config.js
moduleexports = plugins: basePackageValues: name: 'my-app' version: '1.0.0' main: 'out.js' ; ;
Function
webpack.config.js
moduleexports = plugins: { const runtimeChunk = compilationentrypoints; return name: 'my-app' version: '1.0.0' main: runtimeChunkfiles0 ; } ;
outputPath
Type: String
Default: .
Specifies a filesystem path where the generated package.json will be placed.
webpack.config.js
moduleexports = plugins: // plugin will generate <output.path>/package/package.json outputPath: 'package' ;