Vuepress构建后Markdown文件字符间出现�乱码问题咨询
Hey there, let’s tackle this weird character issue you’re seeing after running npm run vuepress build. Those � symbols popping up between every character are almost always a sign of encoding mismatches somewhere in your build pipeline. Here’s a step-by-step breakdown of the most likely fixes:
Verify your Markdown file encodings
First, make sure all your.mdsource files are saved in UTF-8 encoding (without BOM). Tools like VS Code let you check/change this via the bottom-right corner of the editor—click the current encoding label (like "GBK") and select "UTF-8", then choose "Save with encoding" to confirm. BOM (Byte Order Mark) can cause encoding conflicts in build tools, so sticking to UTF-8 without BOM is key.Explicitly set charset in VuePress config
Even though VuePress defaults to UTF-8, explicitly defining the charset in yourconfig.jscan prevent environment-specific encoding overrides. Add this to your config:module.exports = { head: [ ['meta', { charset: 'utf-8' }], // Keep your existing head configurations here ] }Fix your terminal’s encoding (Windows users especially)
If you’re building on Windows, the default terminal (CMD/PowerShell) often uses a non-UTF-8 encoding (like GBK or CP1252). This can mess up how VuePress reads your source files. Run this command in your terminal before building to switch to UTF-8:chcp 65001Then re-run
npm run vuepress build.Clear VuePress cache and rebuild
Cached files might be holding onto corrupted encoding data. Delete the cache folder and rebuild from scratch:# For macOS/Linux rm -rf node_modules/.cache/vuepress # For Windows (PowerShell) Remove-Item -Recurse -Force node_modules/.cache/vuepressAlternatively, use the
--no-cacheflag to skip caching entirely during build:npm run vuepress build --no-cacheCheck for problematic plugins
Third-party VuePress plugins (especially those that process Markdown content) can sometimes introduce encoding issues. Try temporarily disabling all non-essential plugins, then rebuild. If the problem goes away, re-enable plugins one by one to find the culprit.
Once you’ve tried these steps, open the generated dist/index.html in a text editor and confirm its encoding is UTF-8. You can also check in your browser (Chrome: Right-click → View page info → Encoding) to ensure the page is served with UTF-8.
内容的提问来源于stack exchange,提问作者quinlo

