babel-plugin-nukable-import

raw JSON →
0.4.2 verified Sat Apr 25 auth: no javascript maintenance

Babel plugin (v0.4.2) that removes specific named bindings from import declarations and corresponding export references. Useful for stripping development-only or debugging code from production builds. Unlike general dead-code elimination, it targets imports by source and binding name, working at AST level. Maintained by the Glimmer.js team; used within the Glimmer-VM ecosystem. Low release cadence.

error TypeError: Cannot read properties of undefined (reading 'isCallExpression')
cause Delegate called with unexpected path type, likely from non-CallExpression/non-Identifier.
fix
Add a guard in your delegate: if (t.isCallExpression(path) || t.isIdentifier(path)) { ... }
error Error: [BABEL] unknown: Plugin/preset files are not allowed to export objects, only functions.
cause Using plugin without array notation or misconfigured require.
fix
Use ['nukable-import', options] syntax in your Babel config.
error ReferenceError: require is not defined in ES module scope
cause Using require in an ES module context.
fix
Use import.meta.glob or dynamic import, or configure Babel as CommonJS.
breaking Only works with named imports; default imports are not removed.
fix Use named imports for bindings you wish to remove, or use a different plugin for default imports.
gotcha Plugin removes the entire import declaration if all bindings are nuked; side effects may be lost.
fix Ensure the import source has no side effects, or use sideEffects: false in package.json.
gotcha Delegate only receives CallExpression and Identifier paths; other expression types are ignored.
fix Use delegate only for removing call expressions or identifier references; for other cases, write a custom plugin.
gotcha Duplicate imports from the same source: plugin may merge or leave orphaned imports.
fix Avoid duplicate import declarations from the same source in the same file.
npm install babel-plugin-nukable-import
yarn add babel-plugin-nukable-import
pnpm add babel-plugin-nukable-import

Configures Babel to remove all bindings from '@glimmer/debug' import, stripping debug code.

// babel.config.js
module.exports = {
  plugins: [
    ['nukable-import', { source: '@glimmer/debug' }]
  ]
};

// input.js
import { assert, check } from '@glimmer/debug';
assert(someCondition);
check(value, someType);

// output.js
// Both assert and check calls removed, imports removed