rollup-plugin-exclude-dependencies-from-bundle

raw JSON →
1.1.24 verified Mon Apr 27 auth: no javascript

A Rollup plugin that automatically externalizes a library's dependencies and peerDependencies from the bundle output. Version 1.1.24 is stable, with frequent releases following semantic versioning. It eliminates the need to manually maintain the `external` config for library projects, supporting both ESM and CJS output. Compared to alternatives like `rollup-plugin-auto-external`, this plugin offers simpler configuration with boolean flags for `dependencies` and `peerDependencies`. Ships TypeScript declarations and supports Rollup v4+.

error Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'rollup-plugin-exclude-dependencies-from-bundle'
cause Missing installation or incorrect Node.js ESM resolution.
fix
npm install --save-dev rollup-plugin-exclude-dependencies-from-bundle
error TypeError: excludeDependenciesFromBundle is not a function
cause Default import in ESM vs CJS require mismatch.
fix
Use import (ESM) or const plugin = require('rollup-plugin-exclude-dependencies-from-bundle').default;
error 'peerDependencies' is not defined in rollup.config.js
cause Forgetting to pass options object; passing undefined or missing property.
fix
Call excludeDependenciesFromBundle({ peerDependencies: true })
breaking Plugin requires Rollup v4 or later. No support for Rollup v3.
fix Upgrade Rollup to v4 or migrate to a different plugin for Rollup v3.
deprecated Options 'include' and 'exclude' were removed in v1.1.0; use boolean flags only.
fix Set 'dependencies' and 'peerDependencies' to true/false.
gotcha Does not handle 'optionalDependencies' or 'bundledDependencies'. Only 'dependencies' and 'peerDependencies'.
fix Manually add other categories to 'external' config if needed.
npm install rollup-plugin-exclude-dependencies-from-bundle
yarn add rollup-plugin-exclude-dependencies-from-bundle
pnpm add rollup-plugin-exclude-dependencies-from-bundle

Automatically externalize 'dependencies' and 'peerDependencies' from the Rollup bundle, avoiding bundling of external packages.

// rollup.config.mjs
import excludeDependenciesFromBundle from 'rollup-plugin-exclude-dependencies-from-bundle';

export default {
  input: 'src/index.ts',
  output: { file: 'dist/index.js', format: 'es' },
  plugins: [
    excludeDependenciesFromBundle({
      peerDependencies: true,
      dependencies: true
    })
  ]
};