Security News
New Python Packaging Proposal Aims to Solve Phantom Dependency Problem with SBOMs
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
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
.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.
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
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
Security News
Socket CEO Feross Aboukhadijeh discusses open source security challenges, including zero-day attacks and supply chain risks, on the Cyber Security Council podcast.
Security News
Research
Socket researchers uncover how threat actors weaponize Out-of-Band Application Security Testing (OAST) techniques across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.