我的博客
个人资料:
AlanThinker
AlanThinker@stk.me

npm和yarn引用本地package

软件开发 发表时间:2017-02-02 更新时间:2017-02-04

yarn也支持此特性.            

方法1:


This feature was implemented in the version 2.0.0 of npm. Example:

{
  "name": "baz",
  "dependencies": {
    "bar": "file:../foo/bar"
  }
}

Any of the following paths are also valid:

../foo/bar
~/foo/bar
./foo/bar
/foo/bar

The local package will be copied to the prefix (./node-modules).



方法2: (
优点是无需手动更新, 直接链接了原目录.  
缺点是 1. 目前在windows下有报错提示. (但实际上没错误.)
    2. react native 发布Release版本的时候会出错. (建议在发布的时候再临时修改为第一种方法)
)


 

"scripts": {
 "preinstall": "npm link mylib ../../path/to/mylib"
}

   

IP Address: 18.118.119.89