0.1.0 • Published 3 years ago

babel-plugin-extract-export v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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