Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Package with multiple exports folders #260

Closed
kaueDM opened this issue Aug 10, 2022 · 5 comments
Closed

[Question] Package with multiple exports folders #260

kaueDM opened this issue Aug 10, 2022 · 5 comments
Labels
question Further information is requested

Comments

@kaueDM
Copy link

kaueDM commented Aug 10, 2022

Ask your Question

How can I setup builder-bob to output multiple exports?

I want to export some utils in a different path (like "/my-lib/utils"), but couldn't figure it out yet looking the source code/issues.

@kaueDM kaueDM added the question Further information is requested label Aug 10, 2022
@alpha0010
Copy link

Sort of a hack, but here is how I did it: alpha0010/react-native-pdf-viewer@c7c41ea .

  • Write all your code in src/
  • Register a redirect in a subdirectory
// In utils/package.json
{
  "main": "../lib/commonjs/MyScript",
  "module": "../lib/module/MyScript",
  "react-native": "../src/MyScript",
  "types": "../lib/typescript/MyScript.d.ts"
}

With this, import { Xyz } from 'my-lib/utils'; should work when the library is installed. (Requires some trickery to make this work in the example project, so not certain what to suggest there.)

@kaueDM
Copy link
Author

kaueDM commented Sep 23, 2022

Couldn't make it work, so I replaced builder-bob with rollup.

@kaueDM kaueDM closed this as completed Sep 23, 2022
@dmahajan980
Copy link

@kaueDM can you share the repository so that we can see how you did it? Thanks

@zarkoden
Copy link

@kaueDM can you share your rollup solution, please?

@mikelgarciaurbina
Copy link

mikelgarciaurbina commented Feb 12, 2024

I want to share how I solved this:
To better handle exports from paths other than src, for instance, if you have a src/utils directory that you wish to export from a different path, you can create a utils directory outside of src. Then, add a package.json file in this new directory:

/my-lib/utils/package.json
{
  "main": "../lib/commonjs/utils",
  "module": "../lib/module/utils",
  "react-native": "../src/utils"
}

Next, include this directory in the files section of your library's main package.json:

{
 "main": "lib/commonjs/index.js",
 "module": "lib/module/index.js",
 "react-native": "src/index.js"
 ...
 "files": [
   "build",
   "src",
   "utils"
 ],
}

With this setup, you will be able to import utilities like so:

import { someUtil } from 'my-lib/utils';

This approach allows for a clear directory structure and makes it easier to import specific utilities from your library anywhere in your project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants