{"id":19321,"library":"babel-preset-optimizations","title":"babel-preset-optimizations","description":"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.","status":"active","version":"2.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/christophehurpeau/babel-preset-optimizations","tags":["javascript","babel-preset","typescript"],"install":[{"cmd":"npm install babel-preset-optimizations","lang":"bash","label":"npm"},{"cmd":"yarn add babel-preset-optimizations","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-preset-optimizations","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"core optimisation plugin for constant folding","package":"babel-plugin-minify-constant-folding","optional":false},{"reason":"core optimisation plugin for dead code elimination","package":"babel-plugin-minify-dead-code-elimination","optional":false},{"reason":"core optimisation plugin for guarded expressions","package":"babel-plugin-minify-guarded-expressions","optional":false},{"reason":"optional plugin for code simplification","package":"babel-plugin-minify-simplify","optional":true},{"reason":"core optimisation plugin for inlining consecutive additions","package":"babel-plugin-transform-inline-consecutive-adds","optional":false},{"reason":"optional plugin for transforming undefined to void","package":"babel-plugin-transform-undefined-to-void","optional":true}],"imports":[{"note":"It is a preset, not a plugin. Use in presets array with short name 'optimizations'.","wrong":"require('babel-preset-optimizations') as a plugin","symbol":"babel-preset-optimizations","correct":"module.exports = { presets: ['optimizations'] }; or in .babelrc: { \"presets\": [\"optimizations\"] }"},{"note":"Options must be in a nested array: [ [\"presetName\", options] ].","wrong":"{\"presets\": [\"optimizations\", { \"keepFnName\": false }]}","symbol":"options object","correct":"{\"presets\": [[\"optimizations\", { \"keepFnName\": false }]]}"},{"note":"The package exports the preset function directly; no default export needed.","wrong":"const preset = require('babel-preset-optimizations').default;","symbol":"require() in Node API","correct":"const preset = require('babel-preset-optimizations');"}],"quickstart":{"code":"// .babelrc or babel.config.js\nmodule.exports = {\n  presets: [\n    ['optimizations', {\n      keepFnName: true,\n      keepClassName: true,\n      simplify: false,\n      undefinedToVoid: false\n    }]\n  ]\n};","lang":"javascript","description":"Shows how to enable the preset with default options in a Babel configuration file."},"warnings":[{"fix":"Add 'minify' or another minification preset/plugin after this one.","message":"This preset does not minify or mangle code; it only applies optimisations. Use alongside a minifier like babel-minify or terser.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Only enable simplify in production builds with source maps, or avoid it.","message":"The simplify option changes code structure significantly and may be considered harmful for debugging.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Use [[\"optimizations\", { options }]] instead of [\"optimizations\", { options }].","message":"Options must be passed in the nested array format for presets, not as a flat array.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Upgrade Node to >=10.13.0 or stick with v1.x.","message":"Version 2.0.0 drops support for Node <10.13.0.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Use 'babel-preset-optimizations' instead of 'optimizations' if short name fails.","message":"In Babel 7, preset short names may not resolve automatically; you might need the full package name.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Ensure Babel is version 7 and use the correct preset reference: 'babel-preset-optimizations' or short name 'optimizations'.","cause":"Using an outdated Babel version or wrong import syntax for the preset.","error":"Error: Plugin/Preset files are not allowed to export objects, only functions."},{"fix":"Run 'npm install --save-dev babel-preset-optimizations' and check node_modules.","cause":"Package not installed or not properly resolved.","error":"Module not found: Can't resolve 'babel-preset-optimizations'"},{"fix":"Use [['optimizations', { keepFnName: true }]] instead of ['optimizations', { keepFnName: true }].","cause":"Options object passed incorrectly – not wrapped in an array.","error":"Unknown option: keepFnName"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}