LoginSignup
47
26

More than 5 years have passed since last update.

npmのコマンドを同時実行する

Posted at

ビルドしつつサーバーを立ち上げたい

npmのコマンドを書いている時、複数のコマンドを同時に実行したくなることがあるかと思います。例えばbuild --watchしつつserver upしたくなる時。何も考えず&&で繋いでしまうと、build --watch && server upではwatchが終了しないかぎりローカルサーバーが立ち上がらない事になってしまい、やりたいこととは違ってしまうかと思います。

そんな時、便利なのがconcurrently https://www.npmjs.com/package/concurrently というパッケージです。

$ npm install concurrently -D

でインストール、使い方は、

$ concurrently "command1 arg" "command2 arg"

といった感じに同時に実行したいコマンドをダブルクオーテーションでくくってやればいいだけ。なのでnpm startでビルドしつつ監視、サーバーも立ち上げるには、

package.json
{
  "scripts": {
    "start": "build && concurrently \"build --watch\" \"server up\""
  }
}

と言った具合にできてしまいます。とても簡単ですね。

47
26
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
47
26