An ES6+ aware minifier based on the Babel toolchain.
babel-minify is consumable via API, CLI, or Babel preset. Try it online - babeljs.io/replHistorical note: babel-minify was renamed from babili.
babel-minify is an experimental project that attempts to use Babel's toolchain (for compilation) to do something in a similar vein, minification. It's currently in 0.x, so we don't recommend using it in production.
Checkout our CONTRIBUTING.md if you want to help out!
Current tools don't support targeting the latest version of ECMAScript. (yet) - BabelMinify can because it is just a set of Babel plugins, and Babel already understands new syntax with our parser Babylon. - When it's possible to only target browsers that support newer ES features, code sizes can be smaller because you don't have to transpile and then minify.
Check out our blog post for more info!
// Example ES2015 Code
class Mangler {
constructor(program) {
this.program = program;
}
}
new Mangler(); // without this it would just output nothing since Mangler isn't used
Before
// ES2015+ code -> Babel -> BabelMinify/Uglify -> Minified ES5 Code
var a=function a(b){_classCallCheck(this,a),this.program=b};new a;
After
// ES2015+ code -> BabelMinify -> Minified ES2015+ Code
class a{constructor(b){this.program=b}}new a;
| Package | Version | Dependencies |
|---|---|---|
babel-minify |
npm install babel-minify --save-dev
minify src -d lib
| Package | Version | Dependencies |
|---|---|---|
babel-preset-minify |
npm install babel-preset-minify --save-dev
note: minify is still in beta, so we don't recommend using it for production code but rather the production environment.
When testing, it's recommended to run minifiers for production so less code is sent to end-users vs. in development where it can be an issue for readability when debugging. Check out the env docs for more help.
Options specific to a certain environment are merged into and overwrite non-env specific options.
.babelrc:
{
"presets": ["es2015"],
"env": {
"production": {
"presets": ["minify"]
}
}
}
Then you'll need to set the env variable which could be something like BABEL_ENV=production npm run build
The minify repo is comprised of many npm packages. It is a lerna monorepo similar to babel itself.
The npm package babel-preset-minify is at the path packages/babel-preset-minify
Normally you wouldn't be consuming the plugins directly since the preset is available.
Add to your .babelrc's plugins array.
{
"plugins": ["babel-plugin-transform-undefined-to-void"]
}
| Package | Version | Dependencies |
|---|---|---|
babel-plugin-transform-inline-environment-variables |
||
babel-plugin-transform-node-env-inline |
||
babel-plugin-transform-remove-console |
[![npm](https://img.shields.io/npm/v/babel-plugin-trans |
$ claude mcp add minify \
-- python -m otcore.mcp_server <graph>