重要提示: 此中文文档针对的是 Yarn 的最新版本。
有关 1.x 版本的中文文档,请点击进入 classic.yarnpkg.cn。
Yarn
yarn addyarn binyarn cache cleanyarn config getyarn config setyarn config unsetyarn configyarn constraints queryyarn constraints sourceyarn constraintsyarn dedupeyarn dlxyarn execyarn explain peer-requirementsyarn explainyarn infoyarn inityarn installyarn linkyarn nodeyarn npm audityarn npm infoyarn npm loginyarn npm logoutyarn npm publishyarn npm tag addyarn npm tag listyarn npm tag removeyarn npm whoamiyarn packyarn patch-commityarn patchyarn plugin checkyarn plugin import from sourcesyarn plugin importyarn plugin listyarn plugin removeyarn plugin runtimeyarn rebuildyarn removeyarn runyarn searchyarn set resolutionyarn set version from sourcesyarn set versionyarn stageyarn unlinkyarn unplugyarn upyarn upgrade-interactiveyarn version applyyarn version checkyarn versionyarn whyyarn workspaceyarn workspaces focusyarn workspaces foreachyarn workspaces list

yarn run

Run a script defined in the package.json.

Usage

$> yarn run <scriptName> ...

Examples

Run the tests from the local workspace :

yarn run test

Same thing, but without the "run" keyword :

yarn test

Inspect Webpack while running :

yarn run --inspect-brk webpack

Options

Definition
Description

--inspect

Forwarded to the underlying Node process when executing a binary

--inspect-brk

Forwarded to the underlying Node process when executing a binary

-T,--top-level

Check the root workspace for scripts and/or binaries instead of the current one

-B,--binaries-only

Ignore any user defined scripts and only check for binaries

--require #0

Forwarded to the underlying Node process when executing a binary

Details

This command will run a tool. The exact tool that will be executed will depend on the current state of your workspace:

  • If the scripts field from your local package.json contains a matching script name, its definition will get executed.

  • Otherwise, if one of the local workspace's dependencies exposes a binary with a matching name, this binary will get executed.

  • Otherwise, if the specified name contains a colon character and if one of the workspaces in the project contains exactly one script with a matching name, then this script will get executed.

Whatever happens, the cwd of the spawned process will be the workspace that declares the script (which makes it possible to call commands cross-workspaces using the third syntax).