【问题标题】:Does npx use yarn?npx 使用纱线吗?
【发布时间】:2020-11-25 16:50:07
【问题描述】:

今天我使用 CRA 创建了一个 reactjs 起始模板:

npx create-react-app my-app --template redux

这在我的项目中创建了两个文件:package.jsonyarn.lock

我很困惑为什么在我在项目中 cd 并运行 yarn start 之后它会起作用,即使我没有使用 yarn create react-app my-app 启动项目。

我有两个问题:

  • 为什么会生成 yarn.lock?
  • 两者有什么区别
    • npx create-react-app my-app --template redux
    • yarn create react-app my-app --template redux 考虑到它们具有相同的效果。

【问题讨论】:

    标签: reactjs yarnpkg npx


    【解决方案1】:

    npx create-react-app 执行create-react-app 二进制文件,create-react-app 使用yarn 创建您的项目(如果安装了 yarn)。这就是为什么您可以看到 yarn.lock 以及为什么 yarn-start 有效。

    npx create-react-appyarn create react-app 之间的区别

    它们都执行create-react-app 二进制文件。 create-react-app 是决定是否要使用纱线创建项目的人。要在create-react-app 中使用npm,请使用--use-npm 标志(无论您使用npxyarndirectly 执行create-react-app,如果您希望它使用npm,则应设置它。 ):

    create-react-app my-project --use-npm
    

    【讨论】:

    • create-react-app uses yarn 解释它。
    【解决方案2】:

    create-react-app 使用 yarn 进行设置(如果已安装)。

    因此,如果您的系统中已经安装了 yarn,那么 npx create-react-app my-app --template reduxyarn create react-app my-app --template redux 会给您相同的最终结果。

    并且它已经安装在您的系统中,这就是它生成 yarn.lock 而不是 package.lock 的原因。

    yarn.lock is generated to keep the exact version of the installed packages.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-05
      • 2021-06-04
      • 2019-03-09
      • 1970-01-01
      • 2017-05-26
      • 2020-07-26
      • 2020-11-04
      • 2021-09-05
      相关资源
      最近更新 更多