

Once you configure the above steps, your folder structure should look as followsĢ. After that, you must re-install it in the react-native app. Whenever you make any change to your package, you have to create the build again using command – npm run build. Now, create a folder src, add the index.js file and add your component. index.js depending upon your file structure. It compresses code into ‘build’ that can be deployed in the React-Native app. Let’s create a file named and add the lines below. Babel is a compiler to convert JavaScript code into ES5 JavaScript. Note: “main” should be the same as above. Now, open the package.json file in your IDE (code editor) and install all the dependencies as below using – npm install dependency-name.īelow is an example of package.json file. At this point, a package.json file will be created. You can skip questions (by pressing enter) (it is easy to modify later). You will be prompted for the package name, version, main, keyword, etc. Now navigate into that folder directory using terminal and run command – npm init Testing the NPM package on the react-native app.įirst create a folder where package information like package.json. There are 3 phases to create and publish a package.Ģ. Steps to create and publish a react-native NPM package are as follows:

This allows developers to contribute to the NPM ecosystem. If any developer wants to share his own package on the NPM registry, then he needs to make it public. My intention behind writing this blog is to help React-native developers create their own package. NPM has over 8,00,000 packages with public access. NPM allows you to install the various public packages for the project. It was first created in 2009 as an open-source project to help JavaScript developers to easily share their code in the form of packages. Src/index.NPM is a Package Manager for Node JS. Npm install -g create-react-library & create-react-library By installing create-react-library globally and then creating a new module.We can bootstrap our project in two ways: It's really easy to get up and running using create-react-library. It has a bunch of features and the Developer Experience is really good. I've used create-react-library to bootstrap one of my previous NPM package, React Search Box. We'll be using create-react-library to bootstrap our component library. You can create unlimited public packages on NPM. Before we get started, it's recommended to create an account on NPM. You'll need a NPM account before you can publish a package there. We'll be taking inspiration from that component and convert it into a NPM package.

We'd developed a Pagination component in one of our previous posts. We'll also learn how to publish it to NPM so that other developers can use our package.

In this tutorial, we'll learn how we can create a package from a React component.
