babel-plugin-remove-code

0.0.6 • Public • Published

babel-plugin-remove-code

Remove any code from your project.

Build Status

Supported removals

Example

Debugger

In

// Debugger...
debugger;

Out

// Debugger...

Var

In

const stripA = 'foo';
const keepA = 'foo';
const stripBPattern = 'foo';
const keepBPattern = 'foo';
 
let stripC;
let keepC;
let stripFPattern;
let keepFPattern;
 
stripC = 'foo';
stripC = {};
keepC = 'foo';
stripFPattern = 'foo';
stripFPattern = {};
keepFPattern = 'foo';
 
export const stripG = {};
export const keepG = {};
export const stripHPattern = {};
export const keepHPattern = {};
 
export { stripD };
export { keepD };
export { stripIPattern };
export { keepIPattern };
 
export default { stripA, keepA, stripBPattern, keepBPattern };
 
console.log(stripA);
console.log(keepA);
console.log(stripBPattern);
console.log(keepBPattern);
 
if (stripA === 'foo') {}
if (keepA === 'foo') {}
if (stripBPattern === 'foo') {}
if (keepBPattern === 'foo') {}
 
if (stripC === 'foo' && keepC === 'foo') {}
if (stripFPattern === 'foo' && keepFPattern === 'foo') {}
 
keepA = stripA;
keepB = stripB && keepB;

Out

 
const keepA = 'foo';
 
const keepBPattern = 'foo';
 
let keepC;
 
let keepFPattern;
 
keepC = 'foo';
 
keepFPattern = 'foo';
 
export const keepG = {};
 
export const keepHPattern = {};
 
export { keepD };
 
export { keepIPattern };
 
export default { keepA, keepBPattern };
 
console.log(keepA);
 
console.log(keepBPattern);
 
if (keepA === 'foo') {}
 
if (keepBPattern === 'foo') {}
 
if (keepC === 'foo') {}
if (keepFPattern === 'foo') {}
 
keepB = keepB;

Export

In

export const stripA = {};
export const keepA = {};
export const stripBPattern = {};
export const keepBPattern = {};
 
export { stripC };
export { keepC };
export { stripDPattern };
export { keepDPattern };
 
export default { stripE, keepE, stripFPattern, keepFPattern };

Out

 
export const keepA = {};
 
export const keepBPattern = {};
 
export { keepC };
 
export { keepDPattern };
 
export default { keepE, keepFPattern };

Import

In

import { fsA } from "stripA";
import { fkA } from "keepA";
import { fsB } from "stripBPattern";
import { fkB } from "keepBPattern";
fsB('foo');
fkB('foo');
 
import fsC from "stripC";
import fkC from "keepC";
console.log(fsC);
console.log(fkC);
 
import fsD from "stripDPattern";
import fkD from "keepDPattern";
const fsDVar = fsD;
const fkDVar = fkD;
 
import { fsEProxy as fsE } from "stripE";
import { fkEProxy as fkE } from "keepE";
import { fsFProxy as fsF } from "stripFPattern";
import { fkFProxy as fkF } from "keepFPattern";
 
import "stripG";
import "keepG";
import "stripHPattern";
import "keepHPattern";
 
const keepI = fsF(fkF());
const keepJ = fkF(fsF());

Out

 
import { fkA } from "keepA";
 
import { fkB } from "keepBPattern";
 
fkB('foo');
 
import fkC from "keepC";
 
console.log(fkC);
 
import fkD from "keepDPattern";
 
const fkDVar = fkD;
 
import { fkEProxy as fkE } from "keepE";
 
import { fkFProxy as fkF } from "keepFPattern";
 
import "keepG";
 
import "keepHPattern";
 
const keepI;
const keepJ = fkF();

Function

In

function stripA () {}
function keepA () {}
const keepB = function stripB () {};
 
stripA();
console.keepC('foo');
console.keepC.stripC('foo');
console.stripD('bar');
console.stripD.keepD('bar');
 
stripA(keepC());
keepC(stripA());

Out

 
function keepA() {}
const keepB;
 
console.keepC('foo');
 
keepC();

Installation

npm install --save-dev babel-plugin-remove-code

Usage

Via .babelrc (Recommended)

.babelrc

{
  "plugins": [
    ["remove-code", {
        "debugger": true,
        "var": ["pattern"],
        "export": ["pattern"],
        "import": ["pattern"],
        "function": ["pattern"]
    }]
  ]
}

Note: Regex patterns work but the . is escaped.

Package Sidebar

Install

npm i babel-plugin-remove-code

Weekly Downloads

849

Version

0.0.6

License

none

Last publish

Collaborators

  • sendoushi