rollup-plugin-unused

raw JSON →
0.1.1 verified Mon Apr 27 auth: no javascript

Rollup plugin that identifies source files not imported during a build, helping keep repositories clean. Version 0.1.1 (latest) released 2021-12-30, with low release cadence. Supports customization via extensions, include/exclude globs. Ships TypeScript definitions. Distinct from similar plugins (e.g., rollup-plugin-unused-files) by its minimal configuration and focus on detection rather than removal.

error Error: Could not resolve entry module (index.js)
cause rollup.config.js missing input or wrong path
fix
Ensure input points to your entry file, e.g., input: 'src/index.js'
error TypeError: findUnused is not a function
cause Using named import instead of default import
fix
Use 'import findUnused from 'rollup-plugin-unused'' instead of 'import { findUnused } from ...'
gotcha Plugin must be added before any other plugins that load files (e.g., @rollup/plugin-babel) to correctly detect unused imports.
fix Place findUnused() as the first plugin in the plugins array.
gotcha By default, plugin looks for source files with extension .js in the ./src/ folder. Files with other extensions or in other directories are ignored unless configured.
fix Use 'extensions' option for additional file types, 'include' option for a custom glob pattern.
gotcha 'include' option overrides 'extensions' option. If both are specified, only 'include' is used.
fix Use either 'include' or 'extensions', not both, unless you understand the override behavior.
deprecated No known deprecations for this package.
npm install rollup-plugin-unused
yarn add rollup-plugin-unused
pnpm add rollup-plugin-unused

Demonstrates basic usage detecting unused .js files in src/ directory during a Rollup build.

import findUnused from 'rollup-plugin-unused';
import resolve from '@rollup/plugin-node-resolve';

// rollup.config.js
export default {
  input: 'src/index.js',
  output: { file: 'dist/bundle.js', format: 'cjs' },
  plugins: [
    // Must come before any source-loading plugins
    findUnused({ extensions: ['.js'] }),
    resolve()
  ]
};