使用Hexo部署博客时MacBook Pro CPU占用过高:原因与解决方法咨询
Hexo Deployment Causing High CPU Usage on MacBook Pro – Fixes & Root Causes
Hey there, I’ve had several fellow Hexo users reach out about this exact issue—deploying their blog sends their MacBook Pro’s CPU usage through the roof, and I even dealt with it myself when I ran a 500+ post Hexo site. Let’s break down what’s usually going on and the practical fixes to tame that CPU spike.
Common Reasons Behind the High CPU Usage
- Full Static Site Generation Overhead: When you run
hexo deploy, Hexo automatically runshexo generatefirst. If your blog has tons of posts, unoptimized media, or a theme with complex templating (think nested partials, custom filters, or post-processing), Node.js has to crunch through a massive amount of data. Older MacBook models especially struggle with this, as the generation process is single-threaded in many cases. - Node.js & Hexo Version Misalignment: Using an outdated or incompatible Node.js version (Hexo recommends LTS releases) can lead to inefficient code execution. Outdated Hexo versions might also lack performance optimizations that newer releases include.
- Bloated Themes or Plugins: Some third-party themes or plugins are poorly optimized. For example, a theme that reprocesses every image on every deploy, or a plugin that scans all your files repeatedly without caching, can push CPU usage to 100%.
- Corrupted or Unused Cache: Hexo uses caching to speed up subsequent builds, but if the cache gets corrupted (or you accidentally disabled it), it will do a full rebuild every time—way more CPU-intensive than incremental builds.
Practical Fixes to Reduce CPU Load
- Use Incremental Builds: Instead of letting Hexo rebuild everything each time, run
hexo generate --incrementalbefore deploying. This only regenerates files you’ve modified, cutting down CPU usage drastically. For deployments, you can combine it:hexo deploy --incremental. - Update Node.js & Hexo: Make sure you’re on a Node.js LTS version (check Hexo’s official requirements for the latest compatible release). Then update Hexo and its CLI with:
Newer versions often include performance tweaks for generation and deployment.npm update hexo-cli hexo - Audit Your Themes & Plugins: Disable plugins one by one and run a deploy to see which one causes the CPU spike. For themes, switch temporarily to Hexo’s default Landscape theme—if CPU usage drops, your custom theme is the culprit. Look for lightweight themes that avoid unnecessary post-processing, or optimize your current theme by removing unused features.
- Reset the Cache: If the cache is corrupted, wipe it clean and rebuild:
Subsequent deploys will use the fresh cache to avoid full rebuilds.hexo clean hexo generate - Pre-Optimize Media Files: Stop letting Hexo process images during deployment. Compress your images beforehand with tools like ImageOptim or Squoosh, and avoid plugins that run image optimization on every deploy. This cuts out a huge chunk of CPU work.
- Offload Generation to CI/CD: If you’re using Git-based deployment (like GitHub Pages), set up a CI/CD service to handle the
hexo generatestep on a remote server. This way, your MacBook doesn’t have to do the heavy lifting—you just push your source files, and the CI/CD generates and deploys the static site for you.
Hope these tips help you get that CPU usage under control. I used the incremental build and CI/CD trick on my old MacBook Pro, and it went from struggling through 10-minute deployments to finishing in seconds without maxing out the CPU.
内容的提问来源于stack exchange,提问作者ByiProX




