Registry / testing / vite-plugin-unused-code

vite-plugin-unused-code

JSON →
library0.1.8jsnpmunverified

A Vite/Rollup plugin to detect unused files and unused exports in used files (dead code elimination analysis). Current stable version is 0.1.8, released March 2026, with frequent bug fixes and Vite 8/Rolldown compatibility updates. Ported from webpack-deadcode-plugin; uses micromatch patterns for file matching. Key differentiator: provides both unused file and unused export detection in a single plugin for Vite/Rollup ecosystems. Limitations: cannot detect unused CSS or TypeScript types, and unused exports will not be reported in Rolldown (Vite 8+).

npm install vite-plugin-unused-code
INSTALL
IMPORT
SIG · VITE-PLUGIN-UNUSED
V
vite-plugin-unused-code
testingjavascriptv0.1.8
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
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 18–223 runs
build_error
glibc
node 18–223 runs
build_error
Code
Verified usage

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

default (unusedCode)
✓ import unusedCode from 'vite-plugin-unused-code'
✗ const unusedCode = require('vite-plugin-unused-code')
ESM-only package; CommonJS require() will fail. Use dynamic import() if needed.
VitePluginUnusedCodeOptions
✓ import type { VitePluginUnusedCodeOptions } from 'vite-plugin-unused-code'
✗ import { VitePluginUnusedCodeOptions } from 'vite-plugin-unused-code'
Type import only; not a runtime export.
default export with options
✓ unusedCode({ patterns: ['src/**/*.*'] })
✗ unusedCode.new({ patterns: ['src/**/*.*'] })
The default export is a function that accepts an options object. No constructor or new keyword.

Shows how to import and configure vite-plugin-unused-code in a Vite config file with commonly used options.

// vite.config.js import { defineConfig } from 'vite'; import unusedCode from 'vite-plugin-unused-code'; export default defineConfig({ plugins: [ unusedCode({ patterns: ['src/**/*.*'], exclude: ['src/legacy/**'], detectUnusedFiles: true, detectUnusedExport: true, failOnHint: false, exportJSON: false, log: 'unused', }), ], });
Debug
Known issues
gotchaCannot detect unused CSS or TypeScript type exports – only JavaScript/TypeScript runtime exports are checked.
fix
Manually review or use additional tools (e.g., PurgeCSS, ts-prune) for CSS and type unused detection.
affects: >=0.1.0
breakingRolldown (Vite 8+) does not report removed exports during tree shaking; unused exports will never be shown.
fix
Use detectUnusedFiles only, or downgrade to Vite 7 or earlier for unused export detection.
affects: >=0.1.7
deprecatedThe 'exclude' option is deprecated; use micromatch negation patterns in 'patterns' instead.
fix
Replace exclude with patterns like ['!excluded/**'].
affects: >=0.1.0
gotchaFiles matched by patterns are only considered unused if they have no imports or are not referenced. Dynamic imports (import()) may not be fully tracked.
fix
Verify detection results manually for dynamic imports.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: (0 , vite_plugin_unused_code.default) is not a function
Using CommonJS require() on an ESM-only package.
fix
Use import statement: import unusedCode from 'vite-plugin-unused-code'
Error: The plugin 'vite-plugin-unused-code' is not compatible with Vite 8. Please upgrade to a newer version.
Using an older version of the plugin with Vite 8 (Rolldown).
fix
Upgrade to vite-plugin-unused-code >=0.1.7
The exclude option is deprecated and will be removed in a future version. Use micromatch negation patterns instead.
Using the deprecated 'exclude' option.
fix
Replace exclude with patterns: patterns: ['**/*.ts', '!ignore/**']
Upgrade
Version history
0.1.8latest on npm
Audit
Dependencies
viterequiredpeer dependency: requires Vite >=2.0.0 to function as a Vite plugin
Agent activity
19 hits · last 30 days
node
18
Resources
vite-plugin-unused-code — npm install vite-plugin-unused-code · libregistry