6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

npmコマンドから任意のコマンドを実行してみる

Posted at

例えば、以下の様なpackage.jsonがあったとして、

package.json
{
 ...
 "scripts": {
    ...

    "pretest":  "before_test_command",
    "test":     "test_command",
    "posttest": "after_test_command",

    ...
  },
  ...
}

npm testを実行することで pretest > test > posttestの順で指定したコマンドが実行されるのは有名な話ですが、
深遠な理由によりnpmから任意のコマンドを叩きたくなったりして、以下のようなpackage.jsonを書いて

package.json
{
 ...
 "scripts": {
    ...

    "prehoge":  "before_hoge_command",
    "hoge":     "hoge_command",
    "posthoge": "after_hoge_command",

    ...
  },
  ...
}

npm hogeとか叩いてももちろん実行されません。
そういう時はnpm run hogeと実行するとprehoge > hoge > posthogeの順で実行してくれます。

6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?