I have an NPM package that offers two things: Core functionality in form of React hooks and UI components that use these core functionalities.
My idea originally was to make two packages, one for the core stuff and one for the components. So that if you don't want to use the components out of the box, you could still use the libraries core features. After working on the library I found it to be overkill to make two packages, because the core functionality is basically 2 Hooks with less than 200 lines of code.
So I went the route to add the UI components dependencies as peer dependencies, and expected that when I mark them as optional, you wouldn't need to install them if you don't need the UI parts. With mark them as optional I mean:
"peerDependenciesMeta": {
"@material-ui/core": {
"optional": true
},
}
Now the problem is, even if I don't import the UI parts from my library into a testing project I set up, the App breaks because it is trying to look for the optional dependencies.
My questions:
Hopefully someone can shed some light into the dark for me.
Seems the only real solution to this is to really split the core functionality from the UI parts. Otherwise, there will be always dependencies installed that a user might not want.