Gathering detailed insights and metrics for webpack-deadcode-plugin
Gathering detailed insights and metrics for webpack-deadcode-plugin
Gathering detailed insights and metrics for webpack-deadcode-plugin
Gathering detailed insights and metrics for webpack-deadcode-plugin
npm install webpack-deadcode-plugin
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
352 Stars
93 Commits
16 Forks
5 Watching
3 Branches
12 Contributors
Updated on 03 Nov 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
8.6%
13,959
Compared to previous day
Last week
17.6%
68,131
Compared to previous week
Last month
16.9%
266,302
Compared to previous month
Last year
27.6%
2,456,137
Compared to previous year
Webpack plugin to detect unused files and unused exports in used files
Via npm:
1$ npm install webpack-deadcode-plugin --save-dev
Via yarn:
1$ yarn add -D webpack-deadcode-plugin
The 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:
✍️ If you use babel-loader
, you have to set modules: false
to make it works
1# in .babelrc 2{ 3 "presets": [ 4 ["env", { modules: false }] 5 ] 6} 7 8# or in webpack.config.js -> module/rules 9{ 10 loader: 'babel-loader', 11 options: { 12 presets: [ 13 ['env', { modules: false }] 14 ] 15 } 16}
Webpack 3
1const DeadCodePlugin = require('webpack-deadcode-plugin'); 2 3const webpackConfig = { 4 ... 5 plugins: [ 6 new DeadCodePlugin({ 7 patterns: [ 8 'src/**/*.(js|jsx|css)', 9 ], 10 exclude: [ 11 '**/*.(stories|spec).(js|jsx)', 12 ], 13 }) 14 ] 15}
Webpack 4
1const DeadCodePlugin = require('webpack-deadcode-plugin'); 2 3const webpackConfig = { 4 ... 5 optimization: { 6 usedExports: true, 7 }, 8 plugins: [ 9 new DeadCodePlugin({ 10 patterns: [ 11 'src/**/*.(js|jsx|css)', 12 ], 13 exclude: [ 14 '**/*.(stories|spec).(js|jsx)', 15 ], 16 }) 17 ] 18}
To detect using non-existent class names in your codebase, you have to use es6-css-loader
instead of style-loader/mini-css-extract-plugin
. They are quite similiar in term of api except es6-css-loader
supports to detect non-existent css class names.
You can check samples
folder, how to to config webpack-deadcode-plugin
and es6-css-loader
.
Using with typescript loader (ts-loader, awesome-typescript-loader), if you enable transpileOnly/happyPackMode
, output might be not correct due to this issue. In case of incorrect output, the workaround solution is disabling transpileOnly
, it will slow down webpack compiling time.
✍ Under some circumstances and production mode, if your output displays incorrect unused files, we encourage switching to awesome-typescript-loader
.
1new DeadCodePlugin(options);
["**/*.*"]
)The array of patterns to look for unused files and unused export in used files. Directly pass to fast-glob
[]
)The array of patterns to not look at.
Current working directory for patterns above. If you don't set it explicitly, your webpack context will be used.
false
)Deadcode 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.
true
)Whether to run unused files detection or not.
true
)Whether to run unused export detection or not.
"all"
)"all"
: show all messages.
"unused"
: only show messages when there are either unused files or unused export.
"none"
: won't show unused files or unused export messages in the terminal, it can keep terminal clean when set exportJSON
to true
false
)false
: won't create deadcode.json
for the unused files and unused export.
true
: create deadcode.json
for the unused files and unused export at the root of the project.
You can set exportJSON
to a specific path, and it will generate deadcode.json
in that path.
1new DeadCodePlugin({ 2 patterns: ["*.(js|css)"], 3 exclude: ["**/node_modules/**"], 4 log: "none", 5 exportJSON: "./analysis" 6}),
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 4/12 approved changesets -- score normalized to 3
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
52 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More