vazco / uniforms

A React library for building forms from any schema.
https://uniforms.tools
MIT License
1.95k stars 239 forks source link

[Question] Rich component for uniforms #444

Closed theodorDiaconu closed 6 years ago

theodorDiaconu commented 6 years ago

In our apps we've used uniforms custom fields with react-select, react-toggle, react-dates, etc...

I want to open-source them, but at the same time I want a good way to manage this. We either have the option of 1 npm package per field. (which can be tedious to maintain) or 1 package with all those rich components (which is too much when you need a small piece)

What do you suggest ?

radekmie commented 6 years ago

I definitely recommend one repository (with Lerna if needed). Multiple vs single npm packages... Well, I'd go with one. A bunch of components, imported with import XField from 'package/XField is easy enough to use, doesn't bloat, as you won't import unused packages and limits to one npm install (and update).

Whole uniforms go with such idea (import AutoForm from 'uniforms/AutoForm') - theme packages are just a sane separation, as you'll probably never have more than one.

theodorDiaconu commented 6 years ago

The problem is that if I want that kind of package I would have a bunch of npm dependencies on packages that may be very large. And even if I put them as peerDependencies it would still show you warnings you may not want when npm installing.

I've looked at this: https://github.com/Wizcorp/codependency but don't understand it fully yet.

radekmie commented 6 years ago

Welcome to my world!

Yep, that's an issue. Especially, if you have few of these - uniforms are a great case to study that. Well, in this case, I'd go with a monorepo managed with Lerna.

theodorDiaconu commented 6 years ago

@radekmie if I go towards the path of monolith package, I don't see how lerna can help, but thanks for the tip. I will make the single package, if you want you can close this issue, I'll post the link here after I'm done with them.

Maybe I can hackishly do something like const package = require('package'); if package && but it feels so bad...

radekmie commented 6 years ago

No, Lerna will help you with managing monorepo, so a repository with multiple packages.

Using require is not the way. I'm doing the same in uniforms are doing the same and it's great at runtime, but horrible at static analysis - Meteor, Webpack and other bundlers will complain about an unresolved module.

I'll close now, but feel free to share a link here. If you'll want to discuss something or need some help - feel free to ask here or on our Gitter. Good luck!