terser
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
@jridgewell/source-map | 0.3.6 | 173.21 kB | MIT | prod | |
acorn | 8.11.3 | 122.89 kB | MIT | prod | |
commander | 2.20.3 | 18.26 kB | MIT | prod | |
source-map-support | 0.5.21 | 26.03 kB | MIT | prod |
Terser is a JavaScript parser, mangler, compressor, and beautifier toolkit targeting ECMAScript 6 and beyond. It works to reduce the size of your JavaScript files by removing redundant or irrelevant data without affecting its functioning. This process is known as compacting or minifying. Terser mangles and compresses your files to remove spaces, indentation, newlines, and comments. In addition, it shortens the names of your variables and parameters to single-letters. Terser is essentially a fork of uglify-es
that retains API and CLI compatibility with uglify-es
and uglify-js@3
.
You can use Terser via the command line or programmatically in your application.
To install it for command-line usage, you should run the following command:
npm install terser -g
For programmatic usage within your application, the recommended installation command is:
npm install terser
In your JavaScript code, you can then import Terser and use the minify
function to reduce your code size. For instance:
const { minify } = require("terser");
async function run() {
let code = "function add(first, second) { return first + second; }";
let result = await minify(code);
console.log(result.code); // minified output
}
run();
Please note that the minify
function is asynchronous and must be awaited or chained with .then()
and .catch()
.
The Terser documentation can be found in the README file on its GitHub repository at https://github.com/terser/terser
. The available options and API for using Terser are outlined and explained in detail in the README. A link to each section detailing how to use the various options and configurations available in Terser can be found in the Table of Contents.