Babel plugin that statically evaluates calls to clsx, classnames, or compatible APIs, replacing them with optimized inline expressions. Current stable version is 2.6.2, releasing with minor fixes against clsx/classnames ecosystem shifts. Differentiators: works with any library following the (strings, objects, arrays) signature, handles conditional spreads, and supports JSX. Replaces runtime calls with simpler ternary or concatenation, reducing bundle size. Plug into Babel transforms for production builds.
npm install babel-plugin-optimize-clsxVerified import paths — ran on the pinned version, not inferred.
Basic Babel configuration and a sample transform showing clsx call optimization with conditional nesting.
Update config to specify library names explicitly if using classnames etc.
Ensure conditional expressions and object spreads use literal or simple identifiers.
Use the exact package name in 'libraries' array. For re-exports, use 'resolveModuleName' option.
npm install babel-plugin-optimize-clsx --save-dev
Ensure @babel/core version 7+ is installed.
Update to >=2.0.0 for correct handling.