3

I have a package with the following structure:

components/
  Button/
    Button.tsx
    index.tsx
  Icon/
    Icon.tsx
    index.tsx

I am exporting this as an npm package, to be consumed by another repo. In the importing repo, I am currently importing like so:

import Button from "my-package/components/Button"
import Icon from "my-package/components/Icon"

What I would like to do is import them like so:

import { Button, Icon } from "my-package"

I am aware that to do so, I need to define an entry point. However it seems like I will need to manually import/export all the components to and from the entry point file.

Is there a way to automatically generate such an entry point file, without all the required manual effort?

Powderham
  • 1,510
  • 12
  • 14
  • Does this answer your question? [TypeScript Import Path Alias](https://stackoverflow.com/questions/38601592/typescript-import-path-alias) – mamichels Aug 20 '20 at 13:18
  • @mamichels I don't believe it does. Because (as far as I can tell) that's aliasing the destination in the target repo to reflect the structure of the module. What I am looking to do is automatically update the structure of the exported module such that everything can be imported from the root, much like one can do `import { useState} from 'React'` – Powderham Aug 20 '20 at 13:32
  • Possible duplicate of https://stackoverflow.com/questions/29722270/is-it-possible-to-import-modules-from-all-files-in-a-directory-using-a-wildcard – vvg Aug 28 '20 at 22:13
  • If you ever find an answer to your question, please share it. Manually managing an index is a PITA. I have scripts to do it for me (scan the src folder for all files and add entry in a index.ts but it ain't pretty...) – birgersp Jan 13 '23 at 09:16

0 Answers0