babel-plugin-extract-export

Extract ESM exports and their dependencies using Babel.

MIT License

Downloads
5.2K
Stars
3
Committers
1

babel-plugin-extract-export

This is a fork of the NextJS SSG transform Babel plugin that reverses the logic and allows extracting a specific export and its dependencies.

Install

yarn add babel-plugin-extract-export

Example

const babel = require('@babel/core')
const syntaxTypeScript = require('@babel/plugin-syntax-typescript')
const extractExport = require('babel-plugin-extract-export')

const jsx = `
import { Image } from 'system'

export const Avatar = () => <Image />

type SystemProps = { as: any }

type BoxProps = { children: any } & SystemProps

export const Box = (props: BoxProps) => <div {...props} />
`

const result = babel.transform(jsx, {
  configFile: false,
  plugins: [
    [syntaxTypeScript, { isTSX: true }],
    [extractExport, { exportName: 'Avatar' }],
  ],
})

// Output:
// import { Image } from 'system'
// export const Avatar = () => <Image />

Development

yarn install && yarn test