BABEL-MINIFY(1)

πŸ“¦
version 0.5.2 Β· 3 versions
, in debian bookworm, debian trixie, ubuntu noble

πŸ’– NAME πŸ’–

babel-minify β€” an ES6+ aware minifier based on the Babel toolchain ✨

okay bestie, listen. this is the manual page for babel-minify(1), from the User Commands girlies. she minifies your code and she's very ES6+ aware. periodt.


🌸 DESCRIPTION 🌸

so the whole vibe is this:

Usage: minify index.js [options]

you point her at a file, she makes it tiny. iconic. now let's get into every single knob and dial, because there are a LOT and we are NOT skipping any πŸ’…


πŸŽ€ IO Options πŸŽ€

where the output actually goes, bestie.

  • --out-file, -o β€” writes the output to one specific file you picked 🫢
  • --out-dir, -d β€” writes the output into one specific directory instead πŸ“

πŸ¦‹ Parser/Generator options πŸ¦‹

this is the "how do we even read your code" part.

  • --sourceType β€” tells her what mode the code should be parsed in. the valid options are "script" | "module" | "unambiguous" β€” those are the only ones, no cap.
  • --comments β€” turns comments in the output on or off. and if you want something more specific than on/off, she says use the Node API instead ✨

πŸ’œ Transform Options πŸ’œ

the actual glow-up section. every single one:

  • --mangle β€” context and scope aware variable renaming. she knows what she's doing πŸ”₯
  • --simplify β€” simplifies code for minification by reducing statements into expressions
  • --booleans β€” transforms boolean literals into !0 for true and !1 for false
  • --builtIns β€” minify standard built-in objects
  • --consecutiveAdds β€” inlines consecutive property assignments, array pushes, etc.
  • --deadcode β€” inlines bindings and tries to evaluate expressions.
  • --evaluate β€” tries to evaluate expressions and inline the result. deals with numbers and strings πŸ”’
  • --flipComparisons β€” optimize code for repetition-based compression algorithms such as gzip
  • --infinity β€” minify Infinity to 1/0
  • --memberExpressions β€” convert valid member expression property literals into plain identifiers
  • --mergeVars β€” merge sibling variables into single variable declaration
  • --numericLiterals β€” shortening of numeric literals via scientific notation
  • --propertyLiterals β€” transform valid identifier property key literals into identifiers
  • --regexpConstructors β€” change RegExp constructors into literals
  • --removeConsole β€” removes all console.* calls πŸ™ˆ
  • --removeDebugger β€” removes all debugger statements
  • --removeUndefined β€” removes rval's for variable assignments, return arguments from functions that evaluate to undefined
  • --replace β€” replaces matching nodes in the tree with a given replacement node
  • --simplifyComparisons β€” convert === and !== to == and != if their types are inferred to be the same
  • --typeConstructors β€” minify constructors to equivalent version
  • --undefinedToVoid β€” transforms undefined into void 0

⭐ Other Options ⭐

the "please don't break my code" collection.

  • --keepFnName β€” preserve Function Name (useful for code depending on fn.name)
  • --keepClassName β€” preserve Class Name (useful for code depending on c.name)
  • --keepFnArgs β€” don't remove unused fn arguments (useful for code depending on fn.length)
  • --tdz β€” Detect usages of variables in the Temporal Dead Zone πŸ‘‘

🧚 Nested Options 🧚

okay this one's lowkey the coolest part. if you wanna use nested options (that's plugin specific options, iykyk), you just use this pattern:

--pluginName.featureName

like, for example:

minify index.js --mangle.keepClassName --deadcode.keepFnArgs --outFile index.min.js

see how --mangle.keepClassName and --deadcode.keepFnArgs just stack up like that? chef's kiss πŸ’…βœ¨

just a heads up bestie: that example literally says --outFile in it, so write it exactly like that when you're copying her. don't come for me, i'm just the messenger 🫢

πŸ’– SEE ALSO πŸ’–

<nope, no see also section in the original>


that's the whole page, bestie!! go forth and minify. this was babel-minify 0.5.2, from November 2022, and yes she still eats. mwah πŸ’‹ πŸŽ€πŸ¦‹πŸŒΈ

πŸ“¦ where this page comes from