RN開發環境的npm私庫本地debug調試

RN npm私庫本地debug調試

npm link

通常的node工程,官方提供npm link的方式本地調試。具體步驟以下: 我有私庫rn-lib 和工程rn-demonode

在私庫下面執行npm link,將全局的rn-lib指向本地私庫
➜  rn-lib git:(develop_ts_common) ✗ npm link  
/usr/local/lib/node_modules/rn-lib -> /Users/msh/Desktop/rn-lib

在rn-demo下面執行npm link rn-lib,將node_modules的rn-lib指向全局
➜  rn-demo git:(master) ✗ npm link rn-lib
/Users/msh/Desktop/rn-demo/node_modules/rn-lib -> /usr/local/lib/node_modules/rn-lib -> /Users/msh/Desktop/rn-lib

RN 不能使用npm link

error: bundling failed: Error: Expected path `/Users/jgallaso/Projects/aerogear/aerogear-react-native-core/index.js` to be relative to one of the project roots

metro-bundler-error-expected-path-to-be-relative-to-one-of-the-project-rootreact

install-local 替代 npm link

https://www.npmjs.com/package/install-localgit

我將rn-demo 、rn-lib放在一個目錄下面。

➜  rn-demo git:(master) ✗ install-local --save ../rn-lib 
[install-local] installing into rn-demo
[install-local] rn-demo installed
+ rn-lib@1.0.0-beta0
updated 1 package in 6.556s

[install-local] Done

原理是:將../rn-lib下面的代碼copy一份到rn-demo/node_modules/rn-libnpm

使用注意:react-native

  1. install-local要在npm install後面執行。
  2. 每次改動代碼要在原來的位置,不要在node_modules下面,改完要從新執行install-local
相關文章
相關標籤/搜索