Wait seconds before running next task on scripts p

2019-06-25 13:32发布

What I want to do is when I run npm run dev to execute those both tasks I need to wait for 5 seconds until next task runs.

Run the npm run server wait for 5 seconds and then npm run client

  "scripts": {
    "start": "node ./bin/www",
    "server": "nodemon start",
    "client": "gulp",
    "dev": "concurrently 'npm run server' 'npm run client'", 
}

2条回答
贼婆χ
2楼-- · 2019-06-25 14:03

Adding to @TGrif answer, chain scripts with double ampersand && to execute them sequntially. So to execute sleep command first, put && after it and then write npm run client. So the second command(npm run client) will execute only when the first(sleep) is complete.

查看更多
你好瞎i
3楼-- · 2019-06-25 14:04

Assuming you're on Linux, you can use sleep command:

"dev": "concurrently 'npm run server' 'sleep 5 && npm run client'"
查看更多
登录 后发表回答