callstack / react-native-builder-bob

👷‍♂️ Simple set of CLIs to scaffold and build React Native libraries for different targets
https://callstack.github.io/react-native-builder-bob/
2.74k stars 182 forks source link

main fields support #177

Closed akinncar closed 2 years ago

akinncar commented 3 years ago

Main fields support

Can I have multiple entry files for different environments?

For example, I want o use the lib/ directory when publishing the package on NPM, but use src/ directory to test locally without the need to compile on every change or change main on package.json

Package.json that I want:

"main": "lib/commonjs/index.js",
"module": "src/index.ts",

But I have this error when I don't have the files compiled into the lib folder:

Error: ENOENT: no such file or directory, open 'myproject/node_modules/react-native-mask-text/lib/module/index.js'

On README, you suggest using react-native param on the package.json entry file to easily debug, but it doesn't works (at least with expo).

Repo that I need this behavior is https://github.com/akinncar/react-native-mask-text

Related: https://github.com/standard-things/esm/issues/794

satya164 commented 2 years ago

For example, I want o use the lib/ directory when publishing the package on NPM, but use src/ directory to test locally without the need to compile on every change or change main on package.json

This is how it's already configured if you init a project with create-react-native-library. You never need to compile it manually. Source code will be used during development and JS will be compiled automatically when publishing to npm