Jeanmarie Jackman

Jan 26, 2021

5 min read

Homegrown React Libraries

While working on my React project, I researched several npm calendar libraries, including one of which I implemented. But also, came to discover a way that one can grow one’s own garden of npm libraries and save time for future projects.

Start by creating a new react app:

Then delete everything inside src, and create a new index.js

Add a new folder into src, called lib, and then all the components you make can be published to npm from there, for example:

You can style it inline or add an import css file:

Then, you can publish to npm from src/index.js

To get ready to publish to npm, you also need to create using the command and create a file in the root of the project with the following contents:

Then in order to get to be able to work, inside the package.json, replace the build script with

remove from package.json ` and then add to package.json

Then delete the readme text, and add what you need to explain your component:

Then, finally, publish to npm by running the command: and boom! now you can install into any future Create React app using command `npm install component-library`