unplugin-unused
Check unused dependencies.
Installation
bash
npm i -D unplugin-unused
Usage
ts
Unused({
include: [/\.([cm]?[jt]sx?|vue)$/],
exclude: [/node_modules/],
level: 'warning', // or 'error'
/**
* Ignore some dependencies.
*/
ignore: {
peerDependencies: ['vue'],
},
// Or ignore all kinds of dependencies.
// ignore: ['vue'],
/**
* Dependency kinds to check.
*/
depKinds: ['dependencies', 'peerDependencies'],
})
Vite
ts
// vite.config.ts
import UnpluginUnused from 'unplugin-unused/vite'
export default defineConfig({
plugins: [UnpluginUnused()],
})
Rollup
ts
// rollup.config.js
import UnpluginUnused from 'unplugin-unused/rollup'
export default {
plugins: [UnpluginUnused()],
}
Rolldown
ts
// rolldown.config.js
import UnpluginUnused from 'unplugin-unused/rolldown'
export default {
plugins: [UnpluginUnused()],
}
esbuild
ts
// esbuild.config.js
import { build } from 'esbuild'
build({
plugins: [require('unplugin-unused/esbuild')()],
})
Webpack
ts
// webpack.config.js
module.exports = {
/* ... */
plugins: [require('unplugin-unused/webpack')()],
}