How to change Yarn default packages directory?

雨燕双飞 提交于 2019-12-20 10:25:51

问题


When Yarn is used to install dependencies, it puts them in node-modules directory by default.

How can I change this to i.e Laravel resources folder?
Like .bowerrc is used for bower to set "directory": "resources/assets"


回答1:


yarn install --modules-folder ./resources

UPDATE: Keep an eye on this GitHub Issue as this feature is not quite stable.

UPDATE 2: From Damien's answer below, you can add --install.modules-folder "./resources" to a .yarnrc file so that you don't need to continually pass the commandline argument in for each subsequent invocation. Note that double quotes are required; without those, you will get an Invalid value type 1:25 or similar error.

You can then commit the .yarnrc to source control so that other developers on the project can use the same settings automatically.




回答2:


You can create a .yarnrc file with the following content:

--modules-folder resources

This way every yarn command will have this parameter set.




回答3:


According to Yarn Docs, you can specify directories in package.json file

{
  "directories": {
    "lib": "path/to/lib/",
    "bin": "path/to/bin/",
    "man": "path/to/man/",
    "doc": "path/to/doc/",
    "example": "path/to/example/"
  }
}

When installing your package, you can specify exact locations to put binary files, man pages, documentation, examples, etc.



来源:https://stackoverflow.com/questions/40488421/how-to-change-yarn-default-packages-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!