[NPM + React] Prepare a Custom React Hook to be Published as an npm Package

Before we publish our package, we want to make sure everything is set up correctly. We’ll cover versioning, preparing our package, adding a proper README, and updating our package.json.react

 

Using npm version:git

The reason to use npm version to prumping the version, is because it create a version commit and tag.npm

npm version patch

 

Setup a pre- and post- scripts:json

"prepare": "yarn run build",
"postpublilsh": "git push --tags"

 

peerDependenices:post

You might also need to update peerDependencies in order to info the user which verison of react is minimue required.ui

"peerDependencies": {
   "react": ">=16.8.6"
}

 

publishConfig:spa

Depend on your package name:code

// A
"name": "some-react-hooks"

//B
"name": "@zhentiw/some-react-hooks" //@<user-name>/package-name

If you are using B version, it default to a private npm package, if you want to make it public:blog

"publishConfig": {
    "access": "public"
}
相關文章
相關標籤/搜索