npm run
パッケージと実行環境
書き方
npm run <script> [-- <args>]package.jsonのscriptsに書いた命令を実行します。スクリプトへ渡す引数の前には--が必要で、runなしで呼べるのはstartとtestだけです。
よく使うオプション
| オプション | 意味 |
|---|---|
| -- | everything after it goes to the script, not to npm |
| --if-present | exit quietly when the script is missing |
| -w <workspace> | run it in one workspace |
| --workspaces | run it in every workspace |
| -s | hide npm own output |
例
npm run buildruns the build script from package.json
npm run test -- --watchpasses --watch to the test runner, not to npm
npm runwith no name, lists the scripts that exist
何をどこに入れるかが問題です。このプロジェクトの中か、マシン全体かを先に決めてください。
読み方
- 角括弧 [ ] は省いてよい部分です。
- 三点 … は複数並べられるという意味です。
- オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。
よくある質問
Q. npm run は何をしますか。
package.jsonのscriptsに書いた命令を実行します。スクリプトへ渡す引数の前には--が必要で、runなしで呼べるのはstartとtestだけです。
Q. どう打ちますか。
npm run <script> [-- <args>] — 角括弧は省いてよい部分です。
Q. よく使うオプションはいくつですか。
ここにまとめたのは5個です。全部は man npm にあります。このコマンドはパッケージと実行環境の仲間です。
関連するコマンド
man ページ: man npm-run