yarn run

运行一个定义好的包脚本。

你可以在你的 package.json 文件中定义 scripts

{
  "name": "my-package",
  "scripts": {
    "build": "babel src -d lib",
    "test": "jest"
  }
}
yarn run [script] [<args>]

如果你已经在你的包里定义了 scripts,这个命令会运行指定的 [script]。例如:

yarn run test

运行这个命令会执行你的 package.json 里名为 "test" 的脚本。

您可以在脚本名称后放置要传递给您的脚本的额外参数。

yarn run test -o --watch

运行这个命令会执行 jest -o --watch

[script] 也可以是任何 node_modules/.bin/ 里本地安装的可执行程序。

It’s also possible to leave out the run in this command, each script can be executed with its name:

yarn test -o --watch

Running this command will do the same as yarn run test -o --watch. Note that built-in cli commands will have preference over your scripts, so you shouldn’t always rely on this shortcut in other scripts

yarn run env

Running this command will list environment variables available to the scripts at runtime.

如果想覆盖此命令,可以在 package.json 中定义自己的 "env" 脚本。

yarn run

如果你不指定一个脚本给 yarn run 命令,run 命令会列出包里所有可运行的脚本。