babel-plugin-minify-type-constructors
raw JSON → 0.4.3 verified Sat Apr 25 auth: no javascript maintenance
A Babel plugin that minifies type constructors like Boolean(), Number(), String(), Array(), and Object() where possible (e.g., replacing `new Boolean(x)` with `!!x` or `new Number(x)` with `+x`). Part of the babel-minify (formerly babili) minification preset. Version 0.4.3 is the latest stable release (2018). The babel-minify project is now in maintenance mode; no new features are expected. This plugin should be used with caution in environments requiring IE8 or lower due to potential compatibility issues. It is designed to work as part of a Babel minification pipeline, complementing other minify plugins.
Common errors
error Error: Cannot find module 'babel-plugin-minify-type-constructors' ↓
cause Package not installed or missing in node_modules.
fix
npm install babel-plugin-minify-type-constructors --save-dev
error ReferenceError: Boolean is not defined (or similar) in transformed code ↓
cause Plugin transforms `new Boolean(x)` to `!!x`, which may not be equivalent in all edge cases (e.g., `new Boolean(false)` is truthy).
fix
Review transformed code and possibly disable plugin for sensitive cases.
Warnings
breaking Not recommended for full IE8 and lower support due to potential issues with object wrappers. ↓
fix Use only in modern environments or apply polyfills.
deprecated The babel-minify project is no longer actively maintained. Prefer babel-preset-minify or community alternatives. ↓
fix Migrate to babel-preset-minify (which includes this plugin) or other minifiers.
gotcha Potential breaking due to missing dependencies in babel-minify@0.5.0 and 0.5.1. ↓
fix Use version 0.4.3 or upgrade to a later patch if available.
Install
npm install babel-plugin-minify-type-constructors yarn add babel-plugin-minify-type-constructors pnpm add babel-plugin-minify-type-constructors Imports
- default
module.exports = require('babel-plugin-minify-type-constructors'); - default
import minifyTypeConstructors from 'babel-plugin-minify-type-constructors'; - default wrong
plugins: ['minify-type-constructors']correctplugins: ['babel-plugin-minify-type-constructors']
Quickstart
// babel.config.js
module.exports = {
plugins: [
'babel-plugin-minify-type-constructors'
]
};
// Input: var a = new Boolean(true); var b = new String('hello');
// Output: var a = !!true; var b = 'hello';