Registry / devops / babel-preset-optimizations

babel-preset-optimizations

JSON →
library2.0.0jsnpmunverified

Babel preset that bundles babel-minify optimisation plugins for production builds. Version 2.0.0 requires Node >=10.13.0 and ships TypeScript types. It includes plugins for constant folding, dead code elimination, guarded expressions, inline consecutive adds, undefined-to-void, and optionally simplify. Unlike full minifiers, it focuses solely on optimisations without mangling or compression, giving finer control over the output. Options allow preserving function/class names and enabling simplify or undefined-to-void transforms. It is best used alongside a separate minification step.

npm install babel-preset-optimizations
INSTALL
IMPORT
SIG · BABEL-PRESET-OPTIM
B
babel-preset-optimizations
devopsjavascriptv2.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

babel-preset-optimizations
module.exports = { presets: ['optimizations'] }; or in .babelrc: { "presets": ["optimizations"] }
require('babel-preset-optimizations') as a plugin
It is a preset, not a plugin. Use in presets array with short name 'optimizations'.
options object
{"presets": [["optimizations", { "keepFnName": false }]]}
{"presets": ["optimizations", { "keepFnName": false }]}
Options must be in a nested array: [ ["presetName", options] ].
require() in Node API
const preset = require('babel-preset-optimizations');
const preset = require('babel-preset-optimizations').default;
The package exports the preset function directly; no default export needed.

Shows how to enable the preset with default options in a Babel configuration file.

// .babelrc or babel.config.js module.exports = { presets: [ ['optimizations', { keepFnName: true, keepClassName: true, simplify: false, undefinedToVoid: false }] ] };
Debug
Known issues
gotchaThis preset does not minify or mangle code; it only applies optimisations. Use alongside a minifier like babel-minify or terser.
fix
Add 'minify' or another minification preset/plugin after this one.
affects: >=1.0.0
deprecatedThe simplify option changes code structure significantly and may be considered harmful for debugging.
fix
Only enable simplify in production builds with source maps, or avoid it.
affects: >=1.0.0
gotchaOptions must be passed in the nested array format for presets, not as a flat array.
fix
Use [["optimizations", { options }]] instead of ["optimizations", { options }].
affects: >=1.0.0
breakingVersion 2.0.0 drops support for Node <10.13.0.
fix
Upgrade Node to >=10.13.0 or stick with v1.x.
affects: >=2.0.0
gotchaIn Babel 7, preset short names may not resolve automatically; you might need the full package name.
fix
Use 'babel-preset-optimizations' instead of 'optimizations' if short name fails.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Plugin/Preset files are not allowed to export objects, only functions.
Using an outdated Babel version or wrong import syntax for the preset.
fix
Ensure Babel is version 7 and use the correct preset reference: 'babel-preset-optimizations' or short name 'optimizations'.
Module not found: Can't resolve 'babel-preset-optimizations'
Package not installed or not properly resolved.
fix
Run 'npm install --save-dev babel-preset-optimizations' and check node_modules.
Unknown option: keepFnName
Options object passed incorrectly – not wrapped in an array.
fix
Use [['optimizations', { keepFnName: true }]] instead of ['optimizations', { keepFnName: true }].
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies
babel-plugin-minify-constant-foldingrequiredcore optimisation plugin for constant folding
babel-plugin-minify-dead-code-eliminationrequiredcore optimisation plugin for dead code elimination
babel-plugin-minify-guarded-expressionsrequiredcore optimisation plugin for guarded expressions
babel-plugin-minify-simplifyoptionaloptional plugin for code simplification
babel-plugin-transform-inline-consecutive-addsrequiredcore optimisation plugin for inlining consecutive additions
babel-plugin-transform-undefined-to-voidoptionaloptional plugin for transforming undefined to void
Agent activity
4 hits · last 30 days
node
4
Resources
babel-preset-optimizations — npm install babel-preset-optimizations · libregistry