npm link 命令解析
2014-02-27 18:39
344 查看
文字转的
对开发者而言,这算是最有价值的命令。假设我们开发了一个模块叫 test ,然后我们在 test-example 里引用这个模块 ,每次 test 模块的变动我们都需要反映到 test-example 模块里。不要担心,有了 npm link 命令一切变的非常容易。
首先我们需要把 test 链接到全局模式下:
那么 test 的模块将被链接到 $PREFIX/lib/node_modules 下,就像我的机器上 $PREFIX 指到 /usr/local ,那么 /usr/local/lib/node_modules/test 将会链接到 ~/work/node/test 下。执行脚本 bin/test.js 被链接到 /usr/local/bin/test 上。
接下来我们需要把 test 引用到 test-example 项目中来:
npm link test 命令会去 $PREFIX/lib/node_modules 目录下查找名叫 test 的模块,找到这个模块后把 $PREFIX/lib/node_modules/test 的目录链接到 ~/work/node/test-example/node_modules/test 这个目录上来。
现在任何 test 模块上的改动都会直接映射到 test-example 上来。
再比如假设我们开发很多应用,每个应用都用到 Coffee-script :
原理 linux的系统下会自动执行ln -s 命令来创建一个软连接指向你的全局包路径
这么一定段文字有点绕。下面用画图解释一下
例:
test-example 使用需要 test模块,就是上文红色文字
![](http://images.cnitblog.com/i/329668/201402/271908543938172.png)
例2 :每个应用都用到 Coffee-script 上文蓝色字
对开发者而言,这算是最有价值的命令。假设我们开发了一个模块叫 test ,然后我们在 test-example 里引用这个模块 ,每次 test 模块的变动我们都需要反映到 test-example 模块里。不要担心,有了 npm link 命令一切变的非常容易。
首先我们需要把 test 链接到全局模式下:
cd ~/work/node/test # 进入test模块目录 npm link # 创建链接到$PREFIX/lib/node_modules
那么 test 的模块将被链接到 $PREFIX/lib/node_modules 下,就像我的机器上 $PREFIX 指到 /usr/local ,那么 /usr/local/lib/node_modules/test 将会链接到 ~/work/node/test 下。执行脚本 bin/test.js 被链接到 /usr/local/bin/test 上。
接下来我们需要把 test 引用到 test-example 项目中来:
cd ~/work/node/test-example # 进入test-example模块目录 npm link test # 把全局模式的模块链接到本地
npm link test 命令会去 $PREFIX/lib/node_modules 目录下查找名叫 test 的模块,找到这个模块后把 $PREFIX/lib/node_modules/test 的目录链接到 ~/work/node/test-example/node_modules/test 这个目录上来。
现在任何 test 模块上的改动都会直接映射到 test-example 上来。
再比如假设我们开发很多应用,每个应用都用到 Coffee-script :
npm install coffee-script -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过去的项目同时更新了。
原理 linux的系统下会自动执行ln -s 命令来创建一个软连接指向你的全局包路径
这么一定段文字有点绕。下面用画图解释一下
例:
test-example 使用需要 test模块,就是上文红色文字
![](http://images.cnitblog.com/i/329668/201402/271908543938172.png)
例2 :每个应用都用到 Coffee-script 上文蓝色字
![](http://images.cnitblog.com/i/329668/201402/271913064771291.png)
相关文章推荐
- 《自己动手写操作系统》源码解析——第三章pmtest5.asm
- jbpm取得节点Transition
- DPM2012学习(十二),备份Exchange2010数据库
- 自己动手写操作系统源码剖析——第三章 pmtest4.asm
- 玩JBPM6调试报错
- 元祖签约K2 BPM,引领绿色健康食品!
- 分析技术在PMP中的应用
- IPMI配置使用步骤
- 几种互联网产品经理分析产品的思路
- 用到的AM/PM commands
- [转]SQL Server 2005 Integration Services (SSIS) (3) - Business Intelligence Development Studio
- 修改、重新生成和安装srpm源码包
- 作为产品经理,你犯过的最大的错误是哪几个?
- PMP介绍
- fpm来制作rpm包
- Agile Software Development --敏捷软件开发
- 优秀产品经理指南
- 基于jbpm4工作流技术 运行环境搭建
- jbpm5.4安装到mySql
- 基于MPMoviePlayerController实现的视频播放的总结