Yarn 2:如何从 `node_modules/.bin` 目录中 运行 一个脚本?
Yarn 2 : how to run a script from the `node_modules/.bin` directory?
如何使用 Yarn 2 运行 来自 node_modules/.bin
目录的脚本?
例子
假设我需要 运行 位于该目录中的“eslint”脚本
node_modules
├── .bin
│ ├── eslint
使用 NPM,我可以 运行 npx eslint
到 运行 可执行文件。如何使用 Yarn 2 实现此目的?
它和经典的 Yarn 一样,运行 这个:
yarn eslint
参考:https://yarnpkg.com/cli/run#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.
如果您想忽略任何用户定义的脚本并只检查二进制文件,您可以通过 -B
option.
还有yarn exec
:
yarn exec eslint
如何使用 Yarn 2 运行 来自 node_modules/.bin
目录的脚本?
例子
假设我需要 运行 位于该目录中的“eslint”脚本
node_modules
├── .bin
│ ├── eslint
使用 NPM,我可以 运行 npx eslint
到 运行 可执行文件。如何使用 Yarn 2 实现此目的?
它和经典的 Yarn 一样,运行 这个:
yarn eslint
参考:https://yarnpkg.com/cli/run#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.
如果您想忽略任何用户定义的脚本并只检查二进制文件,您可以通过 -B
option.
还有yarn exec
:
yarn exec eslint