vite-plugin-deadfile
raw JSON → 1.4.0 verified Mon Apr 27 auth: no javascript
Vite plugin to find unused source files (dead files) in Vite projects. Current stable version 1.4.0, released under MIT license. Uses @swc/core to detect pure type references and handles Vite's dynamic import (glob-import) feature via the isDynamicModuleLive callback. Differentiators: built for Vite ecosystem, supports TypeScript, customizable include/exclude patterns, optional throw-on-found for CI, and output to file. Peer dependency: vite ^4.0.0 || ^5.0.0 || ^6.0.0.
Common errors
error TypeError: deadFile is not a function ↓
cause Using named import { deadFile } instead of default import.
fix
Use default import: import deadFile from 'vite-plugin-deadfile'
error Cannot find module '@swc/core' ↓
cause @swc/core is an optional peer dependency but not installed.
fix
Run: npm install @swc/core --save-dev
error Error: `root` must be a string ↓
cause Passing root as something other than a string (e.g., array).
fix
Set root to a string: deadFile({ root: 'src' })
error [vite-plugin-deadfile] All source files: 0 ↓
cause Root directory is empty or include pattern matches no files.
fix
Verify root path and include pattern: root must contain source files matching include.
Warnings
breaking Plugin does not work with Vite versions before 4.0; peer dependencies only allow ^4.0.0 || ^5.0.0 || ^6.0.0. ↓
fix Upgrade Vite to 4.x, 5.x, or 6.x.
gotcha The default root is '.', which may include node_modules if not excluded. node_modules is excluded by default but other non-source dirs may be included. ↓
fix Set root explicitly (e.g., root: 'src') and use include/exclude patterns.
gotcha Dynamic imports (glob-import) require manually marking glob-imported files as alive via isDynamicModuleLive callback, otherwise they may be falsely reported as dead. ↓
fix Implement isDynamicModuleLive callback to return true for dynamically imported files.
gotcha The plugin uses @swc/core for type detection; if @swc/core is not installed, type-only imports may be incorrectly reported as dead. ↓
fix Install @swc/core as a dev dependency to enable accurate type reference detection.
deprecated No deprecation warnings reported for current version. ↓
fix N/A
Install
npm install vite-plugin-deadfile yarn add vite-plugin-deadfile pnpm add vite-plugin-deadfile Imports
- deadFile wrong
import { deadFile } from 'vite-plugin-deadfile'correctimport deadFile from 'vite-plugin-deadfile' - DeadFileOptions wrong
const DeadFileOptions = require('vite-plugin-deadfile').DeadFileOptionscorrectimport type { DeadFileOptions } from 'vite-plugin-deadfile' - deadFile (CommonJS) wrong
const deadFile = require('vite-plugin-deadfile')correctconst deadFile = require('vite-plugin-deadfile').default
Quickstart
// vite.config.js
import { defineConfig } from 'vite';
import deadFile from 'vite-plugin-deadfile';
export default defineConfig({
plugins: [deadFile({
root: 'src',
include: ['**/*.{js,ts,jsx,tsx}'],
exclude: ['**/*.test.*', '**/*.spec.*'],
throwWhenFound: true,
output: 'dead-files.txt'
})],
});