Registry / devops / babel-plugin-extract-export

babel-plugin-extract-export

JSON →
library0.1.0jsnpmunverified

A Babel plugin that extracts a specific ESM export and its dependencies from a file, based on a fork of NextJS's SSG transform plugin. Current version 0.1.0, single release. It operates by performing static analysis with Babel to remove unused exports and import statements, outputting only the targeted export and its prerequisites. Differentiates from tree-shaking tools by allowing per-export extraction at build time, useful for code splitting or dynamic imports. Note: The package has not been updated since initial release and may have limited compatibility with newer Babel versions.

npm install babel-plugin-extract-export
INSTALL
IMPORT
SIG · BABEL-PLUGIN-EXTRA
B
babel-plugin-extract-export
devopsjavascriptv0.1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
const extractExport = require('babel-plugin-extract-export')
Plugin is CommonJS only; no ESM or TypeScript typings provided.
default
import extractExport from 'babel-plugin-extract-export'
import * as extractExport from 'babel-plugin-extract-export'
The plugin exports a single default function. As of v0.1.0, ESM syntax works only if your bundler interops with CJS.
default
plugins: [extractExport, { exportName: 'MyExport' }]
plugins: [[extractExport, { exportName: 'MyExport' }]]
When using Babel's plugins array, the plugin and its options are passed as a tuple inside an array, but some may mistakenly wrap it twice.

Shows how to use the plugin with Babel to extract a specific export (Avatar) and its dependencies from a source string.

const babel = require('@babel/core'); const syntaxTypeScript = require('@babel/plugin-syntax-typescript'); const extractExport = require('babel-plugin-extract-export'); const source = ` import { Image } from 'system'; export const Avatar = () => <Image />; type BoxProps = { children: any }; export const Box = (props: BoxProps) => <div {...props} />; `; const result = babel.transformSync(source, { configFile: false, plugins: [ [syntaxTypeScript, { isTSX: true }], [extractExport, { exportName: 'Avatar' }], ], }); console.log(result.code); // Expected output: // import { Image } from 'system'; // export const Avatar = () => <Image />;
Debug
Known issues
breakingVersion 0.1.0 is the only release and may break with Babel versions other than 7.x. No tests for Babel 8.
fix
Ensure Babel 7 compatibility; upgrade to future releases if available.
affects: >=0.1.0
deprecatedThe plugin is in maintenance mode with no recent updates. It may be deprecated or superseded by NextJS's official transforms.
fix
Consider using NextJS's SSG transform directly or a more maintained alternative like babel-plugin-transform-imports.
affects: >=0.1.0
gotchaPlugin only extracts a single named export (via 'exportName' option). Multiple exports or default exports are not supported.
fix
Use separate passes or a different plugin if you need to extract multiple exports.
affects: >=0.1.0
gotchaRequires @babel/plugin-syntax-typescript with { isTSX: true } when extracting from TypeScript JSX files; otherwise parsing may fail silently.
fix
Always include the syntax plugin with appropriate configuration for TSX files.
affects: >=0.1.0
Errors
Common errors & fixes
Error: Cannot find module 'babel-plugin-extract-export'
Package not installed or node_modules missing.
fix
Run 'yarn add babel-plugin-extract-export' or 'npm install babel-plugin-extract-export'.
TypeError: plugin is not a function
Passing the plugin incorrectly to Babel's plugins array; likely double-wrapped in array.
fix
Use [[plugin, options]] syntax correctly: 'plugins: [[extractExport, { exportName: 'Avatar' }]]'.
Cannot read property 'replace' of undefined at ... PluginPass.ExportNamedDeclaration
Plugin encountered a file without any named exports matching the specified exportName, or the file is not parseable.
fix
Ensure the file has an exported variable or function with the exact name given in exportName option.
Upgrade
Version history
0.1.0latest on npm
Audit
Dependencies
@babel/corerequiredPeer dependency required for transforming code
@babel/plugin-syntax-typescriptoptionalRequired to parse TypeScript syntax when TS files are processed
Agent activity
11 hits · last 30 days
node
10
OpenAI (training)
1
Resources
babel-plugin-extract-export — npm install babel-plugin-extract-export · libregistry