esbuild-plugin-entry-chunks
raw JSON → 0.1.21 verified Mon Apr 27 auth: no javascript
An esbuild plugin (v0.1.21) that composes entry points as static chunks without extracting common code, addressing the missing manual-chunks API. It allows one entry point to reuse another as a dependency without duplicating contents. Released as a PoC, with esbuild >=0.19.0 as a peer dependency. Primary alternative to esbuild's code-splitting with dynamic imports for static chunk composition.
Common errors
error Error: Plugin 'entry-chunks' must be used with 'bundle: true' ↓
cause The plugin requires bundling to function; bundle option not set.
fix
Set bundle: true in esbuild config.
error TypeError: Cannot read properties of undefined (reading 'length') ↓
cause Entry points array is empty or undefined.
fix
Ensure entryPoints is an array with at least one file path.
Warnings
gotcha Plugin may cause output files to contain re-exported symbols from other entry points without extracting common code, leading to potential duplication across bundles. ↓
fix Ensure entry points are designed to be composed as dependencies (e.g., index.js vs cli.js). Use allowOverwrite: true to avoid errors.
gotcha Requires esbuild >=0.19.0 due to plugin API changes; older esbuild versions may fail to load the plugin. ↓
fix Update esbuild to >=0.19.0.
gotcha Plugin is in PoC status; not recommended for production use without extensive testing. ↓
fix Evaluate stability and test thoroughly before using in production.
Install
npm install esbuild-plugin-entry-chunks yarn add esbuild-plugin-entry-chunks pnpm add esbuild-plugin-entry-chunks Imports
- entryChunksPlugin wrong
const entryChunksPlugin = require('esbuild-plugin-entry-chunks').entryChunksPlugincorrectimport { entryChunksPlugin } from 'esbuild-plugin-entry-chunks' - default wrong
import { default as entryChunksPlugin } from 'esbuild-plugin-entry-chunks'correctimport entryChunksPlugin from 'esbuild-plugin-entry-chunks' - EntryChunksPluginOptions wrong
const EntryChunksPluginOptions = require('esbuild-plugin-entry-chunks').EntryChunksPluginOptionscorrectimport { EntryChunksPluginOptions } from 'esbuild-plugin-entry-chunks'
Quickstart
import { build } from 'esbuild';
import { entryChunksPlugin } from 'esbuild-plugin-entry-chunks';
const plugin = entryChunksPlugin();
const config = {
entryPoints: ['a.ts', 'b.ts', 'c.ts'],
plugins: [plugin],
external: ['node:*'],
bundle: true,
minify: false,
sourcemap: false,
format: 'esm',
allowOverwrite: true,
};
await build(config);