A Babel plugin that automatically removes unused variables, imports, function arguments, and destructured bindings from JavaScript code, acting as a Babel-based autofix for ESLint's no-unused-vars rule. As of version 2.2.0, it supports source-to-source transformations and is intended for use as a build tool to clean up code. The plugin runs via Babel CLI or programmatically and handles common cases but has known limitations with deep assignment expressions. It is released under the MIT license with moderate maintenance cadence on GitHub, positioned as a more aggressive alternative to manual lint fixes or tree-shaking.
npm install babel-plugin-remove-unused-varsVerified import paths — ran on the pinned version, not inferred.
Shows installation, configuration, CLI usage, and a simple transformation that removes unused imports and variables.
Run locally, inspect output with 'git diff', revert false removals manually.
Avoid deep assignments, or manually adjust after transformation.
Run before other transformations like minification.
Run 'npm install --save-dev babel-plugin-remove-unused-vars' and ensure working directory has node_modules.
Use: babel.transformSync(code, { plugins: [require('babel-plugin-remove-unused-vars')] })Add presets explicitly: npx babel --no-babelrc --presets @babel/preset-env --plugins babel-plugin-remove-unused-vars