Skip to content

Commit 948f71e

Browse files
committed
docs: improve instructions for opting out of shipping generated code from codegen
1 parent d2c628b commit 948f71e

File tree

2 files changed

+40
-12
lines changed

2 files changed

+40
-12
lines changed

docs/pages/build.md

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -131,24 +131,15 @@ yarn add --dev react-native-builder-bob
131131

132132
1. Configure [React Native Codegen](https://reactnative.dev/docs/the-new-architecture/what-is-codegen)
133133

134-
If your library is supporting the [New React Native Architecture](https://reactnative.dev/architecture/landing-page), you should also configure Codegen. This is not required for libraries that are only supporting the old architecture.
134+
If your library supports the [New React Native Architecture](https://reactnative.dev/architecture/landing-page), you should also configure Codegen. This is not required for libraries that only support the old architecture.
135135

136136
You can follow the [Official Codegen Setup Guide](https://reactnative.dev/docs/the-new-architecture/using-codegen) to enable Codegen.
137137

138138
It's also recommended to ship your Codegen generated scaffold code with your library since it has numerous benefits. To see the benefits and implement this behavior, you can see the [Official Codegen Shipping Guide](https://reactnative.dev/docs/the-new-architecture/codegen-cli#including-generated-code-into-libraries).
139139

140-
> Note: If you enable Codegen generated code shipping, React Native won't build the scaffold code automatically when you build your test app. You need to rebuild the codegen scaffold code manually each time you make changes to your spec. If you want to automate this process, you can create a new project with `create-react-native-library` and inspect the example app.
141-
142-
##### Opting out of Codegen shipping **(not recommended)**
140+
See [How to opt-out of shipping the Codegen generated code](./faq.md#how-to-opt-out-of-shipping-codegen-generated-scaffold-code) if you don't want to ship the Codegen generated scaffold code.
143141

144-
If you have a reason to not ship Codegen generated scaffold code with your library, you need to remove the [codegen target](#codegen) and add `package.json` to your `exports` field. Otherwise, React Native Codegen will skip spec generation for your library when your library is consumed as an NPM library. You can find the related issue [here](https://github.com/callstack/react-native-builder-bob/issues/637).
145-
146-
```json
147-
"exports": {
148-
// ...
149-
"./package.json": "./package.json"
150-
},
151-
```
142+
> Note: If you enable Codegen generated code shipping, React Native won't build the scaffold code automatically when you build your test app. You need to rebuild the codegen scaffold code manually each time you make changes to your spec. If you want to automate this process, you can create a new project with `create-react-native-library` and inspect the example app.
152143
153144
And we're done 🎉
154145

docs/pages/faq.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,43 @@ For more accurate testing, there are various other approaches:
124124

125125
You can find installation and usage instructions in the [Verdaccio documentation](https://verdaccio.org/docs/en/installation).
126126

127+
## How to opt out of shipping codegen generated code?
128+
129+
We recommend shipping the generated scaffold code with your library due to [the benefits mentioned in React Native docs](https://reactnative.dev/docs/the-new-architecture/codegen-cli#including-generated-code-into-libraries). The new architecture libraries generated by `create-react-native-library` include the generated scaffold code by default.
130+
131+
If you have a reason to not ship Codegen generated scaffold code with your library, you need do the following steps:
132+
133+
1. Add `"includesGeneratedCode": false` to the `codegenConfig` field in your `package.json`:
134+
135+
```diff
136+
"codegenConfig": {
137+
// …
138+
+ "includesGeneratedCode": false
139+
}
140+
```
141+
142+
2. Remove the [`codegen` target](#codegen) from the `react-native-builder-bob` field in your `package.json` or `bob.config.js`:
143+
144+
```diff
145+
"source": "src",
146+
"output": "lib",
147+
"targets": [
148+
// …
149+
- "codegen"
150+
]
151+
```
152+
153+
3. Add `package.json` to the `exports` field in your `package.json`:
154+
155+
```diff
156+
"exports": {
157+
// …
158+
+ "./package.json": "./package.json"
159+
},
160+
```
161+
162+
This is required for React Native Codegen to read the `codegenConfig` field from your library's `package.json`. You can find the related issue [here](https://github.com/callstack/react-native-builder-bob/issues/637).
163+
127164
## Users get a warning when they install my library
128165

129166
If users are using Yarn 1, they may get a warning when installing your library:

0 commit comments

Comments
 (0)