esbuild plugin for extracting unused module
file list.
npm install -D esbuild-plugin-unused
import fs from 'fs';
import { build } from 'esbuild';
import extractUnusedFiles from 'esbuild-plugin-unused-modules';
build({
...options,
plugins: [
extractUnusedFiles('./src', (unusedFiles) => {
// print unused file list in console
console.log(unusedFiles);
// write unused file list in any file
fs.writeFileSync('unusedFiles.json', JSON.stringify(unusedFiles));
/* ex) remove unused files, ...etc */
})
],
});
const extractUnusedFiles: (rootPath: string, callback: (unusedFiles: string[]) => void, options?: {
excludeExp?: RegExp;
tsconfigFileName?: string;
}) => {
name: string;
setup(build: PluginBuild): void;
};
excludeExp
: RegExp for excluding in unusedFilestsconfigFileName
: TypeScript config file name, If you are using a TypeScript config file name other than tsconfig.json, you need that option. (default: 'tsconfig.json')