跳转到内容
本页面的翻译由 LLM 生成。如果你发现翻译有误,请在 GitHub 上提交 issue 告诉我们。

开始使用

varsha 是一个构建在 Astro 之上的优质网站启动模板。本指南将介绍前置条件、安装方式以及首次启动本地开发服务器。

在安装 varsha 之前,你需要:

工具最低版本备注
Node.js18.17.0 或 20.3.0+推荐使用 LTS 版本
npm9.0+Node.js 自带
代码编辑器—推荐 VS Code + Astro 扩展
Git2.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-site
cd my-varsha-site
npm install

这将创建一个 my-varsha-site 目录,包含 varsha 启动模板的全新副本(不含原始 Git 历史)。

终端窗口
git clone https://github.com/yethikrishna/web-ui-template.git my-varsha-site
cd my-varsha-site
npm install

如果使用 Git 克隆,在提交前可考虑删除原有远程并添加自己的远程仓库:

终端窗口
git remote remove origin
git remote add origin https://github.com/your-username/your-repo.git
终端窗口
npm create astro@latest -- --template yethikrishna/web-ui-template my-varsha-site
cd my-varsha-site
npm install

启动本地开发服务器:

终端窗口
npm run dev

默认情况下,varsha 运行在 http://localhost:4321。在浏览器中打开该地址即可查看网站。

开发服务器支持:

  • 热模块替换(HMR): 对 .astro、.mdx、.css、.ts 文件的修改会立即生效,无需整页刷新。
  • 本地网络访问: 添加 --host 可在本地网络中访问:npm run dev -- --host。

varsha 内置以下 npm 脚本:

脚本命令用途
devnpm run dev启动本地开发服务器
buildnpm run build生成生产构建到 ./dist/
previewnpm run preview在部署前本地预览生产构建
astronpx astro直接运行 Astro CLI 命令

运行 npm run dev 后,确认以下页面均可正常访问:

  1. varsha 首页(http://localhost:4321/)
  2. 文档页面(http://localhost:4321/docs/)
  3. 博客页面(http://localhost:4321/blog/)

如果三个页面都能正常加载,说明安装成功。

快速开始

在 5 分钟内创建并部署你的第一个自定义页面。

快速开始 →