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

Posted answer1215

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[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.

 

Using npm version:

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

npm version patch

 

Setup a pre- and post- scripts:

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

 

peerDependenices:

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

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

 

publishConfig:

Depend on your package name:

// 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:

"publishConfig": {
    "access": "public"
}

 

以上是关于[NPM + React] Prepare a Custom React Hook to be Published as an npm Package的主要内容,如果未能解决你的问题,请参考以下文章

在 NPM 安装上触发准备

node 和 npm GitLab 的 node-sass 版本问题

npm i react-push-notification npm ERR

初始 React npm start 构建失败

在 React 项目中使用 npm 找不到命令

React 'npm start' 给我错误,对于其他项目,该命令成功执行