vite-plugin-unused-code

Vite/Rollup plugin to detect unused files and unused exports in used files.
This package is a ported version of webpack-deadcode-plugin
.
[!IMPORTANT]
This plugin cannot check for dependencies of non-JavaScript files or exports (for example: CSS, or types from TypeScript files), which may be misreported as unused, even if they actually appear in the compiled bundles. Please be careful!
Installation
npm install --save-dev vite-plugin-unused-code
Usage
import unusedCode from 'vite-plugin-unused-code'
export default {
plugins: [
unusedCode({
patterns: ['src/**/*.*'],
}),
],
}
Options
context
-
Type: string
-
Default: root
option of Vite, process.cwd()
as a fallback
Current working directory where patterns
and exclude
are located.
patterns
exclude
detectUnusedFiles
detectUnusedExport
log
-
Type: 'all' | 'used' | 'none'
-
Default: none
if logLevel
option of Vite is 'silent'
, 'unused'
if logLevel
option of Vite is 'error'
or 'warn'
, 'all'
otherwise
Adjust console output verbosity.
'all'
: Show all messages.
'used'
: Only show messages when there are either unused files or unused export.
'none'
: Won't show unused files or unused export messages in the console. It can keep terminal clean when set exportJSON
to true
.
exportJSON
failOnHint