{"id":20647,"library":"unused-webpack-plugin","title":"unused-webpack-plugin","description":"A webpack plugin that detects and lists unused source files in one or more directories, helping developers identify dead code. Current stable version is 2.4.0, with maintenance through minor releases. It supports webpack 3 and 4 via the hooks API. Key differentiators: simple configuration (directories, exclude patterns, root), optional failure on unused files, and respect for .gitignore (default true). It does not remove files, only reports them, and is focused on development builds. Compared to alternatives like 'webpack-deadcode-plugin', it is more minimal and relies on directories rather than webpack's module graph exclusively.","status":"maintenance","version":"2.4.0","language":"javascript","source_language":"en","source_url":"https://github.com/MatthieuLemoine/unused-webpack-plugin","tags":["javascript"],"install":[{"cmd":"npm install unused-webpack-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add unused-webpack-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add unused-webpack-plugin","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required as a peer dependency; plugin implements webpack compiler hooks.","package":"webpack","optional":true}],"imports":[{"note":"The package does not ship ESM exports; use CommonJS require.","wrong":"import UnusedWebpackPlugin from 'unused-webpack-plugin';","symbol":"UnusedWebpackPlugin","correct":"const UnusedWebpackPlugin = require('unused-webpack-plugin');"},{"note":"Default export is an unnamed function; named export does not exist. Avoid destructuring.","wrong":"const UnusedWebpackPlugin = require('unused-webpack-plugin').UnusedWebpackPlugin;","symbol":"UnusedWebpackPlugin","correct":"const { UnusedWebpackPlugin } = require('unused-webpack-plugin');"},{"note":"In TypeScript projects, use a type assertion or skip type checking since no type definitions are bundled.","wrong":"","symbol":"UnusedWebpackPlugin","correct":"const UnusedWebpackPlugin = require('unused-webpack-plugin');"}],"quickstart":{"code":"const path = require('path');\nconst UnusedWebpackPlugin = require('unused-webpack-plugin');\n\nmodule.exports = {\n  // webpack configuration\n  plugins: [\n    new UnusedWebpackPlugin({\n      // Source directories to scan\n      directories: [path.join(__dirname, 'src')],\n      // Exclude patterns (e.g., test files)\n      exclude: ['*.test.js', '*.spec.js', 'node_modules/**'],\n      // Root directory for relative paths (optional)\n      root: __dirname,\n      // Fail build if unused files found (optional, default false)\n      failOnUnused: false,\n      // Respect .gitignore (default true)\n      useGitIgnore: true,\n    }),\n  ],\n};","lang":"javascript","description":"Shows minimal webpack config with the UnusedWebpackPlugin, scanning 'src' directory, excluding test files, and setting root for relative output."},"warnings":[{"fix":"Upgrade to webpack 4+ or use v1.2.0 for webpack 3 support.","message":"v2.0.0 switched to webpack 4 hooks interface, breaking compatibility with webpack <3.","severity":"breaking","affected_versions":">=2.0.0 <3.0.0"},{"fix":"Consider alternatives like webpack-deadcode-plugin or unimported.","message":"Plugin is in maintenance mode; no new features are planned.","severity":"deprecated","affected_versions":">=2.0.0"},{"fix":"Use tools like ESLint with no-unused-vars or webpack-deadcode-plugin for unused exports.","message":"Plugin does not detect unused exports within files; it only lists files that are never imported.","severity":"gotcha","affected_versions":"*"},{"fix":"Always use path.join(__dirname, 'dir') or path.resolve() to define directories.","message":"Directories must be absolute paths; relative paths may fail silently.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run 'npm install webpack' or ensure webpack is in your devDependencies.","cause":"webpack is a peer dependency not installed automatically.","error":"Error: Cannot find module 'webpack'"},{"fix":"Use 'const UnusedWebpackPlugin = require('unused-webpack-plugin');' (no destructuring).","cause":"Incorrect import: using destructured import instead of default require.","error":"TypeError: UnusedWebpackPlugin is not a constructor"},{"fix":"Check that 'directories' array includes every source folder and adjust 'exclude' patterns (e.g., remove 'node_modules/**' if already ignored).","cause":"Directories option may not include all relevant directories or exclude patterns are too broad.","error":"No unused files found, but I know there are unused files."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}