【问题标题】:yarn - install modules in a specific directoryyarn - 在特定目录中安装模块
【发布时间】:2017-01-28 16:54:30
【问题描述】:

当我执行$ yarn install 时,我看到./node_modules 目录被创建并且模块安装在该目录中。

我还知道--modules-folder ./directory_location 存在,一次安装在特定目录中。

在 package.json 配置中是否有始终使用特定目录进行安装的选项?

【问题讨论】:

    标签: yarnpkg


    【解决方案1】:

    我现在正在使用scripts 来执行此操作。

    我可以运行yarn run newinstall

    在 package.json 中

    {
        ...
        "scripts": {
            "newinstall": "yarn install --modules-folder ./directory_location"
        }
        ...
    }
    

    【讨论】:

    • 它仍然会创建 ./node_modules,但它只包含 .bin 文件夹。
    【解决方案2】:

    在您的根项目文件夹中创建一个.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,并提供一些额外信息。

    【讨论】:

    • 每次我运行 Yarn 命令时它仍然会创建一个 ./node_modules,但会安装在正确的位置。
    【解决方案3】:
    "scripts": {
        "postinstall": "cd subdirectory && yarn install", //exec after yarn install automatically
    }
    

    【讨论】:

    猜你喜欢
    • 2020-02-11
    • 2015-11-10
    • 1970-01-01
    • 2010-10-21
    • 2019-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-11
    相关资源
    最近更新 更多