step1:
$ npm install -g create-react-native-module
step2:
create-react-native-module --package-identifier io.mylibrary --generate-example MyLibrary --example-react-native-version 0.63
The module would be generated in the react-native-my-library
subdirectory and the example test app would be in react-native-my-library/example
.
step3:
Now you can add the function. In the MyLibraryModule file add this code:
@ReactMethod
public void youOwnFuction(String json) {
//Do something
}
step4:
add
"publishConfig": { "registry": "https://npm.pkg.github.com" }
and
"repository": {"type": "git","url": "git+https://github.com/<user name or organization name>/myLibrary.git","baseUrl": "https://github.com/<user name or organization name>/myLibrary.git"},
to your react-native-my-library/package.json
file
- In the same directory as your
package.json
file, create or edit an.npmrc
file to include a line specifying GitHub Packages URL and the account owner. ReplaceOWNER
with the name of the user or organization account that owns the repository containing your project.
registry=https://npm.pkg.github.com/OWNER
2. Add the .npmrc file to the repository where GitHub Packages can find your project. For more information, see “Adding a file to a repository using the command line.”
3. Verify the name of your package in your project’s package.json. The name
field must contain the scope and the name of the package. For example, if your package is called "test", and you are publishing to the "My-org" GitHub organization, the name
field in your package.json should be @my-org/test
.
4. Verify the repository
field in your project's package.json. The repository
field must match the URL for your GitHub repository. For example, if your repository URL is github.com/my-org/test
then the repository field should be git://github.com/my-org/test.git
.
5. Publish the package:
$ npm publish
step:5
install
.npmrc
@my-org:registry=https://npm.pkg.github.com
_authToken=TOKEN
always-auth=true
.yarnrc
"@my-org:registry" "https://npm.pkg.github.com"
then
yarn install @my-org/mylibrary@1.0.0