This article is reproduced with authorization from the author. HD Superman, originally linked: Taro develops small programs, high CPU usage leads to the lag problem

Problem description

npm run dev:weapp
Copy the code

Boot takes up a lot of CPU resources, resulting in the overall computer lag.

Repetition steps

  1. Run the following command to restart the vm: NPM run dev: retry p
  2. Open task Manager to view process information

System information

Taro v2.1.4

Taro CLI 2.1.4 Environment Info: System: OS: Windows 10 Binaries: Node: 10.15.0 -d: Program Files\ Nodejs \ node.exe NPM: 6.4.1 – D: \ \ Program Files \ nodejs \ NPM CMD

Positioning reason

  • Switching editor vscode or webstorm has no effect
  • Closed wechat developer tool, no effect

Since Taro’s development supports hot updates, it is suspected that Webpack Watch listens to all node_modules files, which leads to too many file handles being opened and CPU resources being consumed.

Taro’s update to the file on node_modules is not necessary. Taro’s update to the file on node_modules is not necessary. (Found the reason)

Problem solving

Webpack provides the watchOptions option to modify the listening configuration.

  • WatchOptions: {ignored: /node_modules/} no effect. Listen to the file under node_modules

  • Try modifying the webpackChain configuration of the Mini configuration

    mini: { webpackChain (chain, webpack) { chain.merge({ watchOptions: { ignored: /node_modules/}, }); }},Copy the code

Dist /index. Js file in @tarojs/mini-runner. Ignore: {watchOptions: {ignored: /node_modules/}, the CPU usage returns to normal. The problem is rectified.