A Webpack plugin to identify and optionally delete unused files in your project. This helps in keeping your project clean and efficient by removing unnecessary files.
To install the plugin, run:
npm install extract-unused-file-plugin --save-dev
To use the plugin, add it to your Webpack configuration file. Here is an example:
const ExtractUnusedFilePlugin = require('extract-unused-file-plugin');
module.exports = {
// other configurations...
plugins: [
new ExtractUnusedFilePlugin({
readDir: './src', // Directory to read files from
outputPath: './dist', // Path to output the unused files list
excludeFiles: ['static', '.md', '.txt'], // List of files to exclude
isDelete: false, // Whether to delete unused files
outputType: 'json', // Output type: 'json', 'browser', or 'log'
debug: true // Enable debug mode
})
]
};
readDir
: string - Directory to read files from.outputPath
: string - Path to output the unused files list.excludeFiles
: string[] - List of files to exclude. Can be strings or regular expressions.isDelete
: boolean - Whether to delete unused files. Default isfalse
.outputType
: string - Output type. Can bejson
,browser
, orlog
. Default isjson
.debug
: boolean - Enable debug mode. Default isfalse
.
- File Reading: The plugin reads all files in the specified directory, excluding those in the
excludeFiles
list. - Comparison: It compares these files with the files used in the Webpack build.
- Output: Unused files are listed in the specified output format. If
isDelete
istrue
, these files are deleted.
After running the plugin, you might get a result structured like this:
{
".tsx": [
"/Users/FakeName/Work/workspace/your-project/src/Button.tsx",
"/Users/Fake/Work/workspace/your-project/src/Result.tsx",
"/Users/FakeName/Work/workspace/your-project/src/Loading.tsx",
"/Users/FakeName/Work/workspace/your-project/src/NoPermission.tsx",
"/Users/FakeName/Work/workspace/your-project/src/Test.tsx",
"/Users/FakeName/Work/workspace/your-project/src/SelectTable.tsx",
"/Users/FakeName/Work/workspace/your-project/src/ButtonAutoPublish.tsx",
"/Users/FakeName/Work/workspace/your-project/src/ButtonScreenshot.tsx",
"/Users/FakeName/Work/workspace/your-project/src/ButtonTakeInfo.tsx",
"/Users/FakeName/Work/workspace/your-project/src/CardHistoryClass.tsx"
],
".scss": [
"/Users/FakeName/Work/workspace/your-project/src/DateTimePicker.scss",
"/Users/FakeName/Work/workspace/your-project/src/CardHistoryClass.scss",
"/Users/FakeName/Work/workspace/your-project/src/ConfirmList.scss"
]
}
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a pull request or open an issue.
FlyAboveGrass