HarveyD/react-component-library

It should be nice to have support for modular components - export/import

JaLe29 opened this issue · 3 comments

It should be nice to have support for modular components - export/import.

Right now we need to import our component using import { AComponent, BComponent } from "harvey-component-library";

It should be nice to have separate build for each component:

import AComponent from "harvey-component-library/AComponent ";
and
import BComponent from "harvey-component-library/BComponent ";

For example I would like to use ONLY AComponent in other project, why should I include full code (BComponent, ...)

Hey @JaLe29,

This is an excellent suggestion. I've done some research into this and will be updating my blog and repository to show people how to achieve this sometime soon.

Thank you! 😍

Hey @JaLe29,

Sorry about the delay. I've found out this is possible using Rollup's Code Splitting functionality. Unfortunately, I could only get it working by targeting one module format (CJS).

I've written about how to achieve this at: https://blog.harveydelaney.com/creating-your-own-react-component-library/#introducing-code-splitting-optional-

I've already created a commit on the code-splitting branch which shows the changes necessary to implement it.

Please let me know if this helps.