> Discover all available pages from the documentation index: https://mastra.zisheng.pro/llms.txt # NetlifyDeployer `NetlifyDeployer` 类通过调整 Mastra 的输出,创建服务器的优化版本,以处理打包、配置和部署。它扩展了基础 [`Deployer`](https://mastra.zisheng.pro/reference/deployer) 类,增加了 Netlify 专用功能。借助该类,你可以在 Netlify serverless function 或 edge function 中运行 Mastra。 ## 安装 要使用 `NetlifyDeployer`,需要安装 `@mastra/deployer-netlify` 包: **npm**: ```bash npm install @mastra/deployer-netlify@latest ``` **pnpm**: ```bash pnpm add @mastra/deployer-netlify@latest ``` **Yarn**: ```bash yarn add @mastra/deployer-netlify@latest ``` **Bun**: ```bash bun add @mastra/deployer-netlify@latest ``` ## 使用示例 导入 `NetlifyDeployer`,并在 Mastra 配置中将其设为 deployer: ```typescript import { Mastra } from '@mastra/core' import { NetlifyDeployer } from '@mastra/deployer-netlify' export const mastra = new Mastra({ deployer: new NetlifyDeployer(), }) ``` ## 构造函数选项 - `target?: 'serverless' | 'edge'`:Netlify 的部署目标。默认为 `'serverless'`。 - `'serverless'`:标准 [Netlify Functions](https://docs.netlify.com/functions/overview/)(Node.js 运行时,默认超时 60 秒)。 - `'edge'`:[Netlify Edge Functions](https://docs.netlify.com/build/edge-functions/overview/)(基于 Deno 的运行时,在离用户最近的边缘位置运行,没有固定超时时间)。 ### Edge function 示例 ```typescript import { Mastra } from '@mastra/core' import { NetlifyDeployer } from '@mastra/deployer-netlify' export const mastra = new Mastra({ deployer: new NetlifyDeployer({ target: 'edge', }), }) ``` ## 输出 运行 `mastra build` 后,deployer 会生成 `.netlify` 文件夹。构建输出包含项目中的所有 Agent、Tool 和 Workflow,以及用于配置 [Netlify Frameworks API](https://docs.netlify.com/build/frameworks/frameworks-api/) 的 `config.json` 文件。 ### Serverless 输出(默认) ```bash your-project/ └── .netlify/ └── v1/ ├── config.json └── functions/ └── api/ ├── index.mjs ├── package.json └── node_modules/ ``` `config.json` 文件包含: ```json { "functions": { "directory": ".netlify/v1/functions", "node_bundler": "none", "included_files": [".netlify/v1/functions/**"] }, "redirects": [ { "force": true, "from": "/*", "to": "/.netlify/functions/api/:splat", "status": 200 } ] } ``` ### Edge 输出 ```bash your-project/ └── .netlify/ └── v1/ ├── config.json └── edge-functions/ ├── index.mjs ├── package.json └── node_modules/ ``` `config.json` 文件包含: ```json { "edge_functions": [ { "function": "index", "path": "/*" } ] } ```