babel-plugin-eliminator
What is this?
This is a babel plugin for removing specific named exports in your JavaScript code, this is how Next.js implements getServerSideProps
and getStaticProps
, it essentially removes thoses exports and referenced variables.
Install
npm i babel-plugin-eliminator
Usage
Removing specific named exports
Options:
{
"plugins": [
["eliminator", {"namedExports": ["foo"]}]
]
}
Input:
import pkg from 'some-pkg'
const someVariable = 'some-string'
export const foo = () => {
return pkg(someVariable)
}
Output:
export var foo = 1
Options
type PluginState = {
refs: Set<NodePath<BabelTypes.Identifier>>
opts: PluginOpts
removedNamedExports: Set<string>
}
type PluginOpts = {
namedExports?: string[]
done?: (state: PluginState) => void
}
Credits
This plugin is essentially a fork of next.js/next-ssg-transform.
License
MIT © EGOIST