Minifier of js, css, html and img files with CLI and programmatic interfaces
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Comprehensive JavaScript minification supporting multiple minifiers with configurable options and full async/await support.
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
}
}
});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
}
}
});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
}
}
}
});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']
}
}
});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
}
}
}
});JavaScript minification handles various error conditions:
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
}