esbuild-plugin-rdi

raw JSON →
0.0.0 verified Fri May 01 auth: no javascript

An esbuild plugin that removes duplicate require statements from minified builds, reducing bundle size by eliminating redundant module imports. Version 0.0.0 is the initial release. It integrates seamlessly with esbuild and tsup, supporting TypeScript out of the box. Key differentiator: focuses specifically on duplicate require removal in esbuild, filling a niche gap in build optimization. Development is active with no breaking changes yet.

error Error: Cannot find module 'esbuild-plugin-rdi'
cause Package installed under deprecated name 'ep-rdi' or not installed at all.
fix
Install with correct name: npm install esbuild-plugin-rdi
error SyntaxError: Named export 'rdiPlugin' not found
cause Trying to use require() instead of import.
fix
Use ES module import syntax: import { rdiPlugin } from 'esbuild-plugin-rdi'
error TypeError: rdiPlugin is not a function
cause Forgetting to invoke rdiPlugin() in plugins array.
fix
Use it as rdiPlugin() not just rdiPlugin
gotcha Plugin only works with CJS output format; does not affect ESM builds.
fix Ensure esbuild format is 'cjs'.
gotcha Plugin may remove require statements that are not truly duplicates if they have different runtime effects.
fix Manually verify that removed requires are safe.
deprecated Package name 'ep-rdi' is deprecated; use 'esbuild-plugin-rdi' instead.
fix Update npm package name to 'esbuild-plugin-rdi'.
npm install ep-rdi
yarn add ep-rdi
pnpm add ep-rdi

Shows how to use the plugin with esbuild to minify and remove duplicate requires from a bundle.

import { rdiPlugin } from 'esbuild-plugin-rdi';
import * as esbuild from 'esbuild';

await esbuild.build({
  entryPoints: ['src/index.ts'],
  outfile: 'dist/bundle.js',
  bundle: true,
  minify: true,
  format: 'cjs',
  plugins: [rdiPlugin()]
});