@chrisneedham/rollup-plugin-peer-deps-external

中文文档
2.3.1发布于 2023/06/03MITESM + CJS零依赖近 30 天下载 1703

Rollup plugin to automatically add a library's peerDependencies to its bundle's external config.

原始使用文档
文档目录7 节
  1. Motivation
  2. Installation
  3. Usage
  4. Options
  5. packageJsonPath
  6. includeDependencies ** deprecated **
  7. Module paths

Build Status npm

Rollup Plugin Peer Deps External

Automatically externalize peerDependencies in a rollup bundle.

Motivation

When bundling a library using rollup, we generally want to keep from including peerDependencies since they are expected to be provided by the consumer of the library. By excluding these dependencies, we keep bundle size down and avoid bundling duplicate dependencies.

We can achieve this using the rollup external configuration option, providing it a list of the peer dependencies to exclude from the bundle. This plugin automates the process, automatically adding a library's peerDependencies to the external configuration.

Installation

npm install --save-dev rollup-plugin-peer-deps-external

Usage

// Add to plugins array in rollup.config.js
import peerDepsExternal from 'rollup-plugin-peer-deps-external';

export default {
  plugins: [
    // Preferably set as first plugin.
    peerDepsExternal(),
  ],
}

Options

packageJsonPath

If your package.json is not in the current working directory you can specify the path to the file

// Add to plugins array in rollup.config.js
import peerDepsExternal from 'rollup-plugin-peer-deps-external';

export default {
  plugins: [
    // Preferably set as first plugin.
    peerDepsExternal({
      packageJsonPath: 'my/folder/package.json'
    }),
  ],
}

includeDependencies **deprecated**

Set includeDependencies to true to also externalize regular dependencies in addition to peer deps.

// Add to plugins array in rollup.config.js
import peerDepsExternal from 'rollup-plugin-peer-deps-external';

export default {
  plugins: [
    // Preferably set as first plugin.
    peerDepsExternal({
      includeDependencies: true,
    }),
  ],
}

Module paths

This plugin is compatible with module path format applied by, for example, babel-plugin-lodash. For any module name in peerDependencies, all paths beginning with that module name will also be added to external.

E.g.: If lodash is in peerDependencies, an import of lodash/map would be added to externals.

版本与发布记录

@chrisneedham/rollup-plugin-peer-deps-external 共发布 1 个版本,首次发布于 2023/06/03;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.3.1latest2023/06/033 年前

关于 @chrisneedham/rollup-plugin-peer-deps-external 的常见问题

@chrisneedham/rollup-plugin-peer-deps-external 是什么?

Rollup plugin to automatically add a library's peerDependencies to its bundle's external config.

如何安装 @chrisneedham/rollup-plugin-peer-deps-external?

在项目目录运行 npm install @chrisneedham/rollup-plugin-peer-deps-external,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:rollup(^2.x || ^3.x)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@chrisneedham/rollup-plugin-peer-deps-external 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/chrisneedham__rollup-plugin-peer-deps-external 是否存在。

@chrisneedham/rollup-plugin-peer-deps-external 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@chrisneedham/rollup-plugin-peer-deps-external 可以商用吗?

@chrisneedham/rollup-plugin-peer-deps-external 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@chrisneedham/rollup-plugin-peer-deps-external 的下载量有多少?

根据 npm 官方下载统计,@chrisneedham/rollup-plugin-peer-deps-external 在 2026/10/10 – 2026/11/08 这 30 天内被下载 1,703 次,日均约 57 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@chrisneedham/rollup-plugin-peer-deps-external 还在维护吗?

最新版本 2.3.1 发布于 2023/06/03(3 年前);至今共发布 1 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/06/03。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。