Socket
Socket
Sign inDemoInstall

babel-plugin-minify-dead-code-elimination

Package Overview
Dependencies
4
Maintainers
5
Versions
91
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-minify-dead-code-elimination


Version published
Maintainers
5
Created

Package description

What is babel-plugin-minify-dead-code-elimination?

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.

What are babel-plugin-minify-dead-code-elimination's main functionalities?

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());

Other packages similar to babel-plugin-minify-dead-code-elimination

Readme

Source

babel-plugin-minify-dead-code-elimination

Inlines bindings when possible. Tries to evaluate expressions and prunes unreachable as a result.

Example

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);
}

Installation

npm install babel-plugin-minify-dead-code-elimination

Usage

.babelrc

// without options
{
  "plugins": ["minify-dead-code-elimination"]
}

// with options
{
  "plugins": ["minify-dead-code-elimination", { "optimizeRawSize": true }]
}

Via CLI

babel --plugins minify-dead-code-elimination script.js

Via Node API

require("@babel/core").transform("code", {
  plugins: ["minify-dead-code-elimination"]
});

Options

  • 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)

Keywords

FAQs

Last updated on 04 May 2018

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc