【问题标题】:Will Yarn consider the lock files of dependencies?Yarn 会考虑依赖的锁文件吗?
【发布时间】:2016-10-19 09:26:35
【问题描述】:

我有一个内部脚手架应用程序,为此我创建了一个yarn.lock 文件。现在,这个应用程序将被其他 Node 应用程序使用。 Yarn 在为主应用安装依赖时会考虑其依赖的锁文件吗?

【问题讨论】:

    标签: yarnpkg


    【解决方案1】:

    开箱即用,答案将是

    但是有个办法。如果您看到this 讨论,则提供了使用

    的建议
    yarn add file:path-to-submodule
    

    在我看来,这是一种处理子模块包的更具确定性的方法。所以你可以这样做:

    mkdir module && cd module
    yarn init
    mkdir submodule && cd submodule
    yarn init                // Name this package 'submodule'
    yarn add express         // Just an example package
    rm -rf node_modules      // To see if node_modules is going to be regenerated
    ls                       // package.json yarn.lock
    cd ..
    yarn init
    yarn add react           // Another sample module
    yarn add file:submodule  // Adds submodule as a local dependency
    yarn 
    cd node_modules && ls    // Both react & express and their dependencies are now in module/node_modules
    cd .. && cd submodule && ls // No node_modules created within /submodules
    

    在这里你看到你已经成功地在你的主模块中创建了一个本地子模块,使用yarn add

    使用这种方法的优点是:

    • 每个包只保存一个副本
    • 所有包都在一个位置(只有一个 node_modules 文件夹)
    • 您可以选择哪些包是子模块,哪些不是,所以没有意外
    • 没有将秘密子模块添加到您的包中,只是因为它们在您的包文件夹中的位置

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-17
      • 2017-11-09
      • 2012-09-10
      • 2018-08-29
      • 2023-03-03
      • 1970-01-01
      相关资源
      最近更新 更多