forked from react-native-community/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add dependency and project documentation (react-native-communit…
…y#350) * Add dependency documentation and links * Update * Update * Add project desc * Move notice above * add catch-all doc * Typo * Rename the type * Update docs/configuration.md Co-Authored-By: grabbou <[email protected]> * Update docs/configuration.md Co-Authored-By: grabbou <[email protected]> * Do where not when * Plural
- Loading branch information
Showing
5 changed files
with
369 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,15 @@ | ||
# Configuration | ||
|
||
TBD | ||
React Native CLI has a configuration mechanism that allows changing its behavior and providing additional features. | ||
|
||
> Note: Configuring CLI used to be possible via `rn-cli.config.js` (that has been renamed to `metro.config.js`) and never documented `rnpm` entry on the `package.json`. We have provided migration guides where possible. | ||
React Native CLI can be configured by creating a `react-native.config.js` at the root of the project. Depending on a type of a package, this file can have a different set properties. | ||
|
||
Check the documentation for: | ||
- [projects](./projects.md) | ||
- [dependencies](./dependencies.md) | ||
- [platforms](./platforms.md) | ||
- [plugins](./plugins.md) | ||
|
||
to learn more about different types of configuration and features available. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
# Dependency | ||
|
||
A dependency is a JavaScript package that is listed under dependencies present in the project's `package.json`. It can also contain native, platform-specific files that should be linked. | ||
|
||
For example, `lodash` is a dependency that doesn't have any native code to link. On the other hand, `react-native-vector-icons` is a dependency that contains not only native code, but also font assets that the CLI should link. | ||
|
||
By default, CLI analyses the folder structure inside the dependency and looks for assets and native files to link. This simple heuristic works in most of the cases. | ||
|
||
At the same time, a dependency can explicitly set its configuration in case CLI cannot infer it properly. A dependency can also define additional settings, such as a script to run after linking, in order to support some advanced use-cases. | ||
|
||
## How does it work? | ||
|
||
A dependency can define the following `react-native.config.js` at the root: | ||
|
||
```js | ||
module.exports = { | ||
dependency: { | ||
platforms: { | ||
ios: { | ||
project: './Custom.xcodeproj' | ||
} | ||
} | ||
assets: ['./assets'] | ||
} | ||
}; | ||
``` | ||
|
||
> The above configuration informs CLI of the additional assets to link and about a custom project location. | ||
## Dependency interface | ||
|
||
The following type describes the configuration of a dependency that can be set under `dependency` key inside `react-native.config.js`. | ||
|
||
```ts | ||
type DependencyConfigT = { | ||
platforms: { | ||
[key: string]: any, | ||
}, | ||
assets: string[], | ||
hooks: { | ||
[key: string]: string, | ||
} | ||
}; | ||
``` | ||
|
||
> Note: This interface is subject to breaking changes. We may consider renaming some keys to simplify the configuration further. If you are going to use it, be prepared to update before we ship a stable 0.60.0 release. | ||
### platforms | ||
|
||
A map of specific settings that can be set per platform. The exact shape is always defined by the package that provides given platform. | ||
|
||
In most cases, as a library author, you should not need to define any of these. | ||
|
||
The following settings are available on iOS and Android: | ||
|
||
```ts | ||
type DependencyParamsIOST = { | ||
project?: string, | ||
sharedLibraries?: string[], | ||
}; | ||
|
||
type DependencyParamsAndroidT = { | ||
sourceDir?: string, | ||
manifestPath?: string, | ||
packageImportPath?: string, | ||
packageInstance?: string | ||
}; | ||
``` | ||
|
||
#### platforms.ios.project | ||
|
||
Custom path to `.xcodeproj` | ||
|
||
#### platforms.ios.sharedLibraries | ||
|
||
An array of shared iOS libraries to link with the dependency. E.g. `libc++`. This is mostly a requirement of the native code that a dependency ships with. | ||
|
||
#### platforms.android.sourceDir | ||
|
||
Path to a folder with source files. | ||
|
||
#### platforms.android.manifestPath | ||
|
||
Path to a custom `AndroidManifest.xml` | ||
|
||
#### platforms.android.packageImportPath | ||
|
||
Custom package import. For example: `import com.acme.AwesomePackage;`. | ||
|
||
#### platforms.android.packageInstance | ||
|
||
Custom syntax to instantiate a package. By default, it's a `new AwesomePackage()`. It can be useful when your package requires additional arguments while initializing. | ||
|
||
For settings applicable on other platforms, please consult their respective documentation. | ||
|
||
### assets | ||
|
||
An array of assets folders to glob for files to link. | ||
|
||
### hooks | ||
|
||
A map where key is the name of a hook and value is the path to a file to execute. | ||
|
||
For example, `link` command supports `prelink` and `postlink` hooks to run before and after linking is done. | ||
|
||
These are the only ones supported by CLI at the moment. Depending on the packages used in your project, you may find other hooks supported to. | ||
|
||
> Note: This has nothing to do with React Hooks. | ||
## Migrating from `rnpm` configuration | ||
|
||
The changes are mostly cosmetic so the migration should be pretty straight-forward. | ||
|
||
> Note: We read `rnpm` configuration to remain backwards-compatible. Dependency maintainers should update their configuration in the nearest future. | ||
### Changing the configuration | ||
|
||
Properties were renamed. Look at the following example for the differences. | ||
|
||
```json | ||
{ | ||
"rnpm": { | ||
"ios": {}, | ||
"android": {}, | ||
"assets": ["./path-to-assets"], | ||
"hooks": { | ||
"prelink": "./path-to-a-postlink-hook" | ||
} | ||
} | ||
} | ||
``` | ||
|
||
to a `react-native.config.js` | ||
|
||
```js | ||
module.exports = { | ||
dependency: { | ||
platforms: { | ||
ios: {}, | ||
android: {}, | ||
}, | ||
assets: ['./path-to-assets'], | ||
hooks: { | ||
prelink: './path-to-a-postlink-hook' | ||
} | ||
} | ||
}; | ||
``` | ||
|
||
### Asking for params while linking has been removed | ||
|
||
If your library needs it, do not upgrade over to the new config format. | ||
|
||
If you want to ask users for additional settings, consider setting a custom `postlink` hook, just like [`react-native-code-push`](https://github.com/Microsoft/react-native-code-push/blob/master/package.json#L53). |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.