@binary-agents/babel-component-replace
v1.0.1
Published
Replace a component body at compile time.
Downloads
3
Readme
Babel Component Replace
Replace components at compile time with components having the same signature.
Examples:
The original function should have an @component {componentType}
annotation
in its docblock.
/**
* Words that describe the function.
*
* @component speechBubble
*/
function FriendlyGreeter(props) {
return <div>Hey there</div>;
}
The component can then be replaced by adding its component type to the config for this plugin.
{
"plugins": [
[
"babel-component-replace",
{
"speechBubble": "function evilGreeter(props) {return <div>Mwa Ha Ha</div>}"
}
]
]
}
Alternately, the config can point to a file that contains the component.
{
"plugins": [
[
"babel-component-replace",
{
"speechBubble": {
"path": "src/EvilGreeter.js"
}
}
]
]
}
The file should only contain the replacement component.
The end result of this operation will have the original function name and arguments, but will have the body of the replacement function.
/**
* Words that describe the function.
*
* @component speechBubble
*/
function FriendlyGreeter(props) {
return <div>Mwa Ha Ha</div>;
}