← 返回命令列表

Linux command

npm-run-script 命令

网络

复制后可按需替换文件名、目录或参数。

常用示例

Run an npm script

npm run [script-name]

Pass arguments

npm run [script] -- [--flag] [value]

List available scripts

npm run

Run a script in every workspace

npm run [script] --workspaces

Run a script in one workspace

npm run [script] -w [package-name]

Skip missing scripts

npm run [script] --if-present

Run quietly

npm run [script] --silent

说明

npm run-script runs scripts defined in the scripts field of package.json. npm run is the common alias. Without arguments it lists the available scripts along with their commands. Any executable installed into node_modules/.bin is added to $PATH for the duration of the script, so dependency-provided binaries can be invoked by bare name. Arguments after -- are appended to the script command but are not forwarded to pre/post lifecycle scripts.

参数

--silent
Suppress non-error output.
--if-present
Exit successfully (no error) when the named script is not defined.
--ignore-scripts
Do not run pre- and post-hook scripts (e.g. prestart, poststart).
--foreground-scripts
Stream script stdout/stderr directly instead of capturing it.
--script-shell _SHELL_
Use a specific shell to execute the script (default /bin/sh on Unix, cmd.exe on Windows).
-w, --workspace _NAME_
Run the script in the given workspace. May be repeated.
--workspaces
Run the script in every configured workspace.
--include-workspace-root
In combination with --workspaces, also run the script in the repository root.
--
Everything after -- is passed as arguments to the script itself.

FAQ

What is the npm-run-script command used for?

npm run-script runs scripts defined in the scripts field of package.json. npm run is the common alias. Without arguments it lists the available scripts along with their commands. Any executable installed into node_modules/.bin is added to $PATH for the duration of the script, so dependency-provided binaries can be invoked by bare name. Arguments after -- are appended to the script command but are not forwarded to pre/post lifecycle scripts.

How do I run a basic npm-run-script example?

Run `npm run [script-name]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does --silent do in npm-run-script?

Suppress non-error output.