{"id":22903,"library":"vite-plugin-unused-code","title":"vite-plugin-unused-code","description":"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+).","status":"active","version":"0.1.8","language":"javascript","source_language":"en","source_url":"https://github.com/CyanSalt/vite-plugin-unused-code","tags":["javascript","vite","rollup","deadcode","unused","typescript"],"install":[{"cmd":"npm install vite-plugin-unused-code","lang":"bash","label":"npm"},{"cmd":"yarn add vite-plugin-unused-code","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-plugin-unused-code","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency: requires Vite >=2.0.0 to function as a Vite plugin","package":"vite","optional":false}],"imports":[{"note":"ESM-only package; CommonJS require() will fail. Use dynamic import() if needed.","wrong":"const unusedCode = require('vite-plugin-unused-code')","symbol":"default (unusedCode)","correct":"import unusedCode from 'vite-plugin-unused-code'"},{"note":"Type import only; not a runtime export.","wrong":"import { VitePluginUnusedCodeOptions } from 'vite-plugin-unused-code'","symbol":"VitePluginUnusedCodeOptions","correct":"import type { VitePluginUnusedCodeOptions } from 'vite-plugin-unused-code'"},{"note":"The default export is a function that accepts an options object. No constructor or new keyword.","wrong":"unusedCode.new({ patterns: ['src/**/*.*'] })","symbol":"default export with options","correct":"unusedCode({ patterns: ['src/**/*.*'] })"}],"quickstart":{"code":"// vite.config.js\nimport { defineConfig } from 'vite';\nimport unusedCode from 'vite-plugin-unused-code';\n\nexport default defineConfig({\n  plugins: [\n    unusedCode({\n      patterns: ['src/**/*.*'],\n      exclude: ['src/legacy/**'],\n      detectUnusedFiles: true,\n      detectUnusedExport: true,\n      failOnHint: false,\n      exportJSON: false,\n      log: 'unused',\n    }),\n  ],\n});","lang":"javascript","description":"Shows how to import and configure vite-plugin-unused-code in a Vite config file with commonly used options."},"warnings":[{"fix":"Manually review or use additional tools (e.g., PurgeCSS, ts-prune) for CSS and type unused detection.","message":"Cannot detect unused CSS or TypeScript type exports – only JavaScript/TypeScript runtime exports are checked.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Use detectUnusedFiles only, or downgrade to Vite 7 or earlier for unused export detection.","message":"Rolldown (Vite 8+) does not report removed exports during tree shaking; unused exports will never be shown.","severity":"breaking","affected_versions":">=0.1.7"},{"fix":"Replace exclude with patterns like ['!excluded/**'].","message":"The 'exclude' option is deprecated; use micromatch negation patterns in 'patterns' instead.","severity":"deprecated","affected_versions":">=0.1.0"},{"fix":"Verify detection results manually for dynamic imports.","message":"Files matched by patterns are only considered unused if they have no imports or are not referenced. Dynamic imports (import()) may not be fully tracked.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Use import statement: import unusedCode from 'vite-plugin-unused-code'","cause":"Using CommonJS require() on an ESM-only package.","error":"TypeError: (0 , vite_plugin_unused_code.default) is not a function"},{"fix":"Upgrade to vite-plugin-unused-code >=0.1.7","cause":"Using an older version of the plugin with Vite 8 (Rolldown).","error":"Error: The plugin 'vite-plugin-unused-code' is not compatible with Vite 8. Please upgrade to a newer version."},{"fix":"Replace exclude with patterns: patterns: ['**/*.ts', '!ignore/**']","cause":"Using the deprecated 'exclude' option.","error":"The exclude option is deprecated and will be removed in a future version. Use micromatch negation patterns instead."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}