CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-minify

Minifier of js, css, html and img files with CLI and programmatic interfaces

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

javascript-minification.mddocs/

JavaScript Minification

Comprehensive JavaScript minification supporting multiple minifiers with configurable options and full async/await support.

Capabilities

JavaScript Minifier Function

Minifies JavaScript source code using the selected minifier backend.

/**
 * Minifies JavaScript source code using configurable minifiers
 * @param source - JavaScript source code to minify
 * @param userOptions - Configuration options for minification
 * @returns Promise resolving to minified JavaScript code
 */
function minify.js(source: string, userOptions?: MinifyOptions): Promise<string>;

interface MinifyOptions {
  js?: {
    type?: 'putout' | 'terser' | 'esbuild' | 'swc';
    putout?: PutoutOptions;
    terser?: TerserOptions;
    esbuild?: ESBuildOptions;
    swc?: SWCOptions;
  };
}

Usage Examples:

import { minify } from "minify";

// Default minification using putout
const code = "function hello(world) {\n    console.log(world);\n}";
const minified = await minify.js(code);
// Result: "function hello(a){console.log(a)}"

// Using terser
const terserResult = await minify.js(code, {
  js: {
    type: 'terser',
    terser: {
      mangle: false
    }
  }
});

// Using esbuild
const esbuildResult = await minify.js(code, {
  js: {
    type: 'esbuild',
    esbuild: {
      minifyWhitespace: true,
      minifyIdentifiers: false
    }
  }
});

// Using swc
const swcResult = await minify.js(code, {
  js: {
    type: 'swc',
    swc: {
      mangle: false,
      module: true
    }
  }
});

Minifier Backends

Putout (Default)

Fast and modern JavaScript minifier with AST-based transformations.

interface PutoutOptions {
  quote?: string;                    // Quote style: "'" or '"'
  mangle?: boolean;                  // Enable variable name mangling
  mangleClassNames?: boolean;        // Enable class name mangling
  removeUnusedVariables?: boolean;   // Remove unused variable declarations
  removeConsole?: boolean;           // Remove console.* calls
  removeUselessSpread?: boolean;     // Remove unnecessary spread operators
}

Usage:

const result = await minify.js(source, {
  js: {
    type: 'putout',
    putout: {
      quote: "'",
      mangle: true,
      removeConsole: true,
      removeUnusedVariables: false
    }
  }
});

Terser

Industry-standard JavaScript minifier with extensive configuration options.

interface TerserOptions {
  mangle?: boolean | object;         // Variable name mangling options
  compress?: boolean | object;       // Code compression options
  format?: object;                   // Output formatting options
  sourceMap?: boolean | object;      // Source map generation
  ecma?: number;                     // ECMAScript version target
  keep_fnames?: boolean;             // Preserve function names
  toplevel?: boolean;                // Mangle top-level variables
}

Usage:

const result = await minify.js(source, {
  js: {
    type: 'terser',
    terser: {
      mangle: {
        toplevel: true
      },
      compress: {
        drop_console: true,
        drop_debugger: true
      }
    }
  }
});

ESBuild

Ultra-fast Go-based JavaScript minifier and bundler.

interface ESBuildOptions {
  minifyWhitespace?: boolean;        // Remove unnecessary whitespace
  minifyIdentifiers?: boolean;       // Shorten variable names
  minifySyntax?: boolean;           // Use shorter syntax when possible
  target?: string[];                // Target environments
  format?: 'iife' | 'cjs' | 'esm'; // Output format
  platform?: 'browser' | 'node';   // Target platform
}

Usage:

const result = await minify.js(source, {
  js: {
    type: 'esbuild',
    esbuild: {
      minifyWhitespace: true,
      minifyIdentifiers: true,
      minifySyntax: true,
      target: ['es2020']
    }
  }
});

SWC

Rust-based JavaScript minifier with high performance and modern features.

interface SWCOptions {
  mangle?: boolean | object;         // Variable name mangling
  compress?: boolean | object;       // Code compression settings
  module?: boolean;                  // Enable module mode
  toplevel?: boolean;                // Mangle top-level scope
  keep_fnames?: boolean;             // Preserve function names
  safari10?: boolean;                // Safari 10 compatibility
}

Usage:

const result = await minify.js(source, {
  js: {
    type: 'swc',
    swc: {
      mangle: true,
      module: true,
      compress: {
        unused: true
      }
    }
  }
});

Error Handling

JavaScript minification handles various error conditions:

  • Invalid Syntax: Syntax errors in source code are propagated from minifiers
  • Missing Source: Throws assertion error if source parameter is empty
  • Minifier Errors: Backend-specific errors are passed through with context
  • Type Validation: Validates minifier type selection and options structure

Error Examples:

// Empty source validation
try {
  await minify.js("");
} catch (error) {
  console.log(error); // AssertionError
}

// Invalid minifier type
try {
  await minify.js(code, { js: { type: 'invalid' } });
} catch (error) {
  console.log(error.message); // Minifier error
}

docs

auto-detection.md

cli-interface.md

configuration.md

css-minification.md

html-minification.md

image-processing.md

index.md

javascript-minification.md

tile.json