RN npm私库本地debug调试
npm link
一般的node工程,官方提供npm link的方式本地调试。具体步骤如下:我有私库rn-lib 和工程rn-demo
在私库下面执行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-root
install-local 替代 npm link
https://www.npmjs.com/package/install-local
我将rn-demo 、rn-lib放在一个目录下面。
➜ rn-demo git:(master) ✗ install-local --save ../rn-lib
[install-local] installing into rn-demo
[install-local] rn-demo installed
+ [email protected]
updated 1 package in 6.556s
[install-local] Done
原理是:将../rn-lib下面的代码copy一份到rn-demo/node_modules/rn-lib
使用注意:
- install-local要在npm install后面执行。
- 每次改动代码要在原来的位置,不要在node_modules下面,改完要重新执行install-local