> Discover all available pages from the documentation index: https://mastra.zisheng.pro/zh-HK/llms.txt # NetlifyDeployer `NetlifyDeployer` 類別透過調整 Mastra 的輸出,建立伺服器的最佳化版本,以處理封裝、設定及部署。它在基礎 [`Deployer`](https://mastra.zisheng.pro/zh-HK/reference/deployer) 類別上加入 Netlify 專用功能,讓你可以在 Netlify 無伺服器函式或邊緣函式中執行 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 Functions 範例 ```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` 檔案。 ### 無伺服器輸出(預設) ```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": "/*" } ] } ```