Registry / devops / better-minify-js-node

better-minify-js-node

JSON →
library0.7.0jsnpmunverified

Extremely fast JavaScript minifier written in Rust, with Node.js bindings. Current stable version is 0.7.0. This is a fork of the unmaintained minify-js package, aiming to provide maximum performance on a single CPU core using SIMD instructions and a bump allocation arena. It supports JSX, scope analysis, identifier minification, and various AST transformations (e.g., converting if statements to expressions, transforming functions to arrow functions). Unlike UglifyJS or Terser, it focuses on raw speed and simplicity over configurability or bundling; it does not offer extensive options or plugin systems. Release cadence is irregular; the package ships TypeScript type definitions, so no separate @types package is needed.

npm install better-minify-js-node
INSTALL
IMPORT
SIG · BETTER-MINIFY-JS-N
B
better-minify-js-node
devopsjavascriptv0.7.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

minify
import { minify } from 'better-minify-js-node'
const minify = require('better-minify-js-node')
Package ships TypeScript types but the import is the same for both ESM and CJS. Using require will work but may lose types.
minify (default import)
import minify from 'better-minify-js-node'
import { minify as defaultMinify } from 'better-minify-js-node'
Since v0.7.0, a default export is also provided as an alias to the named `minify`. Use whichever style you prefer.
MinifyOptions
import type { MinifyOptions } from 'better-minify-js-node'
import { MinifyOptions } from 'better-minify-js-node'
Options type is not exported as a value; use `import type` for correct TypeScript usage.

Reads a JavaScript file, minifies it using better-minify-js-node, and writes the minified output to a new file.

import { minify } from 'better-minify-js-node'; import { readFileSync, writeFileSync } from 'fs'; const code = readFileSync('input.js', 'utf-8'); const buffer = Buffer.from(code, 'utf-8'); try { const minifiedBuffer = minify(buffer); writeFileSync('output.min.js', minifiedBuffer); console.log('Minification successful!'); } catch (err) { console.error('Minification failed:', err); }
Debug
Known issues
breakingInput must be a Buffer; passing a string will throw a TypeError.
fix
Wrap your string in Buffer.from(input, 'utf-8') before passing to minify().
affects: >=0.7.0
deprecatedThe 'module' mode argument has been removed; the API now always assumes global mode.
fix
Simply call minify(buffer) without a second argument.
affects: >=0.7.0
gotchaMinifier does not preserve comments; all comments are stripped.
fix
Remove comments from input if needed, or use an alternative if you must retain comments.
affects: >=0.1.0
gotchaJSX support is experimental and may not handle all edge cases.
fix
Test your JSX input thoroughly; consider disabling JSX minification if errors occur.
affects: >=0.5.0
deprecatedThe package previously exported 'minifySync' as a named export; it is now an alias for 'minify' and will be removed in a future version.
fix
Replace 'minifySync' with 'minify'.
affects: >=0.6.0
Errors
Common errors & fixes
TypeError: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined
Calling minify() without arguments or with undefined.
fix
Ensure you pass a Buffer: const buffer = Buffer.from(code, 'utf-8');
Error: minify: Could not parse: Unexpected token
Input contains syntax errors or unsupported syntax (e.g., TypeScript).
fix
Validate your JavaScript code or remove TypeScript syntax. The minifier only supports standard JS and JSX.
TypeError: buffer.toString is not a function
Forgetting to convert string to Buffer before passing to minify().
fix
Convert string to buffer: const buffer = Buffer.from(code, 'utf-8');
Upgrade
Version history
0.7.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Resources