npm run <cmd>工作缓慢 [英] npm run &lt;cmd&gt; works slow

查看:40
本文介绍了npm run <cmd>工作缓慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾经通过 Makefile 运行各种命令,但对于 nodejs 项目,package.json 更适合放置这些东西.

I used to run various commands via Makefile but for nodejs projects package.json is a more appropriate place for this stuff.

通过 npm 运行命令效果很好,但与命令时执行相比非常慢.

Running commands via npm works great but very slow comparing with a command time execution.

$ time ./node_modules/.bin/jshint . && ./node_modules/.bin/jscs .

real    0m0.759s
user    0m0.524s
sys 0m0.085s
No code style errors found.

$ time npm run lint

> @ lint /path/to/project
> jshint . && jscs .

No code style errors found.

real    0m2.246s
user    0m1.637s
sys 0m0.277s

可以加速吗?

更新.我的 package.json:

upd. My package.json:

{
  "devDependencies": {
    "jscs": "^1.12.0",
    "jshint": "^2.6.3"
  },
  "scripts": {
    "lint": "jshint . && jscs ."
  }
}

upd2. 我以错误的方式测量时间.甘特在他的评论中指出了这一点.现在这两个时间看起来很相似(相差 100 毫秒).

upd2. I measured time in the wrong way. Gant has pointed to it in his comment. Now both times look similar (100ms difference).

$ time sh -c './node_modules/.bin/jshint . && ./node_modules/.bin/jscs .'
No code style errors found.

real    0m1.704s
user    0m1.245s
sys 0m0.177s
$ time npm run lint

> @ lint /path/to/project
> jshint . && jscs .

No code style errors found.

real    0m1.822s
user    0m1.621s
sys 0m0.198s

推荐答案

这不是 npm 的错,事实上它甚至可以更准确地测量时间.

This isn't npm's fault, in fact it even measures the time more accurately.

让我们看看你做了什么.

Let's look at what you did.

time npm run lint 将调用 time,然后它会按顺序调用您的任务.time 将在 npm 退出时停止占用所需的时间,当您的任务完成运行时它将停止.这里只有轻微的开销,脚本按预期工作.

time npm run lint will invoke time, which will then invoke your tasks in order. time will stop taking the time needed when npm has quit, which it will when your tasks are done running. There is only slight overhead here and the script is working as intended.

time ./node_modules/.bin/jshint .&&./node_modules/.bin/jscs . 但是会调用 time,后者会调用 jshint.一旦 jshint 退出,time 也会退出,jscs 将不运行.这也是为什么在您的示例中输出顺序混淆的原因.

time ./node_modules/.bin/jshint . && ./node_modules/.bin/jscs . however will invoke time, which will invoke jshint. Once jshint quits, time will quit too and jscs will be run without. This is also why in your examples the order of outputs is mixed up.

要在没有 npm 的情况下获得准确的时间测量,请尝试 time sh -c './node_modules/.bin/jshint.&&./node_modules/.bin/jscs .'

To get accurate time measurements without npm, try time sh -c './node_modules/.bin/jshint . && ./node_modules/.bin/jscs .'

这篇关于npm run <cmd>工作缓慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆