yarn run

執行定義在package內的腳本

您可以在 package.json 檔中定義 腳本

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

如果你有在你的package中定義 腳本 ,此命令將執行指定的 [script]。例如︰

yarn run test

執行此命令將執行在你 package.json 檔中名為 "test" 的腳本。

You can pass additional arguments to your script by passing them after the script name.

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.

If you want to override this command, you can do so by defining your own "env" script in package.json.

yarn run

如果你沒有指定任何的腳本給指令 yarn run,指令 run 將會列出所有可以執行的腳本。