【发布时间】:2017-01-28 16:54:30
【问题描述】:
当我执行$ yarn install 时,我看到./node_modules 目录被创建并且模块安装在该目录中。
我还知道--modules-folder ./directory_location 存在,一次安装在特定目录中。
在 package.json 配置中是否有始终使用特定目录进行安装的选项?
【问题讨论】:
标签: yarnpkg
当我执行$ yarn install 时,我看到./node_modules 目录被创建并且模块安装在该目录中。
我还知道--modules-folder ./directory_location 存在,一次安装在特定目录中。
在 package.json 配置中是否有始终使用特定目录进行安装的选项?
【问题讨论】:
标签: yarnpkg
我现在正在使用scripts 来执行此操作。
我可以运行yarn run newinstall
在 package.json 中
{
...
"scripts": {
"newinstall": "yarn install --modules-folder ./directory_location"
}
...
}
【讨论】:
在您的根项目文件夹中创建一个.yarnrc 文件,旁边是package.json。
在.yarnrc 内部,添加以下内容:
# install modules here
--modules-folder apps/my_cool_application/static/
# Note: target directory goes after `--modules-folder` {{target dir}}
在本例中,运行yarn install会将所有模块安装到./apps/my_cool_application/static中,例如,
Bootstrap,安装后会住在:./apps/my_cool_application/static/bootstrap
注意:如果您的node_modules 文件夹当前存在,您可以在创建.yarnrc 并运行yarn install 后将其删除,以便将所有包重新下载到目标目录中。
This site had a helpful walk through,并提供一些额外信息。
【讨论】:
"scripts": {
"postinstall": "cd subdirectory && yarn install", //exec after yarn install automatically
}
【讨论】:
subdirectory/node_modules,如果有人安装你的模块docs.npmjs.com/misc/scripts#descriptionpostinstall运行