How to publish React-Native component to NPM?

2019-08-12 05:46发布

问题:

What are the steps to follow publish React-native component to npm? Am trying to publish sample component in NPM. Do we need to build that before? if yes, how? Please can any one tell in detail along with the commands?

回答1:

No you no need to build, just put android native code in android and ios directory and a index.js in root to refreance them, then

  • Add readme
  • give proper versioning
  • give proper name

Like this in package.json

  {

      "_from": "package-name@0.1.3",
      "_id": "package-name@0.1.3",
      "_inBundle": false,
      "_location": "/package-name",
      "_phantomChildren": {},
      "_requested": {
        "type": "version",
        "registry": true,
        "raw": "package-name@0.1.3",
        "name": "package-name",
        "escapedName": "package-name",
        "rawSpec": "0.1.3",
        "saveSpec": null,
        "fetchSpec": "0.1.3"
      },
      "_requiredBy": [
        "/"
      ],
      "_spec": "0.1.3",
      "author": {
        "name": "Your name",
        "email": "your@gmail.com"
      },
      "bugs": {
        "url": "https://github.com/bug/issues"
      },
      "dependencies": {
        "prop-types": "^15.6.0"
      },
      "description": "description about pacakge",
      "homepage": "https://github.com/#readme",
      "keywords": [
        "react-native", 
        "react",
        "dnd"
      ],
      "license": "MIT",
      "main": "index.js",
      "name": "package-name",
      "peerDependencies": {},
      "repository": {
        "type": "git",
        "url": "git+https://github.com/package-name.git"
      },
      "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1"
      },
      "version": "0.1.3"
    }