Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
babel-plugin-minify-mangle-names
Advanced tools
Context- and scope- aware variable renaming.
The babel-plugin-minify-mangle-names package is a Babel plugin that minifies JavaScript code by mangling variable and function names. This helps reduce the size of the output file, which can improve load times and performance for web applications.
Mangle Variable Names
This feature renames variables and function names to shorter versions, reducing the overall size of the code.
const babel = require('@babel/core');
const code = 'function add(a, b) { return a + b; }';
const output = babel.transformSync(code, { plugins: ['babel-plugin-minify-mangle-names'] });
console.log(output.code); // Output: function a(a,b){return a+b}
Mangle Function Names
This feature renames function names to shorter versions, which helps in reducing the size of the code.
const babel = require('@babel/core');
const code = 'function multiply(x, y) { return x * y; }';
const output = babel.transformSync(code, { plugins: ['babel-plugin-minify-mangle-names'] });
console.log(output.code); // Output: function a(a,b){return a*b}
UglifyJS is a JavaScript parser, minifier, compressor, and beautifier toolkit. It provides more comprehensive minification options compared to babel-plugin-minify-mangle-names, including dead code removal and advanced optimizations.
Terser is a JavaScript parser and mangler/compressor toolkit for ES6+. It is a fork of UglifyJS and offers similar functionalities with better support for modern JavaScript syntax. Terser is often used in build tools like Webpack for minifying JavaScript code.
Babel Minify is a Babel plugin that minifies JavaScript code. It includes a variety of minification plugins, including babel-plugin-minify-mangle-names. It provides a more integrated solution for Babel users who want to minify their code as part of the Babel transformation process.
Context- and scope- aware variable renaming.
In
var globalVariableName = 42;
function foo() {
var longLocalVariableName = 1;
if (longLocalVariableName) {
console.log(longLocalVariableName);
}
}
Out
var globalVariableName = 42;
function foo() {
var a = 1;
if (a) {
console.log(a);
}
}
npm install babel-plugin-minify-mangle-names --save-dev
.babelrc
(Recommended).babelrc
// without options
{
"plugins": ["minify-mangle-names"]
}
// with options
{
"plugins": [
["minify-mangle-names", { "exclude": { "foo": true, "bar": true} }]
]
}
babel --plugins minify-mangle-names script.js
require("@babel/core").transform("code", {
plugins: ["minify-mangle-names"]
});
exclude
- A plain JS Object with keys as identifier names and values indicating whether to exclude (default: {}
)eval
- mangle identifiers in scopes accessible by eval (default: false
)keepFnName
- prevent mangler from altering function names. Useful for code depending on fn.name
(default: false
)topLevel
- mangle topLevel Identifiers (default: false
)keepClassName
- prevent mangler from altering class names (default: false
).FAQs
Context- and scope- aware variable renaming.
The npm package babel-plugin-minify-mangle-names receives a total of 269,970 weekly downloads. As such, babel-plugin-minify-mangle-names popularity was classified as popular.
We found that babel-plugin-minify-mangle-names demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.