0

I'm trying to create a component library with multiple independent components folders. The end goal is to allow a user to do something like

import { Header } from 'component-library/theme/one' 
import { Header as HeaderTwo } from 'component-library/theme/two'

But when i try to import it, i get this errors:

Error 1

Error 2

I have structured folder like:

src
 -index.js
themes
 one
   - index.js
 two
   - index.js

2 Answers2

0

If you export your components like export default then you can import it with whatever name you want. import { whatever } from ....

IWI
  • 1,528
  • 4
  • 27
  • 47
  • but my problem is the way to compile sub-folders, I need to use other components with `import { Header } from 'library/theme/two'`. in this case, I need to use Header from theme two – quirozcarlos Mar 08 '21 at 19:21
0

I already fixed it, I changed my package.json with:

"main": "./_modules/index.js",
"exports": {
  ".": "./_modules/index.js",
  "./theme_two": "./_modules/themes/two/index.js"
},

So, if I want to add more themes, only should add the reference from _modules folder.