prebundle
TypeScript icon, indicating that this package has built-in type declarations

1.2.5 • Public • Published

Prebundle

Prebundle Node.js dependencies, output a single js file, a package.json file and the dts files.

Based on ncc and rollup-plugin-dts.

npm version license

Motivation

Prebundle is used to:

  • Reduce dependencies of core packages, install faster.
  • Improve stability by locking the sub-dependency version .
  • Fix peer dependency warning of some packages.

Command

Run following command to prebundle all dependencies:

npx prebundle

Run following command to prebundle single dependencies:

npx prebundle <pkgName>

# For example, prebundle commander
npx prebundle commander

Dependency Config

Supported dependency config:

externals

Externals to leave as requires of the build.

// prebundle.config.mjs
export default {
  dependencies: [
    {
      name: 'foo',
      externals: {
        webpack: '../webpack',
      },
    },
  ],
};

You can also configure externals for all packages like this:

// prebundle.config.mjs
export default {
  externals: {
    webpack: '../webpack',
  },
  dependencies: [{ name: 'foo' }, { name: 'foo' }],
};

dtsExternals

Externals for dts.

// prebundle.config.mjs
export default {
  dependencies: [
    {
      name: 'foo',
      dtsExternals: ['webpack'],
    },
  ],
};

minify

Whether to minify the code, default false.

// prebundle.config.mjs
export default {
  dependencies: [
    {
      name: 'foo',
      minify: false,
    },
  ],
};

packageJsonField

Copy extra fields from original package.json to target package.json.

// prebundle.config.mjs
export default {
  dependencies: [
    {
      name: 'foo',
      packageJsonField: ['options'],
    },
  ],
};

Following fields will be copied by default:

  • name
  • author
  • version
  • funding
  • license
  • types
  • typing
  • typings

beforeBundle

Callback before bundle.

// prebundle.config.mjs
export default {
  dependencies: [
    {
      name: 'foo',
      beforeBundle(task) {
        console.log('do something');
      },
    },
  ],
};

emitFiles

Emit extra entry files to map imports.

// prebundle.config.mjs
export default {
  dependencies: [
    {
      name: 'foo',
      emitFiles: [
        {
          path: 'foo.js',
          content: `module.exports = require('./').foo;`,
        },
      ],
    },
  ],
};

ignoreDts

Ignore the original .d.ts declaration file, then generate a fake .d.ts file.

This can be used to reduce file size for the packages that do not require type definitions, such as webpack plugin.

// prebundle.config.mjs
export default {
  dependencies: [
    {
      name: 'foo',
      ignoreDts: true,
    },
  ],
};

target

Target ECMAScript version, default es2021.

// prebundle.config.mjs
export default {
  dependencies: [
    {
      name: 'foo',
      target: 'es2015',
    },
  ],
};

prettier

Whether to prettier the code and strip comments, default false.

// prebundle.config.mjs
export default {
  prettier: true,
};

Readme

Keywords

none

Package Sidebar

Install

npm i prebundle

Weekly Downloads

1,250

Version

1.2.5

License

none

Unpacked Size

348 kB

Total Files

22

Last publish

Collaborators

  • chenjiahan