rollup-plugin-generate-package-json
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/rollup-plugin-generate-package-json package

3.2.0 • Public • Published

rollup-plugin-generate-package-json

Build Status Codecov

Generate package.json file with packages from your bundle using Rollup.

About

This plugin is useful when you have a lot of packages in your current package.json file and want to create a lean one with only packages from your generated bundle, probably for deployment.

Installation

# yarn 
yarn add rollup-plugin-generate-package-json -D
 
# npm 
npm install rollup-plugin-generate-package-json -D

Usage

// rollup.config.js
import generatePackageJson from 'rollup-plugin-generate-package-json'
 
export default {
  input: 'src/index.js',
  output: {
    file: 'dist/app.js',
    format: 'cjs'
  },
  plugins: [
    generatePackageJson()
  ]
}

Configuration

There are some useful options, all of them are optional:

inputFolder

Type: string
Default: current working directory

Set input package.json folder.

generatePackageJson({
  inputFolder: 'nested/folder'
})

outputFolder

Type: string
Default: bundle output folder

Set output folder for generated package.json file.

generatePackageJson({
  outputFolder: 'dist'
})

baseContents

Type: object | function
Default: {}

Set base contents for your generated package.json file.

generatePackageJson({
  baseContents: {
    scripts: {
      start: 'node app.js'
    },
    dependencies: {},
    private: true
  }
})

It can also be a function, which receives the contents of the input package.json file.

generatePackageJson({
  baseContents: (pkg) => ({
    name: pkg.name,
    main: pkg.main.replace('src', 'dist')
    dependencies: {},
    private: true
  })
})

additionalDependencies

Type: Array | object
Default: []

Set dependencies which are not directly imported in the bundle, but are used by the app.

generatePackageJson({
  additionalDependencies: ['pg']
})

It's also possible to add new dependencies or overwrite dependency version.

generatePackageJson({
  additionalDependencies: {
    pg: '7.12.1',
    'react-calendar': 'file:../react-calendar/react-calendar-v2.13.2.tgz'
  }
})

License

MIT

Package Sidebar

Install

npm i rollup-plugin-generate-package-json

Weekly Downloads

39,010

Version

3.2.0

License

MIT

Unpacked Size

9.05 kB

Total Files

4

Last publish

Collaborators

  • shcherbin