Registry / devops / esbuild-plugin-rdi

esbuild-plugin-rdi

JSON →
library0.0.0jsnpmunverified

esbuild-plugin-rdi is an ESBuild plugin designed to optimize JavaScript bundles by identifying and removing redundant `require` statements during the minification phase. This process helps to reduce the final bundle size, improving application load times and overall performance. The package is currently at version `0.0.0`, indicating an initial public release or very early development stage. As such, its API surface and internal behavior might be subject to rapid changes, and a formal release cadence is not yet established. Its primary differentiator lies in its targeted approach to deduplicating `require` calls, which can be particularly beneficial for projects that compile to or still rely on CommonJS modules, or when integrating with frameworks like React (versions 18 and 19) and Next.js (versions 14 and 15), especially in scenarios involving React Server Components where such optimizations are crucial. The plugin is intended for use within an `esbuild` build pipeline or through tools like `tsup` that leverage `esbuild`.

npm install esbuild-plugin-rdi
INSTALL
IMPORT
SIG · ESBUILD-PLUGIN-RDI
E
esbuild-plugin-rdi
devopsjavascriptv0.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

rdiPlugin
import { rdiPlugin } from 'esbuild-plugin-rdi';
const rdiPlugin = require('esbuild-plugin-rdi');
The library ships TypeScript types and is primarily consumed via ES Modules. While `require` might work in some transpiled environments, `import` is the idiomatic way.
RdiPluginOptions
import type { RdiPluginOptions } from 'esbuild-plugin-rdi';
Type import for configuring the plugin. Options are 'coming soon' according to the README, but the type definition would follow this pattern.

This quickstart demonstrates how to integrate `esbuild-plugin-rdi` into an `esbuild` configuration. It sets up a dummy project with duplicate `require` statements, runs `esbuild` with the plugin, and then outputs the (truncated) minified bundle to show its effect on CommonJS imports.

import * as esbuild from 'esbuild'; import { rdiPlugin } from 'esbuild-plugin-rdi'; import * as path from 'path'; import * as fs from 'fs'; const srcDir = path.resolve(__dirname, 'src'); const entryPoint = path.join(srcDir, 'index.js'); const outputDir = path.resolve(__dirname, 'dist'); const outputFile = path.join(outputDir, 'bundle.js'); // Create dummy files for demonstration if (!fs.existsSync(srcDir)) fs.mkdirSync(srcDir, { recursive: true }); if (!fs.existsSync(outputDir)) fs.mkdirSync(outputDir, { recursive: true }); fs.writeFileSync(entryPoint, ` const depA = require('./commonDep'); const depB = require('./anotherDep'); const depA_again = require('./commonDep'); // This duplicate 'require' will be targeted console.log(depA.message, depB.message, depA_again.message); `); fs.writeFileSync(path.join(srcDir, 'commonDep.js'), `exports.message = 'Hello from commonDep';`); fs.writeFileSync(path.join(srcDir, 'anotherDep.js'), `exports.message = 'Hello from anotherDep';`); async function buildExample() { try { await esbuild.build({ entryPoints: [entryPoint], bundle: true, outfile: outputFile, format: 'cjs', // Important: plugin targets 'require' statements plugins: [rdiPlugin()], minify: true, // Minification often exposes duplicate requires logLevel: 'info' }); console.log('Build successful! Output:', outputFile); const content = fs.readFileSync(outputFile, 'utf-8'); console.log('\n--- Generated Bundle Excerpt (first 500 chars) ---\n', content.substring(0, 500)); } catch (e) { console.error('ESBuild failed:', e); } finally { // Cleanup dummy files fs.unlinkSync(entryPoint); fs.unlinkSync(path.join(srcDir, 'commonDep.js')); fs.unlinkSync(path.join(srcDir, 'anotherDep.js')); fs.rmdirSync(srcDir); // fs.rmdirSync(outputDir, { recursive: true }); // Careful with this in real projects } } buildExample();
Debug
Known issues
gotchaThis package is currently at version `0.0.0`, indicating it's in a very early development stage. The API is subject to rapid change, and stability is not guaranteed across minor or even patch versions.
fix
Exercise caution when using in production. Pin to exact versions and consult the GitHub repository for any breaking changes or updated documentation before upgrading.
affects: >=0.0.0
gotchaThe plugin specifically targets `require` statements for deduplication. It will not process or deduplicate ES module `import` statements, which are typically handled by `esbuild`'s native tree-shaking and optimization capabilities.
fix
Ensure your project or the specific parts you want to optimize are using CommonJS `require` syntax for the plugin to be effective. For pure ESM projects, `esbuild`'s default optimizations are usually sufficient.
affects: >=0.0.0
gotchaThe effectiveness of `esbuild-plugin-rdi` is tied to `esbuild`'s minification process and specific build configurations. Different `esbuild` versions or custom plugin interactions might alter its behavior or impact.
fix
Thoroughly test the plugin with your exact `esbuild` setup and versions. Monitor bundle size changes and review the output to ensure it performs as expected. Report any unexpected behavior to the maintainers.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'esbuild-plugin-rdi' or its corresponding type declarations.
The package is not installed, or the module resolution path is incorrect, or TypeScript cannot find its type definitions.
fix
Run `npm install esbuild-plugin-rdi` or `pnpm add esbuild-plugin-rdi`. If using TypeScript, ensure your `tsconfig.json` has appropriate `moduleResolution` settings (e.g., `NodeNext` or `Bundler`).
Plugin 'rdiPlugin' is not a valid ESBuild plugin. Plugins must be an object with a 'name' and 'setup' property.
The `rdiPlugin` function was called incorrectly, or there's a version mismatch with `esbuild`.
fix
Ensure you are calling `rdiPlugin()` as a function to get the plugin object: `plugins: [rdiPlugin()]`. Do not pass `rdiPlugin` directly without invoking it.
Upgrade
Version history
0.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
esbuild-plugin-rdi — npm install esbuild-plugin-rdi · libregistry