dist-package
raw JSON → 1.0.1 verified Mon Apr 27 auth: no javascript
A Rolldown/Rollup/Vite/tsdown/tsup plugin that automatically cleans up package.json for distribution. It strips outDir prefixes from paths (e.g., ./dist/index.js → ./index.js), removes unwanted fields like scripts and devDependencies, handles bin paths, copies extra files, rewrites dependency versions (e.g., workspace: protocol), and allows custom transforms. Version 1.0.1 is current stable; the plugin is actively maintained and works across multiple bundlers. Key differentiator: no manual post-build editing of package.json. Ships TypeScript types.
Common errors
error TypeError: distPackage is not a function ↓
cause Using default import instead of named import: import distPackage from 'rolldown-plugin-dist-package'
fix
Use named import: import { distPackage } from 'rolldown-plugin-dist-package'
error Error: Cannot find module 'rolldown-plugin-dist-package' or its corresponding type declarations. ↓
cause Package not installed or TypeScript module resolution not configured for ESM.
fix
Install the package: npm install -D rolldown-plugin-dist-package; ensure tsconfig.json has 'moduleResolution': 'node16' or 'bundler'.
error RollupError: The plugin 'dist-package' hook 'generateBundle' returned a promise that was not awaited. ↓
cause The plugin's generateBundle hook may be async and not properly handled if used in an older Rollup version.
fix
Update Rollup to ^4.0.0 or ensure your Rollup version supports async hooks.
Warnings
gotcha Plugin auto-detects outDir from bundler output options; if output.dir is not set or overridden, paths may not be cleaned correctly. ↓
fix Explicitly set the outDir option in the plugin configuration, e.g., distPackage({ outDir: 'dist' }).
gotcha When using with Rollup <4 or Vite <7, ensure peer dependency version ranges are satisfied. The plugin requires rollup ^3.0.0 || ^4.0.0 and vite ^7.0.0 || ^8.0.0. ↓
fix Update your bundler to a supported version or pin a compatible plugin version.
gotcha The bin field handling strips outDir prefix but does NOT add './' prefix; Node.js expects bare paths for executables. If you need './' prefix for other fields, use bareFields option carefully. ↓
fix Review bin paths after build; they should be without './' (e.g., 'cli.js' not './cli.js').
deprecated No deprecated features as of version 1.0.1.
Install
npm install rolldown-plugin-dist-package yarn add rolldown-plugin-dist-package pnpm add rolldown-plugin-dist-package Imports
- distPackage wrong
import distPackage from 'rolldown-plugin-dist-package'correctimport { distPackage } from 'rolldown-plugin-dist-package' - type DistPackageOptions wrong
import { DistPackageOptions } from 'rolldown-plugin-dist-package'correctimport type { DistPackageOptions } from 'rolldown-plugin-dist-package' - distPackage (CommonJS) wrong
const distPackage = require('rolldown-plugin-dist-package')correctconst { distPackage } = require('rolldown-plugin-dist-package')
Quickstart
import { defineConfig } from 'rolldown';
import { distPackage } from 'rolldown-plugin-dist-package';
export default defineConfig({
input: 'src/index.ts',
output: { dir: 'dist' },
plugins: [
distPackage({
removeFields: ['scripts', 'devDependencies', 'lint-staged'],
set: { sideEffects: false, type: 'module' },
}),
],
});