![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
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.
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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.