unused-files-webpack-plugin
raw JSON → 3.4.0 verified Sat Apr 25 auth: no javascript maintenance
A Webpack plugin that globs all files under the webpack context and reports which files are not required by the bundle. Version 3.4.0 is the latest stable release, with an unclear release cadence (last release appears to be in 2018). It differs from alternatives like `unused-webpack-plugin` by using `glob-all` for pattern matching and supporting `failOnUnused` to emit errors. The plugin helps identify dead code and redundant files in webpack projects. Note: The plugin is no longer actively maintained; users should consider alternatives or verify compatibility with modern webpack versions.
Common errors
error Cannot find module 'glob-all' ↓
cause Missing dependency `glob-all`
fix
Run
npm install glob-all or ensure it is in package.json. error TypeError: UnusedFilesWebpackPlugin is not a constructor ↓
cause Wrong import style; default import used as named
fix
Use
const UnusedFilesWebpackPlugin = require('unused-files-webpack-plugin') for CJS or import UnusedFilesWebpackPlugin from '...' for ESM. error Error: Cannot find module 'unused-files-webpack-plugin' ↓
cause Package not installed
fix
Run
npm install --save-dev unused-files-webpack-plugin. Warnings
deprecated Plugin is no longer actively maintained; last update in 2018. ↓
fix Consider alternatives like `unused-webpack-plugin` or `webpack-deadcode-plugin`.
gotcha Default pattern `**/*.*` may include binary or large files, causing performance issues. ↓
fix Specify more focused patterns, e.g., `['**/*.js', '**/*.jsx']`.
broken Incompatible with webpack 5 due to changed compiler hooks. ↓
fix Use webpack 4 or patch plugin; consider migrating to a maintained plugin.
Install
npm install unused-files-webpack-plugin yarn add unused-files-webpack-plugin pnpm add unused-files-webpack-plugin Imports
- default wrong
const UnusedFilesWebpackPlugin = require('unused-files-webpack-plugin')correctimport UnusedFilesWebpackPlugin from 'unused-files-webpack-plugin' - UnusedFilesWebpackPlugin wrong
const { UnusedFilesWebpackPlugin } = require('unused-files-webpack-plugin').defaultcorrectimport { UnusedFilesWebpackPlugin } from 'unused-files-webpack-plugin' - PluginOptions
import type { PluginOptions } from 'unused-files-webpack-plugin'
Quickstart
// webpack.config.js
const UnusedFilesWebpackPlugin = require('unused-files-webpack-plugin');
module.exports = {
// ... other webpack config
plugins: [
new UnusedFilesWebpackPlugin({
patterns: ['**/*.*'],
failOnUnused: false,
globOptions: {
ignore: 'node_modules/**/*'
}
})
]
};