虚拟机中npm run watch-poll占用cpu过高

在虚拟机中做laravel+vue的开发,为了在win下更改后虚拟机能实时编译,需要用到npm run watch-poll。
但是缺点就是cpu占用蹭蹭往上涨,一直稳定在50~60%。我也是听着风扇不停的转,才发现的。

这里(点击查看)有人就建议在win下npm run watch,composer在虚拟机中就可以了。
毕竟在win下,占用cpu很低的。
本来是想放弃的,但是觉得这样开发好别扭啊。

解决方案

最后,在这里(点击查看)找到了答案

# Polling will definitely push your CPU more. Try setting a longer poll interval. Within your package.json file, update your watch-poll script to use a five second interval, like this:
"watch-poll": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --watch-poll=5000 --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",

在 laravel5.6 的package.json中,只需要更改

"watch-poll": "npm run watch --watch-poll=5000",

就可以了。cpu占用率稳定在3~10%,编译的时候升到二三十,然后就又会降下来。
这应该就可以了。

2 评论

发表评论

电子邮件地址不会被公开。 必填项已用*标注