通常的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
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
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