{"id":22342452,"url":"https://github.com/mquy/webpack-deadcode-plugin","last_synced_at":"2025-05-16T02:07:11.553Z","repository":{"id":31602771,"uuid":"128387463","full_name":"MQuy/webpack-deadcode-plugin","owner":"MQuy","description":"Webpack plugin to detect unused files and unused exports in used files","archived":false,"fork":false,"pushed_at":"2023-12-15T05:14:33.000Z","size":1970,"stargazers_count":356,"open_issues_count":9,"forks_count":16,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-16T02:06:26.234Z","etag":null,"topics":["deadcode","plugin","unused","webpack"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MQuy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-04-06T11:41:07.000Z","updated_at":"2025-03-09T21:29:07.000Z","dependencies_parsed_at":"2023-12-15T06:29:09.745Z","dependency_job_id":"08978207-180c-46c4-9156-0de19c2fd2b0","html_url":"https://github.com/MQuy/webpack-deadcode-plugin","commit_stats":{"total_commits":73,"total_committers":14,"mean_commits":5.214285714285714,"dds":0.589041095890411,"last_synced_commit":"948212e0f1579eaa4fb171a2d32f55ba24b608e0"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MQuy%2Fwebpack-deadcode-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MQuy%2Fwebpack-deadcode-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MQuy%2Fwebpack-deadcode-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MQuy%2Fwebpack-deadcode-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MQuy","download_url":"https://codeload.github.com/MQuy/webpack-deadcode-plugin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254453652,"owners_count":22073617,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deadcode","plugin","unused","webpack"],"created_at":"2024-12-04T08:12:41.289Z","updated_at":"2025-05-16T02:07:11.536Z","avatar_url":"https://github.com/MQuy.png","language":"JavaScript","readme":"## Webpack Deadcode Plugin\n\nWebpack plugin to detect unused files and unused exports in used files\n\n[![npm][npm]][npm-url]\n[![node][node]][node-url]\n[![deps][deps]][deps-url]\n[![licenses][licenses]][licenses-url]\n\n### Installation\n\nVia npm:\n\n```bash\n$ npm install webpack-deadcode-plugin --save-dev\n```\n\nVia yarn:\n\n```bash\n$ yarn add -D webpack-deadcode-plugin\n```\n\n![output](https://i.imgur.com/3Ll49Pj.png)\n\n### Usage\n\nThe plugin will report unused files and unused exports into your terminal but those are not part of your webpack build process, therefore, it will not fail your build (warning you). Simple add into your webpack config as follows:\n\n✍️ If you use `babel-loader`, you have to set `modules: false` to make it works\n\n```bash\n# in .babelrc\n{\n  \"presets\": [\n    [\"env\", { modules: false }]\n  ]\n}\n\n# or in webpack.config.js -\u003e module/rules\n{\n  loader: 'babel-loader',\n  options: {\n    presets: [\n      ['env', { modules: false }]\n    ]\n  }\n}\n```\n\n**Webpack 3**\n\n```js\nconst DeadCodePlugin = require('webpack-deadcode-plugin');\n\nconst webpackConfig = {\n  ...\n  plugins: [\n    new DeadCodePlugin({\n      patterns: [\n        'src/**/*.(js|jsx|css)',\n      ],\n      exclude: [\n        '**/*.(stories|spec).(js|jsx)',\n      ],\n    })\n  ]\n}\n```\n\n**Webpack 4**\n\n```js\nconst DeadCodePlugin = require('webpack-deadcode-plugin');\n\nconst webpackConfig = {\n  ...\n  optimization: {\n    usedExports: true,\n  },\n  plugins: [\n    new DeadCodePlugin({\n      patterns: [\n        'src/**/*.(js|jsx|css)',\n      ],\n      exclude: [\n        '**/*.(stories|spec).(js|jsx)',\n      ],\n    })\n  ]\n}\n```\n\n#### Using non-existent css class names\n\nTo detect using non-existent class names in your codebase, you have to use [`es6-css-loader`](https://github.com/MQuy/es6-css-loader) instead of `style-loader/mini-css-extract-plugin`. They are quite similiar in term of api except [`es6-css-loader`](https://github.com/MQuy/es6-css-loader) supports to detect non-existent css class names.\n\n![non-existent css class names](https://i.imgur.com/amHZF5Q.png)\n\nYou can check `samples` folder, how to to config `webpack-deadcode-plugin` and `es6-css-loader`.\n\n#### Typescript\n\nUsing with typescript loader ([ts-loader](https://github.com/TypeStrong/ts-loader), [awesome-typescript-loader](https://github.com/s-panferov/awesome-typescript-loader)), if you enable `transpileOnly/happyPackMode`, output might be not correct due to [this issue](https://github.com/TypeStrong/ts-loader/issues/783). In case of incorrect output, the workaround solution is disabling `transpileOnly`, it will slow down webpack compiling time.\n\n✍ Under some circumstances and production mode, if your output displays incorrect unused files, we encourage switching to [`awesome-typescript-loader`](https://github.com/s-panferov/awesome-typescript-loader).\n\n### Configuration\n\n```js\nnew DeadCodePlugin(options);\n```\n\n#### options.patterns (default: `[\"**/*.*\"]`)\n\nThe array of patterns to look for unused files and unused export in used files. Directly pass to [`fast-glob`](https://github.com/mrmlnc/fast-glob)\n\n#### options.exclude (default: `[]`)\n\nThe array of patterns to not look at.\n\n#### options.context\n\nCurrent working directory for patterns above. If you don't set it explicitly, your webpack context will be used.\n\n#### options.failOnHint (default: `false`)\n\nDeadcode does not interrupt the compilation by default. If you want to cancel the compilation, set it true, it throws a fatal error and stops the compilation.\n\n#### options.detectUnusedFiles (default: `true`)\n\nWhether to run unused files detection or not.\n\n#### options.detectUnusedExport (default: `true`)\n\nWhether to run unused export detection or not.\n\n#### options.log (default: `\"all\"`)\n\n`\"all\"`: show all messages.\n\n`\"unused\"`: only show messages when there are either unused files or unused export.\n\n`\"none\"`: won't show unused files or unused export messages in the terminal, it can keep terminal clean when set `exportJSON` to `true`\n\n#### options.exportJSON (default: `false`)\n\n`false`: won't create `deadcode.json` for the unused files and unused export.\n\n`true`: create `deadcode.json` for the unused files and unused export at the root of the project.\n\nYou can set `exportJSON` to a specific path, and it will generate `deadcode.json` in that path.\n\n```js\nnew DeadCodePlugin({\n  patterns: [\"*.(js|css)\"],\n  exclude: [\"**/node_modules/**\"],\n  log: \"none\",\n  exportJSON: \"./analysis\"\n}),\n```\n\n[npm]: https://img.shields.io/npm/v/webpack-deadcode-plugin.svg\n[npm-url]: https://npmjs.com/package/webpack-deadcode-plugin\n[node]: https://img.shields.io/node/v/webpack-deadcode-plugin.svg\n[node-url]: https://nodejs.org\n[deps]: https://img.shields.io/david/MQuy/webpack-deadcode-plugin.svg\n[deps-url]: https://david-dm.org/MQuy/webpack-deadcode-plugin\n[licenses]: https://img.shields.io/github/license/MQuy/webpack-deadcode-plugin.svg\n[licenses-url]: https://github.com/MQuy/webpack-deadcode-plugin/blob/master/LICENSE\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmquy%2Fwebpack-deadcode-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmquy%2Fwebpack-deadcode-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmquy%2Fwebpack-deadcode-plugin/lists"}