> Discover all available pages from the documentation index: https://mastra.zisheng.pro/zh-TW/llms.txt # NetlifyDeployer `NetlifyDeployer` 類別會調整 Mastra 的輸出,以建立最佳化的伺服器版本,並處理封裝、設定與部署。它以 Netlify 專屬功能擴充基礎 [`Deployer`](https://mastra.zisheng.pro/zh-TW/reference/deployer) 類別,讓你可以在 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 執行,沒有固定逾時時間)。 ### 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": "/*" } ] } ```