如果开发一个模块test,在example里引用这个模块,每次test模块的变动都需要反映到example里;可以使用npm link命令;
- 把test链接到全局模式下: cd ~/memo/test //进入test模块下 npm link //’/Users/username/memo/test’ -> ‘/usr/local/lib/node_modules/test’
- 把test引用到example项目中: cd ~/memo/example npm link test //把全局模式的模块链接的本地; npm link test 命令会去/usr/local/lib/node_modules下查找test模块, 找到以后把’/usr/local/lib/node_modules/test’目录链接到~/memo/example上。
比如每个应用都会用到 Coffee-script:
npm install -g coffee-script
cd ~/work/Node/test #进入开发目录
npm link coffee-script #把全局模式的 coffee-script 模块链接到本地的Node modules 下
cd .. /test-example #进入另外的一个开发目录
npm link coffee-script #把全局模式的 coffee-script 模块链接到本地
npm update coffee-script -g #更新全局模式的 coffee-script,所有 link 过去的项目同时更新了。