A Babel plugin to remove specific import/require declarations during transpilation. Current stable version is 1.8.1 (2024). Release cadence is irregular; updates address bug fixes and support for require(). Key differentiator: allows conditional removal of imports based on regex patterns, useful for SSR builds or tree-shaking. Small bundle size (~3KB). Peer dependency on @babel/core ^7.0.0. Ships TypeScript types.
npm install babel-plugin-transform-remove-importsVerified import paths — ran on the pinned version, not inferred.
Configures Babel to remove all imports matching pattern '^lodash(\\/.*)?$' (e.g., 'lodash' and 'lodash/merge').
Explicitly keep required side-effect imports by adjusting the test regex or using a whitelist approach.
Use double backslashes in JSON config strings: '^lodash\\/.*$'. Alternatively, use a RegExp object in JavaScript config.
Upgrade to v1.5.0 or later if you need to remove CommonJS require() calls.
Evaluate alternatives: babel-plugin-import-remove (more features) or implement a custom Babel visitor for precise control.
Use a more specific test pattern to avoid catching dynamic requires. For example, if only static imports need removal, use a pattern that includes 'import' but not 'require'? Not directly supported; consider using regex negative lookahead.
Ensure the 'test' property is provided and is a string or RegExp. Example: { test: '^lodash$' }Double escape backslashes: '^lodash(\\/.*)?$'
Update @babel/core to version 7 or later. Run: npm install @babel/core@^7.0.0