推荐:degit
使用 degit 下载不含 Git 历史的最新模板,获得干净的起始状态。
varsha 是一个构建在 Astro 之上的优质网站启动模板。本指南将介绍前置条件、安装方式以及首次启动本地开发服务器。
在安装 varsha 之前,你需要:
| 工具 | 最低版本 | 备注 |
|---|---|---|
| Node.js | 18.17.0 或 20.3.0+ | 推荐使用 LTS 版本 |
| npm | 9.0+ | Node.js 自带 |
| 代码编辑器 | — | 推荐 VS Code + Astro 扩展 |
| Git | 2.0+ | 克隆和部署所需 |
检查 Node.js 版本:
node --version选择以下任一方式创建新的 varsha 项目。
推荐:degit
使用 degit 下载不含 Git 历史的最新模板,获得干净的起始状态。
Git clone
如需贡献代码或保留 Git 历史,克隆完整仓库。
npm create
使用 Astro CLI 并指定 varsha 模板标志。
npx degit yethikrishna/web-ui-template my-varsha-sitecd my-varsha-sitenpm install这将创建一个 my-varsha-site 目录,包含 varsha 启动模板的全新副本(不含原始 Git 历史)。
git clone https://github.com/yethikrishna/web-ui-template.git my-varsha-sitecd my-varsha-sitenpm install如果使用 Git 克隆,在提交前可考虑删除原有远程并添加自己的远程仓库:
git remote remove origingit remote add origin https://github.com/your-username/your-repo.gitnpm create astro@latest -- --template yethikrishna/web-ui-template my-varsha-sitecd my-varsha-sitenpm install启动本地开发服务器:
npm run dev默认情况下,varsha 运行在 http://localhost:4321。在浏览器中打开该地址即可查看网站。
开发服务器支持:
.astro、.mdx、.css、.ts 文件的修改会立即生效,无需整页刷新。--host 可在本地网络中访问:npm run dev -- --host。varsha 内置以下 npm 脚本:
| 脚本 | 命令 | 用途 |
|---|---|---|
dev | npm run dev | 启动本地开发服务器 |
build | npm run build | 生成生产构建到 ./dist/ |
preview | npm run preview | 在部署前本地预览生产构建 |
astro | npx astro | 直接运行 Astro CLI 命令 |
运行 npm run dev 后,确认以下页面均可正常访问:
http://localhost:4321/)http://localhost:4321/docs/)http://localhost:4321/blog/)如果三个页面都能正常加载,说明安装成功。