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:
- Is this expected behavior?
- Whats optional about these peer dependencies, if the App breaks when the modules my library depends on are not around?
- Are there no options for me other than to make a separate package for the components?
Hopefully someone can shed some light into the dark for me.