You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -104,7 +104,6 @@ To configure your project manually, follow these steps:
104
104
-`source`: The path to the source code. It is used by `react-native-builder-bob` to detect the correct output files and provide better error messages.
105
105
-`main`: The entry point for the CommonJS build. This is used by Node - such as tests, SSR etc.
106
106
-`module`: The entry point for the ES module build. This is used by bundlers such as webpack.
107
-
-`types`: The entry point for the TypeScript definitions. This is used by TypeScript to typecheck the code using your library.
108
107
-`files`: The files to include in the package when publishing with `npm`.
109
108
-`exports`: The entry points for tools that support the `exports` field in `package.json` - such as Node.js 12+ & modern browsers. See [the ESM support guide](./esm.md) for more details.
The `main`, `module` and `types` fields are for legacy setups that don't support the `exports` field. See the [Manual configuration](build.md#manual-configuration) guide for more information about those fields.
55
55
56
-
The `exports` field is used by modern tools and bundlers to determine the correct entry point. Here, we specify 2 conditions:
56
+
The `exports` field is used by modern tools and bundlers to determine the correct entry point. The entrypoint is specified in the `.` key and will be used when the library is imported or required directly (e.g. `import 'my-library'` or `require('my-library')`).
57
+
58
+
Here, we specify 2 conditions:
57
59
58
60
-`import`: Used when the library is imported with an `import` statement or a dynamic `import()`. It should point to the ESM build.
59
61
-`require`: Used when the library is required with a `require` call. It should point to the CommonJS build.
60
62
61
-
Each condition has a `types` field - necessary for TypeScript to provide the appropriate definitions for the module system. The type definitions have slightly different semantics for CommonJS and ESM, so it's important to specify them separately.
63
+
Each condition has 2 fields:
62
64
63
-
The `default` field is the fallback entry point for both conditions. It's used for the actual JS code when the library is imported or required.
65
+
-`types`: necessary for TypeScript to provide the appropriate definitions for the module system. The type definitions have slightly different semantics for CommonJS and ESM, so it's important to specify them separately.
66
+
-`default`: fallback entry point for both conditions. It's used for the actual JS code when the library is imported or required.
64
67
65
68
You can also specify additional conditions for different scenarios, such as `react-native`, `browser`, `production`, `development` etc. Note that support for these conditions depends on the tooling you're using.
66
69
70
+
The `./package.json` field is used to point to the library's `package.json` file. It's necessary for tools that may need to read the `package.json` file directly (e.g. [React Native Codegen](https://reactnative.dev/docs/the-new-architecture/what-is-codegen)).
71
+
67
72
## Guidelines
68
73
69
74
There are still a few things to keep in mind if you want your library to be ESM-compatible:
@@ -96,6 +101,7 @@ There are still a few things to keep in mind if you want your library to be ESM-
0 commit comments