CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-terser

JavaScript parser, mangler/compressor and beautifier toolkit for ES6+

Pending
Overview
Eval results
Files

configuration.mddocs/

Configuration

Comprehensive configuration system providing fine-grained control over parsing, compression, mangling, and output formatting with extensive option categories and intelligent defaults.

Capabilities

Minify Options Interface

Main configuration interface that controls all aspects of the minification process.

interface MinifyOptions {
  /** Enable/configure code compression and optimization */
  compress?: boolean | CompressOptions;
  /** ECMAScript target version for parsing and output */
  ecma?: ECMA;
  /** Wrap code in anonymous function with configurable parameters */
  enclose?: boolean | string;
  /** Support for Internet Explorer 8 compatibility */
  ie8?: boolean;
  /** Preserve class names during mangling */
  keep_classnames?: boolean | RegExp;
  /** Preserve function names during mangling */
  keep_fnames?: boolean | RegExp;
  /** Enable/configure variable and function name mangling */
  mangle?: boolean | MangleOptions;
  /** Treat input as ES6 module */
  module?: boolean;
  /** Cache object for preserving mangled names across multiple runs */
  nameCache?: object;
  /** Configure output code formatting */
  format?: FormatOptions;
  /** @deprecated Use format instead */
  output?: FormatOptions;
  /** Configure JavaScript parsing behavior */
  parse?: ParseOptions;
  /** Support for Safari 10 compatibility */
  safari10?: boolean;
  /** Enable/configure source map generation */
  sourceMap?: boolean | SourceMapOptions;
  /** Process variables in top-level scope */
  toplevel?: boolean;
}

Parse Options

Controls JavaScript parsing behavior and syntax support.

interface ParseOptions {
  /** Allow return statements outside functions */
  bare_returns?: boolean;
  /** @deprecated ECMAScript version (all supported versions are valid) */
  ecma?: ECMA;
  /** Support HTML5-style comments */
  html5_comments?: boolean;
  /** Preserve Unix shebang lines */
  shebang?: boolean;
}

Usage Examples:

const parseOptions: ParseOptions = {
  bare_returns: true,  // For CommonJS modules
  html5_comments: true,  // Support <!-- comments -->
  shebang: true  // Preserve #!/usr/bin/env node
};

await minify(code, { parse: parseOptions });

Compression Options

Extensive optimization configuration with 75+ individual settings for dead code elimination, constant folding, and advanced transformations.

interface CompressOptions {
  /** Optimize function arguments */
  arguments?: boolean;
  /** Convert function expressions to arrow functions */
  arrows?: boolean;
  /** Represent booleans as integers */
  booleans_as_integers?: boolean;
  /** Optimize boolean expressions */
  booleans?: boolean;
  /** Collapse single-use variables */
  collapse_vars?: boolean;
  /** Optimize comparison operations */
  comparisons?: boolean;
  /** Optimize computed property access */
  computed_props?: boolean;
  /** Optimize conditional expressions */
  conditionals?: boolean;
  /** Remove unreachable code */
  dead_code?: boolean;
  /** Apply default optimizations */
  defaults?: boolean;
  /** Process directive prologues */
  directives?: boolean;
  /** Remove console.* calls */
  drop_console?: boolean | ConsoleProperty[];
  /** Remove debugger statements */
  drop_debugger?: boolean;
  /** Target ECMAScript version */
  ecma?: ECMA;
  /** Evaluate constant expressions */
  evaluate?: boolean;
  /** Parse input as single expression */
  expression?: boolean;
  /** Define global constants */
  global_defs?: object;
  /** Hoist function declarations */
  hoist_funs?: boolean;
  /** Hoist property assignments */
  hoist_props?: boolean;
  /** Hoist var declarations */
  hoist_vars?: boolean;
  /** Support IE8 compatibility */
  ie8?: boolean;
  /** Optimize return statements in if blocks */
  if_return?: boolean;
  /** Inline function calls */
  inline?: boolean | InlineFunctions;
  /** Join consecutive var statements */
  join_vars?: boolean;
  /** Preserve class names */
  keep_classnames?: boolean | RegExp;
  /** Preserve function arguments in unused functions */
  keep_fargs?: boolean;
  /** Preserve function names */
  keep_fnames?: boolean | RegExp;
  /** Keep Infinity literal */
  keep_infinity?: boolean;
  /** Optimize left-hand side constants */
  lhs_constants?: boolean;
  /** Optimize loop structures */
  loops?: boolean;
  /** Treat input as module */
  module?: boolean;
  /** Negate immediately invoked function expressions */
  negate_iife?: boolean;
  /** Number of compression passes */
  passes?: number;
  /** Optimize property access */
  properties?: boolean;
  /** Functions safe to remove when return value unused */
  pure_funcs?: string[];
  /** Constructors safe to remove when return value unused */
  pure_new?: boolean;
  /** Property getters with no side effects */
  pure_getters?: boolean | 'strict';
  /** Inline and remove function declarations */
  reduce_funcs?: boolean;
  /** Optimize variable assignments and usage */
  reduce_vars?: boolean;
  /** Join consecutive statements with comma operator */
  sequences?: boolean | number;
  /** Drop side-effect-free statements */
  side_effects?: boolean;
  /** Optimize switch statements */
  switches?: boolean;
  /** Process top-level scope */
  toplevel?: boolean;
  /** Names to preserve in top-level scope */
  top_retain?: null | string | string[] | RegExp;
  /** Optimize typeof expressions */
  typeofs?: boolean;
  /** Convert functions to arrow functions (unsafe) */
  unsafe_arrows?: boolean;
  /** Enable unsafe optimizations */
  unsafe?: boolean;
  /** Unsafe comparison optimizations */
  unsafe_comps?: boolean;
  /** Optimize Function constructor calls */
  unsafe_Function?: boolean;
  /** Optimize Math.* calls */
  unsafe_math?: boolean;
  /** Optimize symbol operations */
  unsafe_symbols?: boolean;
  /** Optimize method calls */
  unsafe_methods?: boolean;
  /** Optimize prototype operations */
  unsafe_proto?: boolean;
  /** Optimize regular expression literals */
  unsafe_regexp?: boolean;
  /** Optimize undefined comparisons */
  unsafe_undefined?: boolean;
  /** Remove unused variables and functions */
  unused?: boolean;
}

Compression

Name Mangling

Variable, function, and property name obfuscation system with customizable identifier generation and preservation rules.

interface MangleOptions {
  /** Mangle names in eval scope */
  eval?: boolean;
  /** Preserve class names */
  keep_classnames?: boolean | RegExp;
  /** Preserve function names */
  keep_fnames?: boolean | RegExp;
  /** Treat input as module */
  module?: boolean;
  /** Custom identifier generation algorithm */
  nth_identifier?: SimpleIdentifierMangler | WeightedIdentifierMangler;
  /** Enable/configure property name mangling */
  properties?: boolean | ManglePropertiesOptions;
  /** Names to exclude from mangling */
  reserved?: string[];
  /** Safari 10 compatibility mode */
  safari10?: boolean;
  /** Process top-level scope */
  toplevel?: boolean;
}

Name Mangling

Output Formatting

Code generation and formatting configuration controlling whitespace, comments, quotes, and structural formatting.

interface FormatOptions {
  /** Use ASCII-only output */
  ascii_only?: boolean;
  /** @deprecated Not implemented */
  beautify?: boolean;
  /** Always use braces for control structures */
  braces?: boolean;
  /** Comment preservation configuration */
  comments?: boolean | 'all' | 'some' | RegExp | ((node: any, comment: CommentObject) => boolean);
  /** Target ECMAScript version */
  ecma?: ECMA;
  /** IE8 compatibility mode */
  ie8?: boolean;
  /** Preserve numeric literals */
  keep_numbers?: boolean;
  /** Indentation level */
  indent_level?: number;
  /** Starting indentation */
  indent_start?: number;
  /** Inline script tag compatibility */
  inline_script?: boolean;
  /** Keep quoted property names */
  keep_quoted_props?: boolean;
  /** Maximum line length */
  max_line_len?: number | false;
  /** Code preamble */
  preamble?: string;
  /** Preserve type annotations */
  preserve_annotations?: boolean;
  /** Quote all property keys */
  quote_keys?: boolean;
  /** Quote style preference */
  quote_style?: OutputQuoteStyle;
  /** Safari 10 compatibility */
  safari10?: boolean;
  /** Use semicolons */
  semicolons?: boolean;
  /** Preserve shebang */
  shebang?: boolean;
  /** Use shorthand properties */
  shorthand?: boolean;
  /** Source map configuration */
  source_map?: SourceMapOptions;
  /** WebKit compatibility mode */
  webkit?: boolean;
  /** Output width for beautification */
  width?: number;
  /** Wrap IIFEs in parentheses */
  wrap_iife?: boolean;
  /** Wrap function arguments in parentheses */
  wrap_func_args?: boolean;
}

interface CommentObject {
  value: string;
  type: 'comment1' | 'comment2' | 'comment3' | 'comment4';
  pos: number;
  line: number;
  col: number;
}

Output Formatting

Types

interface MinifyOutput {
  /** The minified JavaScript code */
  code?: string;
  /** Source map as JSON string */
  map?: string;
  /** Decoded source map object for programmatic access */
  decoded_map?: object | null;
  /** Performance timing information (when timings: true) */
  timings?: {
    parse: number;
    rename: number;
    compress: number;
    scope: number;
    mangle: number;
    properties: number;
    format: number;
    total: number;
  };
}

type ECMA = 5 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020;

type ConsoleProperty = keyof typeof console;
type DropConsoleOption = boolean | ConsoleProperty[];

enum InlineFunctions {
  Disabled = 0,
  SimpleFunctions = 1,
  WithArguments = 2,
  WithArgumentsAndVariables = 3
}

enum OutputQuoteStyle {
  PreferDouble = 0,
  AlwaysSingle = 1,
  AlwaysDouble = 2,
  AlwaysOriginal = 3
}

Install with Tessl CLI

npx tessl i tessl/npm-terser

docs

advanced.md

cli.md

compression.md

configuration.md

formatting.md

index.md

mangling.md

minification.md

tile.json