VS Code 开发 Hugo 网站的最佳实践
VS Code 是 Hugo 开发的最佳伴侣,配置得当能事半功倍。
通过安装 Go 扩展、markdownlint 和 Live Preview 等插件,可实现语法高亮、格式校验与实时刷新。使用工作区设置同步项目依赖,让团队成员保持一致的开发体验,从而提升整体效率。
必备扩展
Hugo 相关
- Hugo Language and Syntax Support: 提供 Hugo 模板语法高亮
- Hugo Snippets: 常用 Hugo 代码片段
Markdown 相关
- Markdownlint: 格式检查和修复
- Markdown Preview Enhanced: 增强预览功能
开发工具
- Go: Go 语言支持(用于 Hugo 主题开发)
- Prettier: 代码格式化
- Live Server: 本地服务器预览
工作区配置
创建 .vscode/settings.json 配置工作区设置:
{
"go.useLanguageServer": true,
"markdownlint.config": {
"MD001": false,
"MD013": false
},
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
任务和快捷键
配置 tasks.json 定义常用任务:
{
"version": "2.0.0",
"tasks": [
{
"label": "Hugo Server",
"type": "shell",
"command": "hugo",
"args": ["server", "-D"],
"group": "build"
},
{
"label": "Build Site",
"type": "shell",
"command": "npm",
"args": ["run", "build"],
"group": "build"
}
]
}
本站实践
本站的 VS Code 配置包括:
- 扩展同步: 使用 Settings Sync 同步扩展
- 格式化: Prettier + markdownlint 自动格式化
- 调试: 配置 Hugo 调试任务
- 主题: 使用 Hugo 主题专用扩展
示例配置:
// 本站工作区设置片段
{
"hugo.server.port": 8089,
"hugo.build.minify": true,
"editor.quickSuggestions": {
"strings": true
}
}
总结
通过合理的 VS Code 配置,可以显著提升 Hugo 开发效率。本站的实践展示了团队协作和个人开发的最佳平衡。