Skip to content

Commit 139c3f6

Browse files
committed
feat: add support for bob.config.js and update docs
1 parent aceaf75 commit 139c3f6

File tree

2 files changed

+80
-3
lines changed

2 files changed

+80
-3
lines changed

README.md

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
The CLI can build code for following targets:
88

9-
- Android AAR files
109
- Generic CommonJS build
1110
- ES modules build for bundlers such as webpack
1211
- Flow definitions (copies .js files to .flow files)
13-
- TypeScript definitions (uses tsc to generate declaration files)
12+
- TypeScript definitions (uses `tsc` to generate declaration files)
13+
- Android AAR files
1414

1515
## Why?
1616

@@ -72,6 +72,12 @@ To configure your project manually, follow these steps:
7272
]
7373
```
7474

75+
Make sure to change specify correct files according to the targets you have enabled.
76+
77+
It's usually good to point to your source code with the `react-native` field to make debugging easier. Metro already supports compiling a lot of new syntaxes including JSX, Flow and TypeScript and it will use this field if present.
78+
79+
If you're building TypeScript definition files, also make sure that the `types` field points to a correct path. Depending on the project configuration, the path can be different for you than the example snippet.
80+
7581
1. Add the output directory to `.gitignore` and `.eslintignore`
7682

7783
```gitignore
@@ -87,6 +93,75 @@ To configure your project manually, follow these steps:
8793

8894
And we're done 🎉
8995

96+
## Options
97+
98+
The options can be specified in the `package.json` file under the `@react-native-community/bob` property, or in a `bob.config.js` file in your project directory.
99+
100+
### `source`
101+
102+
The name of the folder with the source code which should be compiled. The folder should include an `index` file.
103+
104+
### `output`
105+
106+
The name of the folder where the compiled files should be output to. It will contain separate folder for each target.
107+
108+
### `targets`
109+
110+
Various targets to build for. The available targets are:
111+
112+
#### `commonjs`
113+
114+
Enable compiling source files with Babel and use commonjs module system.
115+
116+
This is useful for running the code in Node (SSR, tests etc.). The output file should be referenced in the `main` field of `package.json`.
117+
118+
By default, this will compile the code for last 2 versions of modern browsers, as well as JSX. It'll also strip TypeScript and Flow annotations. To customize the babel config used, you can pass the [`configFile`](https://babeljs.io/docs/en/options#configfile) or [`babelrc`](https://babeljs.io/docs/en/options#babelrc) options.
119+
120+
If your source code is written in [Flow](http://www.typescriptlang.org/), You can also specify the `copyFlow` option to copy the source files as `.js.flow` to the output folder. If the `main` entry in `package.json` points to the `index` file in the output folder, the flow type checker will pick these files up to use for type definitions.
121+
122+
Example:
123+
124+
```json
125+
["commonjs", { "babelrc": true, "copyFlow": true }]
126+
```
127+
128+
#### `module`
129+
130+
Enable compiling source files with Babel and use ES module system. This is essentially same as the `commonjs` target and accepts the same options, but leaves the `import`/`export` statements in your code.
131+
132+
This is useful for bundlers which understand ES modules and can tree-shake. The output file should be referenced in the `module` field of `package.json`.
133+
134+
Example:
135+
136+
```json
137+
["commonjs", { "babelrc": true, "copyFlow": true }]
138+
```
139+
140+
#### `typescript`
141+
142+
Enable generating type definitions with `tsc` if your source code is written in [TypeScript](http://www.typescriptlang.org/).
143+
144+
By default, it'll use the `tsconfig.json` file in your project root. If you want to use a different config, you can specify it using the `project` option.
145+
146+
Example:
147+
148+
```json
149+
["typescript", { "project": "tsconfig.build.json" }]
150+
```
151+
152+
#### `aar`
153+
154+
Enable assembling Android AAR files for a library for React Native modules including native code.
155+
156+
It's also possible to convert the AAR with the `reverseJetify` option to use the [Android support Library](https://developer.android.com/topic/libraries/support-library) using the [`jetifier`](https://www.npmjs.com/package/jetifier) package if your package is using [AndroidX](https://developer.android.com/jetpack/androidx). This is useful to publish packages for older projects which haven't migrated to AndroidX.
157+
158+
You can also specify the `androidPath` (defaults to `android`) to specify the `android` directory and `androidBundleName` (defaults to `android.aar`) to customize the name of AAR file.
159+
Example:
160+
161+
```json
162+
["aar", { "reverseJetify": true }]
163+
```
164+
90165
## LICENSE
91166

92167
MIT

src/cli.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ import { Options } from './types';
1616
const { name } = require('../package.json');
1717

1818
const root = process.cwd();
19-
const explorer = cosmiconfigSync(name);
19+
const explorer = cosmiconfigSync(name, {
20+
searchPlaces: ['package.json', `bob.config.js`],
21+
});
2022

2123
const FLOW_PRGAMA_REGEX = /\*?\s*@(flow)\b/m;
2224

0 commit comments

Comments
 (0)