I am currently creating a React component library. This component needed a lightweight tooltip, and as I could not find anything as light as I wanted, I made another component library that I can use for the main or any other projects I want. This works very well.
However, what I'd like to do is offer users of my library a way to disable tooltips and not be penalized for doing so. From my tests it seem that, even if the tooltip is not used, it is still added to the bundle. Webpack apparently can't shake it out. It will also need to be installed as a dependency.
To give an idea of how it's used:
return (
<div>
{showTooltip ? (
<Tooltip>
//...children
</Tooltip>
) : (
//children
)}
</div>
);
showTooltip
is just a destructured prop. I get why this doesn't work, as it's impossible for the bundler to know that showTooltip
is never going to change value, but how do I do what I want here? How do I allow users to not install the tooltip lib and not be weighed down by a feature they've disabled?