@putout/plugin-minify
🐊Putout plugin contains minifiers
Last updated 5 months ago by coderaiser .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install @putout/plugin-minify 
SYNC missed versions from official npm registry.

@putout/plugin-minify NPM version

🐊Putout plugin adds support of minifiers used in @putout/minify and minify.

Install

npm i @putout/plugin-putout -D

Rules

Config

{
    "rules": {
        "minify/apply-ternary": "on",
        "minify/apply-template-literal": "on",
        "minify/convert-var-to-const": "on",
        "minify/convert-if-to-logical": "on",
        "minify/convert-strict-equal-to-equal": "on",
        "minify/convert-array-from-to-spread": "on",
        "minify/convert-return-to-sequence-expression": "on",
        "minify/extract-body": "on",
        "minify/expand-bindings": "on",
        "minify/mangle-names": ["on", {
            "mangleClassNames": true
        }],
        "minify/merge-assignment-expressions": "on",
        "minify/merge-variables": "on",
        "minify/merge-loops": "on",
        "minify/remove-var-undefined": "on",
        "minify/remove-return-undefined": "on",
        "minify/simplify-floor": "on",
        "minify/shorten-names": "on",
        "minify/join-continued-strings": "on",
        "minify/inline": "on",
        "minify/types": "on"
    }
}

apply-ternary

Check out in 🐊Putout Editor.

❌ Example of incorrect code

if (a)
    b();
else
    c();

βœ… Example of correct code

a ? b() : c();

apply-template-literal

Not only short, but also fast:

// 34.795ms
for (let i = 0; i < 1_000_000; i++)
    String(i);

// 28.302ms
for (let i = 0; i < 1_000_000; i++)
    i.toString();

// 24.818ms
for (let i = 0; i < 1_000_000; i++)
    `${i}`;

❌ Example of incorrect code

x.toString();
String(x);

βœ… Example of correct code

String(x);

convert-if-to-logical

Check out in 🐊Putout Editor.

❌ Example of incorrect code

if (a)
    console.log('hello');

if (b) {
    console.log('hello');
    console.log('world');
}

if (a) {
    console.log(1);
    console.log(2);
} else {
    console.log(3);
    console.log(4);
}

βœ… Example of correct code

a && console.log('hello');

b && (console.log('hello'), console.log('world'));

a ? (console.log(1), console.log(2)) : (console.log(3), console.log(4));

convert-const-to-var

❌ Example of incorrect code

const a = 5;

βœ… Example of correct code

var a = 5;

convert-return-to-sequence-expression

Check out in 🐊Putout Editor.

❌ Example of incorrect code

() => {
    d();
    return 1;
};

βœ… Example of correct code

() => {
    d();
    return 1;
};

convert-strict-equal-to-equal

Check out in 🐊Putout Editor.

❌ Example of incorrect code

a === b;

βœ… Example of correct code

a == b;

convert-array-from-to-spread

❌ Example of incorrect code

Array
    .from(a)
    .map((x, i) => `${i}: ${x}`);

βœ… Example of correct code

[...a].map((x, i) => `${i}: ${x}`);

extract-body

Check out in 🐊Putout Editor.

❌ Example of incorrect code

if (x)
    return;

const hello = () => {
    return 'world';
};

βœ… Example of correct code

if (x)
    return;

const hello = () => 'world';

expand-bindings

Check out in 🐊Putout Editor.

❌ Example of incorrect code

const y = 'abc';
const x = y;
const fn = require(x);

const a = 5;
const b = a;
const c = b;

fn(c);

βœ… Example of correct code

require('abc')(5);

remove-var-undefined

Checkout in 🐊Putout Editor.

❌ Example of incorrect code

var a = undefined;

βœ… Example of correct code

var a;

remove-return-undefined

❌ Example of incorrect code

const fn = () => {
    if (a)
        return undefined;
    
    return undefined;
};

βœ… Example of correct code

const fn = () => {
    if (a)
        return;
};

mangle-names

Check out in 🐊Putout Editor.

❌ Example of incorrect code

function generate() {
    const hello = 'hi';
    return hello;
}

βœ… Example of correct code

function generate() {
    const a = 'hi';
    return a;
}

When you want to preserve class names use

{
    "rules": {
        "minify/mangle-names": ["on", {
            "mangleClassNames": false
        }]
    }
}

In this case you will see:

❌ Example of incorrect code

class Hello {
    world() {
        const hello = 'hello';
        return hello;
    }
}

βœ… Example of correct code

class Hello {
    world() {
        const a = 'hello';
        return a;
    }
}

merge-assignment-expressions

Check out in 🐊Putout Editor.

❌ Example of incorrect code

a = 'hello';
b = 'hello';
c = 'hello';
d = 'hello';

βœ… Example of correct code

a = b = c = d = 'hello';

merge-variables

Check out in 🐊Putout Editor.

❌ Example of incorrect code

var a;
var b;

βœ… Example of correct code

var a, b;

merge-loops

Check out in 🐊Putout Editor.

❌ Example of incorrect code

for (const aa of a)
    d.push(aa);

for (const bb of b)
    d.push(bb);

βœ… Example of correct code

for (const aa of [...a, ...b])
    d.push(aa);

simplify-floor

Not only shorter, but faster:

// 5.027ms
for (let i = 0; i < 1_000_000; i++)
    Math.floor(i + 0.5);

// 3.493ms
for (let i = 0; i < 1_000_000; i++)
    ~~(i + 0.5);

❌ Example of incorrect code

Math.floor(x);

βœ… Example of correct code

~~x;

shorten-names

Feats good to @putout/plugin-declare. Check out in 🐊Putout Editor.

❌ Example of incorrect code

const a = (b) => {
    Object.keys(b);
};

const b = (keys) => {
    Object.keys(keys);
};

Object.freeze(a);
Object.defineProperty(b);

βœ… Example of correct code

const a = (b) => {
    keys(b);
};

const b = (keys) => {
    Object.keys(keys);
};

freeze(a);
defineProperty(b);

types

Check out in 🐊Putout Editor.

❌ Example of incorrect code

const a = undefined;
const b = true;
const c = false;

βœ… Example of correct code

const a = void 0;
const b = !0;
const c = !1;

join-continued-strings

Join continued strings to one line. Check out in 🐊Putout Editor.

❌ Example of incorrect code

console.log(`\
  1\
  2\
  3`, '\
  a\
  b\
  c');

βœ… Example of correct code

console.log(`  1  2  3`, '  a  b  c');

inline

Check out in 🐊Putout Editor.

❌ Example of incorrect code

let x = 1;
--x;

if (!x)
    console.log('hello');

βœ… Example of correct code

let x = 1;

if (!--x)
    console.log('hello');

License

MIT

Current Tags

  • 8.19.2                                ...           latest (5 months ago)

90 Versions

  • 8.19.2                                ...           5 months ago
  • 8.19.1                                ...           5 months ago
  • 8.19.0                                ...           5 months ago
  • 8.18.0                                ...           5 months ago
  • 8.17.0                                ...           5 months ago
  • 8.16.1                                ...           5 months ago
  • 8.16.0                                ...           5 months ago
  • 8.15.1                                ...           5 months ago
  • 8.15.0                                ...           5 months ago
  • 8.14.0                                ...           5 months ago
  • 8.13.0                                ...           5 months ago
  • 8.12.0                                ...           5 months ago
  • 8.11.0                                ...           5 months ago
  • 8.10.0                                ...           5 months ago
  • 8.9.1                                ...           5 months ago
  • 8.9.0                                ...           5 months ago
  • 8.8.1                                ...           5 months ago
  • 8.8.0                                ...           5 months ago
  • 8.7.0                                ...           5 months ago
  • 8.6.0                                ...           5 months ago
  • 8.5.0                                ...           5 months ago
  • 8.4.0                                ...           5 months ago
  • 8.3.0                                ...           5 months ago
  • 8.2.0                                ...           9 months ago
  • 8.1.0                                ...           9 months ago
  • 8.0.0                                ...           10 months ago
  • 7.1.1                                ...           10 months ago
  • 7.1.0                                ...           10 months ago
  • 7.0.0                                ...           10 months ago
  • 6.2.0                                ...           a year ago
  • 6.1.2                                ...           a year ago
  • 6.1.1                                ...           a year ago
  • 6.1.0                                ...           a year ago
  • 6.0.0                                ...           a year ago
  • 5.1.0                                ...           a year ago
  • 5.0.0                                ...           a year ago
  • 4.1.0                                ...           a year ago
  • 4.0.0                                ...           a year ago
  • 3.1.0                                ...           a year ago
  • 3.0.0                                ...           a year ago
  • 2.4.0                                ...           a year ago
  • 2.3.0                                ...           a year ago
  • 2.2.0                                ...           a year ago
  • 2.1.0                                ...           a year ago
  • 2.0.2                                ...           a year ago
  • 2.0.1                                ...           a year ago
  • 2.0.0                                ...           a year ago
  • 1.40.0                                ...           a year ago
  • 1.39.0                                ...           a year ago
  • 1.38.0                                ...           a year ago
  • 1.37.0                                ...           a year ago
  • 1.36.0                                ...           a year ago
  • 1.35.1                                ...           a year ago
  • 1.35.0                                ...           a year ago
  • 1.34.0                                ...           a year ago
  • 1.33.0                                ...           a year ago
  • 1.32.0                                ...           a year ago
  • 1.31.1                                ...           a year ago
  • 1.31.0                                ...           a year ago
  • 1.30.0                                ...           a year ago
  • 1.29.0                                ...           a year ago
  • 1.28.0                                ...           a year ago
  • 1.26.0                                ...           a year ago
  • 1.25.0                                ...           a year ago
  • 1.24.0                                ...           a year ago
  • 1.23.0                                ...           a year ago
  • 1.22.0                                ...           a year ago
  • 1.21.0                                ...           a year ago
  • 1.20.0                                ...           a year ago
  • 1.19.0                                ...           a year ago
  • 1.18.0                                ...           a year ago
  • 1.17.0                                ...           a year ago
  • 1.16.0                                ...           a year ago
  • 1.15.0                                ...           a year ago
  • 1.14.0                                ...           a year ago
  • 1.13.0                                ...           a year ago
  • 1.12.0                                ...           a year ago
  • 1.11.0                                ...           a year ago
  • 1.10.0                                ...           a year ago
  • 1.9.0                                ...           a year ago
  • 1.8.1                                ...           a year ago
  • 1.8.0                                ...           a year ago
  • 1.7.0                                ...           a year ago
  • 1.6.0                                ...           a year ago
  • 1.5.0                                ...           a year ago
  • 1.4.0                                ...           a year ago
  • 1.3.0                                ...           a year ago
  • 1.2.0                                ...           a year ago
  • 1.1.0                                ...           a year ago
  • 1.0.0                                ...           2 years ago
Maintainers (1)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (3)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE