Convert Figma logo to code with AI

babel logominify

:scissors: An ES6+ aware minifier based on the Babel toolchain (beta)

4,391
225
4,391
202

Top Related Projects

8,615

🗜 JavaScript parser, mangler and compressor toolkit for ES6+

13,088

JavaScript parser / mangler / compressor / beautifier toolkit

A JavaScript checker and optimizer.

Terser Plugin

37,921

An extremely fast bundler for the web

31,086

Rust-based platform for the Web

Quick Overview

Babel Minify (also known as babili) is a JavaScript minifier designed to leverage Babel's toolchain for optimal minification. It aims to provide a configurable, ES6+-aware minification solution that can be used as a Babel preset or as a standalone tool.

Pros

  • Leverages Babel's parsing and transformation capabilities for better ES6+ support
  • Highly configurable with various optimization options
  • Can be used as a Babel preset or standalone CLI tool
  • Actively maintained and part of the Babel ecosystem

Cons

  • May be slower than some other minifiers due to its comprehensive approach
  • Requires Babel as a dependency, which can increase project size
  • Some optimizations might be less aggressive compared to specialized minifiers
  • Limited browser support information for certain optimizations

Code Examples

  1. Using Babel Minify as a preset:
// babel.config.js
module.exports = {
  presets: ['minify']
};
  1. Configuring specific minification options:
// babel.config.js
module.exports = {
  presets: [
    ['minify', {
      mangle: {
        keepClassName: true
      },
      deadcode: {
        keepFnArgs: true
      }
    }]
  ]
};
  1. Using Babel Minify programmatically:
const babel = require('@babel/core');
const minifyPreset = require('babel-preset-minify');

const result = babel.transformSync('const x = 5; console.log(x);', {
  presets: [minifyPreset]
});

console.log(result.code); // Output: console.log(5);

Getting Started

To use Babel Minify in your project:

  1. Install the necessary packages:

    npm install --save-dev @babel/core babel-preset-minify
    
  2. Create or update your babel.config.js:

    module.exports = {
      presets: ['minify']
    };
    
  3. Run Babel on your JavaScript files:

    npx babel src --out-dir dist
    

This will minify your JavaScript files using Babel Minify's default settings. Adjust the configuration as needed for your specific use case.

Competitor Comparisons

8,615

🗜 JavaScript parser, mangler and compressor toolkit for ES6+

Pros of Terser

  • Faster execution and better performance optimization
  • More active development and frequent updates
  • Wider community adoption and support

Cons of Terser

  • Less integration with Babel ecosystem
  • May require additional configuration for advanced use cases

Code Comparison

Minify:

const minify = require("babel-minify");
const result = minify("function add(a, b) { return a + b; }");
console.log(result.code);

Terser:

const Terser = require("terser");
const result = Terser.minify("function add(a, b) { return a + b; }");
console.log(result.code);

Key Differences

  • Terser is a fork of UglifyJS, while Minify is built on Babel
  • Terser focuses on JavaScript minification, while Minify leverages Babel's parsing capabilities
  • Terser generally produces smaller output and has better performance

Use Cases

  • Terser: Ideal for projects requiring fast and efficient minification
  • Minify: Better suited for projects already using Babel or requiring advanced ES6+ transformations

Community and Maintenance

  • Terser: More active development, larger user base
  • Minify: Less frequent updates, smaller community

Integration

  • Terser: Widely supported in build tools and bundlers
  • Minify: Tighter integration with Babel ecosystem
13,088

JavaScript parser / mangler / compressor / beautifier toolkit

Pros of UglifyJS

  • More mature and widely adopted project with a larger community
  • Faster execution time for minification tasks
  • Supports a broader range of JavaScript versions and features

Cons of UglifyJS

  • Less integrated with modern JavaScript toolchains
  • May require additional configuration for optimal results with ES6+ code
  • Slower development cycle and less frequent updates

Code Comparison

UglifyJS:

UglifyJS.minify(code, {
  compress: {
    dead_code: true,
    drop_debugger: true,
    conditionals: true,
    evaluate: true,
    booleans: true,
    loops: true,
    unused: true,
    hoist_funs: true,
    keep_fargs: false,
    hoist_vars: true,
    if_return: true,
    join_vars: true,
    cascade: true,
    side_effects: true,
    warnings: false
  }
});

Babel Minify:

const babel = require("@babel/core");
const minifyPreset = require("babel-preset-minify");

babel.transform(code, {
  presets: [minifyPreset()]
});

Both UglifyJS and Babel Minify are popular JavaScript minification tools, each with its own strengths. UglifyJS is a more established project with faster execution times and broader JavaScript support. However, Babel Minify integrates better with modern JavaScript toolchains and may be more suitable for projects already using Babel. The code comparison shows that UglifyJS offers more granular control over minification options, while Babel Minify provides a simpler API through its preset system.

A JavaScript checker and optimizer.

Pros of Closure Compiler

  • More advanced optimization techniques, including dead code elimination and function inlining
  • Supports type checking and annotation-based optimizations
  • Mature project with extensive documentation and community support

Cons of Closure Compiler

  • Steeper learning curve due to its complexity and advanced features
  • Slower compilation times, especially for large projects
  • Requires specific coding patterns and annotations for optimal results

Code Comparison

Babel Minify:

function greet(name) {
  console.log("Hello, " + name + "!");
}
greet("World");

Closure Compiler (Advanced mode):

console.log("Hello, World!");

Key Differences

  • Closure Compiler performs more aggressive optimizations, potentially resulting in smaller output
  • Babel Minify is easier to set up and use, especially for projects already using Babel
  • Closure Compiler provides better support for large-scale applications and library development
  • Babel Minify focuses on JavaScript-specific optimizations, while Closure Compiler can handle other languages like TypeScript

Use Cases

  • Choose Closure Compiler for large, complex projects requiring advanced optimizations
  • Opt for Babel Minify for simpler projects or when already using the Babel ecosystem
  • Consider Closure Compiler when type checking and annotation-based optimizations are important
  • Use Babel Minify for quick and easy minification without extensive configuration

Terser Plugin

Pros of terser-webpack-plugin

  • Seamless integration with Webpack, optimized for its ecosystem
  • Utilizes Terser, a modern JavaScript minifier with better performance
  • Supports caching for faster subsequent builds

Cons of terser-webpack-plugin

  • Limited to Webpack projects, less versatile than babel-minify
  • May require additional configuration for optimal results
  • Focuses primarily on minification, lacking some of babel-minify's transformation capabilities

Code Comparison

terser-webpack-plugin:

const TerserPlugin = require('terser-webpack-plugin');

module.exports = {
  optimization: {
    minimizer: [new TerserPlugin()],
  },
};

babel-minify:

const MinifyPlugin = require('babel-minify-webpack-plugin');

module.exports = {
  plugins: [
    new MinifyPlugin()
  ],
};

Summary

terser-webpack-plugin is tailored for Webpack projects, offering seamless integration and leveraging Terser for efficient minification. It excels in performance and caching capabilities. However, it's limited to the Webpack ecosystem and may require more setup for optimal results.

babel-minify, on the other hand, provides a more versatile solution that can be used in various JavaScript projects, not just Webpack. It offers additional code transformation features beyond minification but may have slightly lower performance in some scenarios.

Choose terser-webpack-plugin for Webpack-specific projects prioritizing performance, and babel-minify for broader JavaScript optimization needs or when additional code transformations are required.

37,921

An extremely fast bundler for the web

Pros of esbuild

  • Significantly faster build times due to its Go-based implementation
  • Supports modern JavaScript features and TypeScript out of the box
  • Offers a simple API and configuration options

Cons of esbuild

  • Less mature and may have fewer plugins available compared to Babel ecosystem
  • Limited customization options for advanced use cases
  • May not support older JavaScript syntax or certain edge cases

Code Comparison

esbuild:

import * as esbuild from 'esbuild'

await esbuild.build({
  entryPoints: ['app.js'],
  bundle: true,
  minify: true,
  outfile: 'out.js',
})

babel-minify:

const minify = require('babel-minify');

const {code, map} = minify('input code', {
  mangle: true,
  deadcode: true
});

Summary

esbuild offers superior performance and modern language support, making it ideal for projects prioritizing build speed. However, minify, being part of the Babel ecosystem, provides more extensive customization options and better support for older JavaScript syntax. The choice between the two depends on project requirements, with esbuild excelling in speed and simplicity, while minify offers more flexibility and compatibility with legacy code.

31,086

Rust-based platform for the Web

Pros of swc

  • Significantly faster performance due to being written in Rust
  • Supports both JavaScript and TypeScript out of the box
  • Actively maintained with frequent updates and improvements

Cons of swc

  • Less mature ecosystem compared to Babel
  • May have fewer plugins and customization options
  • Potential compatibility issues with some existing Babel-based workflows

Code Comparison

swc:

use swc_ecma_minifier::option::MinifyOptions;
use swc_ecma_minifier::optimize;

let result = optimize(
    ast,
    source_map,
    handler,
    &MinifyOptions::default(),
    &mut Default::default(),
);

babel-minify:

const minify = require("babel-minify");

const { code, map } = minify("input code", {
  mangle: true,
  deadcode: true
});

While both tools aim to minify JavaScript code, swc's implementation in Rust offers potential performance benefits. However, babel-minify's JavaScript-based approach may be more familiar to some developers and easier to integrate into existing JavaScript projects. swc provides a more comprehensive solution for both transpilation and minification, while babel-minify focuses specifically on minification within the Babel ecosystem.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

babel-minify (beta)

An ES6+ aware minifier based on the Babel toolchain.

NPM Version Travis Status CircleCI Status AppveyorCI Status Code Coverage Slack Status NPM Downloads

  • babel-minify is consumable via API, CLI, or Babel preset. Try it online - babeljs.io/repl

Historical note: babel-minify was renamed from babili.

Table of Contents

Experimental

babel-minify is an experimental project that attempts to use Babel's toolchain (for compilation) to do something in a similar vein, minification. It's currently in 0.x, so we don't recommend using it in production.

Checkout our CONTRIBUTING.md if you want to help out!

Requirements

  • node >= 6
  • babel >= 6.20.0

Why

Current tools don't support targeting the latest version of ECMAScript. (yet)

  • BabelMinify can because it is just a set of Babel plugins, and Babel already understands new syntax with our parser Babylon.
  • When it's possible to only target browsers that support newer ES features, code sizes can be smaller because you don't have to transpile and then minify.

Check out our blog post for more info!

// Example ES2015 Code
class Mangler {
  constructor(program) {
    this.program = program;
  }
}
new Mangler(); // without this it would just output nothing since Mangler isn't used

Before

// ES2015+ code -> Babel -> BabelMinify/Uglify -> Minified ES5 Code
var a=function a(b){_classCallCheck(this,a),this.program=b};new a;

After

// ES2015+ code -> BabelMinify -> Minified ES2015+ Code
class a{constructor(b){this.program=b}}new a;

CLI

PackageVersionDependencies
babel-minifynpmDependency Status

Install

npm install babel-minify --save-dev

Usage

minify src -d lib

Babel preset

PackageVersionDependencies
babel-preset-minifynpmDependency Status

Install

npm install babel-preset-minify --save-dev

Usage

note: minify is still in beta, so we don't recommend using it for production code but rather the production environment.

When testing, it's recommended to run minifiers for production so less code is sent to end-users vs. in development where it can be an issue for readability when debugging. Check out the env docs for more help.

Options specific to a certain environment are merged into and overwrite non-env specific options.

.babelrc:

{
  "presets": ["es2015"],
  "env": {
    "production": {
      "presets": ["minify"]
    }
  }
}

Then you'll need to set the env variable which could be something like BABEL_ENV=production npm run build

Individual Plugins

The minify repo is comprised of many npm packages. It is a lerna monorepo similar to babel itself.

The npm package babel-preset-minify is at the path packages/babel-preset-minify

PackageVersionDependencies
babel-plugin-minify-constant-foldingnpmDependency Status
babel-plugin-minify-dead-code-eliminationnpmDependency Status
babel-plugin-minify-flip-comparisonsnpmDependency Status
babel-plugin-minify-guarded-expressionsnpmDependency Status
babel-plugin-minify-infinitynpmDependency Status
babel-plugin-minify-mangle-namesnpmDependency Status
babel-plugin-minify-replacenpmDependency Status
babel-plugin-minify-simplifynpmDependency Status
babel-plugin-minify-type-constructorsnpmDependency Status
babel-plugin-transform-member-expression-literalsnpmDependency Status
babel-plugin-transform-merge-sibling-variablesnpmDependency Status
babel-plugin-transform-minify-booleansnpmDependency Status
babel-plugin-transform-property-literalsnpmDependency Status
babel-plugin-transform-simplify-comparison-operatorsnpmDependency Status
babel-plugin-transform-undefined-to-voidnpmDependency Status

Usage

Normally you wouldn't be consuming the plugins directly since the preset is available.

Add to your .babelrc's plugins array.

{
  "plugins": ["babel-plugin-transform-undefined-to-void"]
}

Other

PackageVersionDependencies
babel-plugin-transform-inline-environment-variablesnpmDependency Status
babel-plugin-transform-node-env-inlinenpmDependency Status
babel-plugin-transform-remove-consolenpmDependency Status
babel-plugin-transform-remove-debuggernpmDependency Status

Benchmarks

Bootstrap: npm run bootstrap

Build: npm run build

Running the benchmarks: ./scripts/benchmark.js [file...] - defaults to a few packages fetched from unpkg.com and is defined in benchmark.js.

Note: All Input sources are ES5.

Benchmark Results for react.js:

Input Size: 54.79KB

Input Size (gzip): 15.11KB

minifieroutput rawraw wingzip outputgzip winparse time (ms)minify time (ms)
babel-minify15.97KB71%6.08KB60%1.001039.06
terser15.65KB71%5.98KB60%0.93532.19
uglify15.6KB72%6KB60%1.09463.69
closure-compiler15.74KB71%6.04KB60%1.222361.41
closure-compiler-js18.21KB67%6.73KB55%1.083381.47

Benchmark Results for vue.js:

Input Size: 282.52KB

Input Size (gzip): 77.52KB

minifieroutput rawraw wingzip outputgzip winparse time (ms)minify time (ms)
babel-minify104.21KB63%38.71KB50%6.093538.30
terser103.12KB63%37.92KB51%6.421680.85
uglify102.71KB64%38.08KB51%6.591662.50
closure-compiler101.93KB64%38.6KB50%10.414413.06
closure-compiler-js105.18KB63%39.5KB49%6.7912082.80

Benchmark Results for lodash.js:

Input Size: 527.18KB

Input Size (gzip): 94.04KB

minifieroutput rawraw wingzip outputgzip winparse time (ms)minify time (ms)
babel-minify69.59KB87%24.37KB74%5.382587.27
terser68.66KB87%24.31KB74%6.411913.43
uglify68.15KB87%24.05KB74%5.892075.71
closure-compiler71.05KB87%24.19KB74%6.244119.43
closure-compiler-js73.51KB86%24.94KB73%5.179650.59

Benchmark Results for three.js:

Input Size: 1.05MB

Input Size (gzip): 212.43KB

minifieroutput rawraw wingzip outputgzip winparse time (ms)minify time (ms)
babel-minify535.88KB50%134.66KB37%27.249988.57
terser536.16KB50%132.78KB37%28.393919.34
uglify533.42KB50%133.21KB37%26.154025.20
closure-compiler532.44KB51%134.41KB37%29.969029.19
closure-compiler-js543.08KB50%136.3KB36%24.3695743.77

Browser support

Babel Minify is best at targeting latest browsers (with full ES6+ support) but can also be used with the usual Babel es2015 preset to transpile down the code first.

Team

Amjad MasadBoopathi RajaaJuriy ZaytsevHenry ZhuVignesh Shanmugam
Amjad MasadBoopathi RajaaJuriy ZaytsevHenry ZhuVignesh Shanmugam
@amasad@boopathi@kangax@hzoo@vigneshshanmugam
@amasad@heisenbugger@kangax@left_pad@_vigneshh

NPM DownloadsLast 30 Days