Skip to content

Commit f6accd3

Browse files
committed
docs: add example code for expo config plugin
1 parent ccd8600 commit f6accd3

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

docs/pages/esm.md

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@ For TypeScript, it also generates 2 sets of type definitions if the [`commonjs`]
2424
It's recommended to specify `"moduleResolution": "bundler"` in your `tsconfig.json` file to match Metro's behavior:
2525

2626
```json
27-
{
28-
"compilerOptions": {
29-
"moduleResolution": "bundler"
30-
}
31-
}
27+
{ "compilerOptions": { "moduleResolution": "bundler" } }
3228
```
3329

3430
Specifying `"moduleResolution": "bundler"` means that you don't need to use file extensions in the import statements. Bob automatically adds them when possible during the build process.
@@ -60,12 +56,26 @@ Here, we specify 3 conditions:
6056

6157
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.
6258

63-
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)). Make sure to also add any other files that other tools may read, for example `./app.plugin.js` if you provide a [Expo Config plugin](https://docs.expo.dev/config-plugins/plugins-and-mods/#apppluginjs).
59+
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)).
6460

6561
Using the `exports` field has a few benefits, such as:
6662

67-
- It [restricts access to the library's internals](https://nodejs.org/api/packages.html#main-entry-point-export) by default. You can explicitly specify which files are accessible with [subpath exports](https://nodejs.org/api/packages.html#subpath-exports).
6863
- It allows you to specify different entry points for different environments with [conditional exports](https://nodejs.org/api/packages.html#conditional-exports) (e.g. `node`, `browser`, `module`, `react-native`, `production`, `development` etc.).
64+
- It [restricts access to the library's internals](https://nodejs.org/api/packages.html#main-entry-point-export) by default. You can explicitly specify which files are accessible with [subpath exports](https://nodejs.org/api/packages.html#subpath-exports).
65+
66+
So make sure to explicitly specify any files that need to be readable by other tools, e.g. `./app.plugin.js` if you provide a [Expo Config plugin](https://docs.expo.dev/config-plugins/plugins-and-mods/#apppluginjs):
67+
68+
```diff
69+
"exports": {
70+
".": {
71+
"source": "./src/index.tsx",
72+
"types": "./lib/typescript/src/index.d.ts",
73+
"default": "./lib/module/index.js"
74+
},
75+
"./package.json": "./package.json",
76+
+ "./app.plugin.js": "./app.plugin.js"
77+
},
78+
```
6979

7080
### A note on `import.meta`
7181

0 commit comments

Comments
 (0)