Socket
Socket
Sign inDemoInstall

pnp-package-json-webpack-plugin

Package Overview
Dependencies
77
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    pnp-package-json-webpack-plugin

A webpack plugin to generate package.json file with external modules as dependencies


Version published
Weekly downloads
7
increased by600%
Maintainers
1
Install size
1.60 MB
Created
Weekly downloads
 

Readme

Source

npm node deps downloads

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-plugin

Install

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 = require('pnp-package-json-webpack-plugin');

const basePackageValues = {
  name: 'my-nodejs-module',
  version: '1.0.0',
  main: './index.js',
  engines: {
    node: '>= 14.0.0',
  },
};

module.exports = {
  // ...
  plugins: [
    new PnpPackageJsonPlugin({
      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:

{
  "name": "",
  "version": "0.0.0",
  "description": "",
  "main": "main.js"
}

Specifies an object or function customizing the outputted package.json.

Object

webpack.config.js

module.exports = {
  plugins: [
    new PnpPackageJsonPlugin({
      basePackageValues: {
        name: 'my-app',
        version: '1.0.0',
        main: 'out.js',
      };
    }),
  ],
};
Function

webpack.config.js

module.exports = {
  plugins: [
    new PnpPackageJsonPlugin({
      basePackageValues(compilation) {
        const { runtimeChunk } = compilation.entrypoints.get('my-app');
        return {
          name: 'my-app',
          version: '1.0.0',
          main: runtimeChunk.files[0],
        };
      },
    }),
  ],
};

outputPath

Type: String Default: .

Specifies a filesystem path where the generated package.json will be placed.

webpack.config.js

module.exports = {
  plugins: [
    new PnpPackageJsonPlugin({
      // plugin will generate <output.path>/package/package.json
      outputPath: 'package',
    }),
  ],
};

Keywords

FAQs

Last updated on 20 May 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc