Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
babel-plugin-minify-dead-code-elimination
Advanced tools
Inlines bindings when possible. Tries to evaluate expressions and prunes unreachable as a result.
The babel-plugin-minify-dead-code-elimination package is a Babel plugin that helps in removing dead code from your JavaScript files. This can significantly reduce the size of your code by eliminating code that is never executed, such as unreachable code, unused variables, and functions.
Remove Unreachable Code
This feature removes code that is never executed. In the example, the `if` block will be removed because the condition is always false.
const condition = false;
if (condition) {
console.log('This will never be logged');
}
Remove Unused Variables
This feature removes variables that are declared but never used. In the example, `unusedVar` will be removed because it is never used.
const unusedVar = 42;
const usedVar = 24;
console.log(usedVar);
Remove Unused Functions
This feature removes functions that are declared but never called. In the example, `unusedFunction` will be removed because it is never called.
function unusedFunction() {
return 'I am not used';
}
function usedFunction() {
return 'I am used';
}
console.log(usedFunction());
UglifyJS is a JavaScript parser, minifier, compressor, and beautifier toolkit. It can also remove dead code, but it is a more general-purpose tool compared to babel-plugin-minify-dead-code-elimination, which is specifically designed for dead code elimination.
Terser is a JavaScript parser and mangler/compressor toolkit for ES6+. It is a fork of UglifyJS and offers similar functionalities, including dead code elimination. Terser is often used in modern JavaScript projects for minification and dead code removal.
This is a Rollup plugin that integrates Terser for minification and dead code elimination. It is specifically designed to work with Rollup, a module bundler for JavaScript, making it a good choice for projects that use Rollup.
Inlines bindings when possible. Tries to evaluate expressions and prunes unreachable as a result.
In
function foo() {var x = 1;}
function bar() { var x = f(); }
function baz() {
var x = 1;
console.log(x);
function unused() {
return 5;
}
}
Out
function foo() {}
function bar() { f(); }
function baz() {
console.log(1);
}
npm install babel-plugin-minify-dead-code-elimination --save-dev
.babelrc
(Recommended).babelrc
// without options
{
"plugins": ["minify-dead-code-elimination"]
}
// with options
{
"plugins": ["minify-dead-code-elimination", { "optimizeRawSize": true }]
}
babel --plugins minify-dead-code-elimination script.js
require("@babel/core").transform("code", {
plugins: ["minify-dead-code-elimination"]
});
keepFnName
- prevent plugin from removing function name. Useful for code depending on fn.name
keepFnArgs
- prevent plugin from removing function args. Useful for code depending on fn.length
keepClassName
- prevent plugin from removing class name. Useful for code depending on cls.name
tdz
- Account for TDZ (Temporal Dead Zone)FAQs
Inlines bindings when possible. Tries to evaluate expressions and prunes unreachable as a result.
The npm package babel-plugin-minify-dead-code-elimination receives a total of 315,638 weekly downloads. As such, babel-plugin-minify-dead-code-elimination popularity was classified as popular.
We found that babel-plugin-minify-dead-code-elimination demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.