如果您的首选环境还没有适配器,您可以自己构建。我们建议查看[类似您平台的适配器源代码](https://github.com/sveltejs/kit/tree/main/packages)作为起点进行复制。 适配器包实现了以下 API,该 API 创建了一个`适配器`: ```js // @errors: 2322 // @filename: ambient.d.ts type AdapterSpecificOptions = any; // @filename: index.js // ---cut--- /** @param {AdapterSpecificOptions} options */ export default function (options) { /** @type {import('@sveltejs/kit').Adapter} */ const adapter = { name: 'adapter-package-name', async adapt(builder) { // adapter implementation }, async emulate() { return { async platform({ config, prerender }) { // the returned object becomes `event.platform` during dev, build and // preview. Its shape is that of `App.Platform` } } }, supports: { read: ({ config, route }) => { // Return `true` if the route with the given `config` can use `read` // from `$app/server` in production, return `false` if it can't. // Or throw a descriptive error describing how to configure the deployment } } }; return adapter; } ``` 在这些中,`名称`和`适配`是必需的。`模拟`和`支持`是可选的。 在`adapt`方法中,适配器应该做很多事情: * 清理构建目录 * 编写 SvelteKit 输出,使用`builder.writeClient`、`builder.writeServer`和`builder.writePrerendered` * 输出代码,使其: * 导入 `服务器` 从 `${builder.getServerDirectory()}/index.js` * 实例化应用程序,使用 `builder.generateManifest({ relativePath })` 生成的清单 * 监听来自平台的请求,如有必要,将其转换为标准 [`请求`](https://developer.mozilla.org/en-US/docs/Web/API/Request),调用 `server.respond(request, { getClientAddress })` 函数生成 [`响应`](https://developer.mozilla.org/en-US/docs/Web/API/Response) 并以之响应 * 暴露任何平台特定信息到 SvelteKit,通过传递给 `platform` 选项的 `server.respond`。 * 全局适配 `fetch` 以在目标平台上运行,如有必要。SvelteKit 为可使用 `@sveltejs/kit/node/polyfills` 的平台提供了一个 `undici` 帮助器。 * 将输出打包以避免在目标平台上需要安装依赖项,如果需要 * 将用户的静态文件和生成的 JS/CSS 放置在目标平台的正确位置 尽可能的情况下,我们建议将适配器输出放在`build/`目录下,任何中间输出放在`.svelte-kit/[adapter-name]`目录下。