HarveyD / react-component-library

A project skeleton to get your very own React Component Library up and running using Rollup, Typescript, SASS + Storybook
https://blog.harveydelaney.com/creating-your-own-react-component-library/
MIT License
790 stars 167 forks source link

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

Closed JaLe29 closed 4 years ago

JaLe29 commented 4 years ago

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, ...)

HarveyD commented 4 years ago

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.

JaLe29 commented 4 years ago

Thank you! 😍

HarveyD commented 4 years ago

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.