Svelte

部署你的 Svelte 应用

Plain Svelte (scaffolded with npm create vite -- --template svelte) is a normal static Vite build. SvelteKit is different by default — it expects a server — so it needs one extra step to output static files instead.

steps
  1. 01

    Plain Svelte: just build

    Run "npm run build". Like any Vite template, it writes static HTML, CSS, and JS to "dist" — nothing else to configure.

  2. 02

    SvelteKit: switch to the static adapter

    Install "@sveltejs/adapter-static", set it as the adapter in svelte.config.js, and run "npm run build". Output goes to "build" by default (configurable in the adapter options) instead of "dist".

  3. 03

    部署它

    在项目根目录运行 "npx harvis deploy dist"。首次部署无需配置、无需登录——你会立即拿到一个可访问 URL,以及一个私密认领链接,方便你随时把网站关联到一个免费账号。

一条命令部署 Svelte

构建你的项目,然后把输出文件夹交给 harvis。首次部署无需账号——你会拿到一个可访问链接,以及一个用于以后管理网站的私密认领链接。

terminal
npm run build
npx harvis deploy dist

更喜欢拖拽文件而不是用终端?构建项目后,把输出文件夹拖到这里即可用同样的方式发布。

Svelte 部署常见问题

How do I know if my project is plain Svelte or SvelteKit?

Check package.json: SvelteKit projects depend on "@sveltejs/kit" and have a "src/routes" folder. Plain Svelte (the Vite template) doesn't — it's a single App.svelte with no server-side concept at all.

SvelteKit's adapter-static warns about "prerender" — what does that mean?

adapter-static needs every route pre-rendered at build time since there's no server to render them on request. Add "export const prerender = true" to your root +layout.js (or per-route) to opt every page in.

把 Svelte 应用部署到 harvis 真的免费吗?

是的,无需信用卡。免费额度为每个网站 500 个文件、50 MB,对于一个静态 Svelte 构建产物来说绰绰有余。已发布的网站不会过期——会一直在线,直到你删除它们。

已部署的 Svelte 网站可以使用我自己的域名吗?

每个网站都会获得一个免费的 harvis.dev 地址,认领之后你可以在仪表盘中选择自己的子域名——比如 my-app.harvis.dev,而不是一个随机地址。把你已经拥有的域名(比如 mystore.com)指向该网站,目前还不支持。

这和把 Svelte 部署到 Vercel 或 Netlify 有什么不同?

Vercel 和 Netlify 的核心是连接一个 Git 仓库,在他们的服务器上运行构建,并通过一个仪表盘进行配置。harvis 跳过了这一切:你在本地(或自己的 CI 中)构建,对输出文件夹运行一条命令,就能拿到一个链接——无需项目搭建,直到你想保留这个网站才需要账号。

other frameworks

要部署别的东西?

各处的方法都一样——先构建,然后用 npx harvis deploy 部署输出。