
March 6, 2024 • Knowledge
May 31, 2024 • Knowledge • by Widiana Putra
Table of Contents
To start creating your React Native package, use the following command:
npx create-react-native-library <package_name>
Create a Private Repository on GitHub
Generate a GitHub Token
write:package
permissions and workflow access.
Make sure to check the write:package permissions and workflow
Modify package.json
for Publishing
publishConfig
attribute in your package.json
file to specify the GitHub registry.Open your package.json, and change the “publishConfig” attribute to:
"publishConfig": {
"registry": "<https://npm.pkg.github.com>"
},
Login to GitHub via Terminal
npm login –registry=https://npm.pkg.github.com
username: GitHub username
password: Token (newly created token using the above steps)
email: your email
Add .npmrc
to Your Project Root
.npmrc
file in the root directory of your project and add the following line://npm.pkg.github.com/:_authToken=<token>
Optional: Update lefthook.yml
for Pre-commit Linting
lefthook.yml
as follows:pre-commit:
parallel: true
commands:
lint:
files: git diff --name-only @{push}
glob: '*.{js,ts,jsx,tsx}'
run: npx eslint {files}
types:
files: git diff --name-only @{push}
glob: '*.{js,ts, jsx, tsx}'
run: npx tsc --noEmit
Update the name
Attribute in package.json
package.json
:Tambahkan @username/ diawal.
{
"name": "@widianapw/react-native-multiplier",
Push to GitHub
Create a Release on GitHub
https://github.com/widianapw/react-native-multiplier/releases
Publish the Package
npm publish
Once published, the package will appear on the right side of your GitHub repository page.
Initialize a New Project (Optional)
npm init
Add .npmrc
to the Project Root
.npmrc
file with the following content://npm.pkg.github.com/:_authToken=<token>
@<username>:registry=https://npm.pkg.github.com
Install the Package
yarn add @<username>/<packagename>
With these steps, you can successfully create and use a private React Native package hosted on GitHub. This ensures your package remains secure and accessible only to authorized users.
If you require assistance with creating private packages or any other aspect of digitalizing your business, don’t hesitate to reach out to Timedoor Indonesia. Our team of experts is ready to help you transform your digital presence and enhance your business operations.
Contact us today to get started on your journey towards digital excellence!
some other blog posts you might be interested in