当我只需要构建时,为什么 yarn 会安装开发依赖项?

Why will yarn install dev dependencies when I just need the builds?

如果我调用 yarn add <my-package>Yarn 将同时安装 <my-package> 的依赖项和 devDependencies。这是正常行为吗?

我查看了文档,但找不到阻止它安装开发依赖项(我不需要)的方法。我相信 devDependencies 是用于将源代码编译到构建脚本中的依赖项。构建我的应用程序我只需要构建。

Yarn 有一个 --production 选项,这将导致它只安装生产依赖项。这显示 here

使用--production=true(或简称--production--prod)。这确实是正常行为; Yarn 假定您处于 'development' 上下文中,除非您的 NODE_ENV 环境变量设置为 'production'.

看看 Yarn 的 documentation

所述

Not "broken" but "badly designed" --prod still downloads and "installs" dev packages IF yarn needs to resolve "full tree". Just use yarn install --production --frozen-lockfile and matching yarn.lock and --production will work as expected.

将 210 MB node_modules 删除到 70 MB,类似于 npmpnpm

NODE_ENV=production 也阻止安装 devDependencies