jquense / react-formal

Sophisticated HTML form management for React
http://jquense.github.io/react-formal
MIT License
526 stars 52 forks source link

Support ES6 modules to only import needed parts? #110

Closed supermoos closed 7 years ago

supermoos commented 7 years ago

Is it possible to support es6 imports so I could import only FormField from react-formal, like:

import {Field} from 'react-formal';

Mainly looking for better tree-shaking support when used with webpack ^v.2

jquense commented 7 years ago

there isn't much benefit to that here, you always going to need 95% percent of the library to use it, so you don't gain much from treekshaking.

if you want to import individual components then you can do so like import FormField from 'react-formal/lib/Field'

supermoos commented 7 years ago

Hmm, I might be wrong, but in my opinion I might easily not the 'inputs' part of this project (Select, date etc.) as seen in this screenshot, that's still 8.9kb. I know, I know, that's not a ton, but still, since it's authored in es6 it seems this should be possible.

And thanks for the library BTW :-)

screen shot 2017-01-04 at 12 56 32

supermoos commented 7 years ago

Mind you those kb are uncompressed, so I guess I see your point :-)

jquense commented 7 years ago

ya it's not a ton, and its not actually likely that tree-shaking would help you at all there. It's not as smart as you might think, and often has to completely bail out of the optimization. You can completely avoid unused stuff tho by directly importing the components you want, like my example above!

supermoos commented 7 years ago

Yeah, I tried that way of importing, but it doesn't seem to work when using the Form component like:

import Form from 'react-formal/lib/Form';