Help us understand the problem. What is going on with this article?

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

More than 3 years have passed since last update.

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

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\""
  }
}

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

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした