babel-plugin-eliminator
v1.0.1
Published
Remove specific named exports
Downloads
5,028
Readme
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
/** Removed named exports */
removedNamedExports: Set<string>
}
type PluginOpts = {
/** Removing specific named exports */
namedExports?: string[]
/** Called at the end of transpiling */
done?: (state: PluginState) => void
}
Credits
This plugin is essentially a fork of next.js/next-ssg-transform.
License
MIT © EGOIST