netlify-deploy
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseNetlify Deployment Skill
Netlify 部署技能
Deploy web projects to Netlify using the Netlify CLI with intelligent detection of project configuration and deployment context.
使用Netlify CLI将Web项目部署到Netlify,可智能检测项目配置和部署环境。
Overview
概述
This skill automates Netlify deployments by:
- Verifying Netlify CLI authentication
- Detecting project configuration and framework
- Linking to existing sites or creating new ones
- Deploying to production or preview environments
本技能通过以下方式自动化Netlify部署:
- 验证Netlify CLI身份认证状态
- 检测项目配置和框架
- 关联现有站点或创建新站点
- 部署到生产或预览环境
Prerequisites
前提条件
- Netlify CLI: Installed via npx (no global install required)
- Authentication: Netlify account with active login session
- Project: Valid web project in current directory
- When sandboxing blocks the deployment network calls, rerun with .
sandbox_permissions=require_escalated - The deployment might take a few minutes. Use appropriate timeout values.
- Netlify CLI:通过npx安装(无需全局安装)
- 身份认证:处于登录状态的Netlify账户
- 项目:当前目录下的有效Web项目
- 当沙箱阻止部署网络调用时,使用重新运行。
sandbox_permissions=require_escalated - 部署可能需要几分钟,请设置合适的超时时间。
Authentication Pattern
身份认证模式
The skill uses the pre-authenticated Netlify CLI approach:
- Check authentication status with
npx netlify status - If not authenticated, guide user through
npx netlify login - Fail gracefully if authentication cannot be established
Authentication uses either:
- Browser-based OAuth (primary): opens browser for authentication
netlify login - API Key (alternative): Set environment variable
NETLIFY_AUTH_TOKEN
本技能采用预认证Netlify CLI方式:
- 使用检查身份认证状态
npx netlify status - 若未认证,引导用户执行
npx netlify login - 若无法完成认证,优雅地终止流程
身份认证可通过以下两种方式:
- 基于浏览器的OAuth(首选):会打开浏览器进行认证
netlify login - API密钥(备选):设置环境变量
NETLIFY_AUTH_TOKEN
Workflow
工作流程
1. Verify Netlify CLI Authentication
1. 验证Netlify CLI身份认证
Check if the user is logged into Netlify:
bash
npx netlify statusExpected output patterns:
- ✅ Authenticated: Shows logged-in user email and site link status
- ❌ Not authenticated: "Not logged into any site" or authentication error
If not authenticated, guide the user:
bash
npx netlify loginThis opens a browser window for OAuth authentication. Wait for user to complete login, then verify with again.
netlify statusAlternative: API Key authentication
If browser authentication isn't available, users can set:
bash
export NETLIFY_AUTH_TOKEN=your_token_hereTokens can be generated at: https://app.netlify.com/user/applications#personal-access-tokens
检查用户是否已登录Netlify:
bash
npx netlify status预期输出模式:
- ✅ 已认证:显示已登录用户的邮箱和站点关联状态
- ❌ 未认证:“未登录任何站点”或认证错误
若未认证,引导用户执行:
bash
npx netlify login这会打开一个浏览器窗口进行OAuth认证。等待用户完成登录后,再次使用验证。
netlify status备选:API密钥认证
若无法使用浏览器认证,用户可设置:
bash
export NETLIFY_AUTH_TOKEN=your_token_here2. Detect Site Link Status
2. 检测站点关联状态
From output, determine:
netlify status- Linked: Site already connected to Netlify (shows site name/URL)
- Not linked: Need to link or create site
从的输出中判断:
netlify status- 已关联:站点已连接到Netlify(显示站点名称/URL)
- 未关联:需要关联或创建站点
3. Link to Existing Site or Create New
3. 关联现有站点或创建新站点
If already linked → Skip to step 4
If not linked, attempt to link by Git remote:
bash
undefined若已关联 → 跳至步骤4
若未关联,尝试通过Git远程仓库关联:
bash
undefinedCheck if project is Git-based
检查项目是否基于Git
git remote show origin
git remote show origin
If Git-based, extract remote URL
若基于Git,提取远程仓库URL
Format: https://github.com/username/repo or git@github.com:username/repo.git
格式:https://github.com/username/repo 或 git@github.com:username/repo.git
Try to link by Git remote
尝试通过Git远程仓库关联
npx netlify link --git-remote-url <REMOTE_URL>
**If link fails** (site doesn't exist on Netlify):
```bashnpx netlify link --git-remote-url <REMOTE_URL>
**若关联失败**(Netlify上不存在该站点):
```bashCreate new site interactively
交互式创建新站点
npx netlify init
This guides user through:
1. Choosing team/account
2. Setting site name
3. Configuring build settings
4. Creating netlify.toml if needednpx netlify init
这会引导用户完成以下步骤:
1. 选择团队/账户
2. 设置站点名称
3. 配置构建设置
4. 必要时创建netlify.toml文件4. Verify Dependencies
4. 验证依赖项
Before deploying, ensure project dependencies are installed:
bash
undefined部署前,确保已安装项目依赖项:
bash
undefinedFor npm projects
针对npm项目
npm install
npm install
For other package managers, detect and use appropriate command
针对其他包管理器,自动检测并使用相应命令
yarn install, pnpm install, etc.
yarn install, pnpm install 等
undefinedundefined5. Deploy to Netlify
5. 部署到Netlify
Choose deployment type based on context:
Preview/Draft Deploy (default for existing sites):
bash
npx netlify deployThis creates a deploy preview with a unique URL for testing.
Production Deploy (for new sites or explicit production deployments):
bash
npx netlify deploy --prodThis deploys to the live production URL.
Deployment process:
- CLI detects build settings (from netlify.toml or prompts user)
- Builds the project locally
- Uploads built assets to Netlify
- Returns deployment URL
根据环境选择部署类型:
预览/草稿部署(现有站点默认选项):
bash
npx netlify deploy这会创建一个带有唯一URL的部署预览用于测试。
生产部署(针对新站点或明确的生产部署需求):
bash
npx netlify deploy --prod这会部署到线上生产环境URL。
部署流程:
- CLI检测构建设置(来自netlify.toml或提示用户输入)
- 在本地构建项目
- 将构建后的资源上传到Netlify
- 返回部署URL
6. Report Results
6. 报告结果
After deployment, report to user:
- Deploy URL: Unique URL for this deployment
- Site URL: Production URL (if production deploy)
- Deploy logs: Link to Netlify dashboard for logs
- Next steps: Suggest to view site or dashboard
netlify open
部署完成后,向用户报告以下信息:
- 部署URL:本次部署的唯一URL
- 站点URL:生产环境URL(若为生产部署)
- 部署日志:Netlify控制台的日志链接
- 后续步骤:建议使用查看站点或控制台
netlify open
Handling netlify.toml
处理netlify.toml文件
If a file exists, the CLI uses it automatically. If not, the CLI will prompt for:
netlify.toml- Build command: e.g., ,
npm run buildnext build - Publish directory: e.g., ,
dist,build.next
Common framework defaults:
- Next.js: build command , publish
npm run build.next - React (Vite): build command , publish
npm run builddist - Static HTML: no build command, publish current directory
The skill should detect framework from if possible and suggest appropriate settings.
package.json若存在文件,CLI会自动使用其中的配置。若不存在,CLI会提示用户输入:
netlify.toml- 构建命令:例如、
npm run buildnext build - 发布目录:例如、
dist、build.next
常见框架默认配置:
- Next.js:构建命令,发布目录
npm run build.next - React (Vite):构建命令,发布目录
npm run builddist - 静态HTML:无需构建命令,发布目录为当前目录
本技能会尽可能从中检测框架,并推荐合适的配置。
package.jsonExample Full Workflow
完整工作流程示例
bash
undefinedbash
undefined1. Check authentication
1. 检查身份认证状态
npx netlify status
npx netlify status
If not authenticated:
若未认证:
npx netlify login
npx netlify login
2. Link site (if needed)
2. 关联站点(若需要)
Try Git-based linking first
优先尝试基于Git的关联
git remote show origin
npx netlify link --git-remote-url https://github.com/user/repo
git remote show origin
npx netlify link --git-remote-url https://github.com/user/repo
If no site exists, create new one:
若站点不存在,创建新站点:
npx netlify init
npx netlify init
3. Install dependencies
3. 安装依赖项
npm install
npm install
4. Deploy (preview for testing)
4. 部署(预览版本用于测试)
npx netlify deploy
npx netlify deploy
5. Deploy to production (when ready)
5. 部署到生产环境(准备就绪后)
npx netlify deploy --prod
undefinednpx netlify deploy --prod
undefinedError Handling
错误处理
Common issues and solutions:
"Not logged in"
→ Run
npx netlify login"No site linked"
→ Run or
npx netlify linknpx netlify init"Build failed"
→ Check build command and publish directory in netlify.toml or CLI prompts
→ Verify dependencies are installed
→ Review build logs for specific errors
"Publish directory not found"
→ Verify build command ran successfully
→ Check publish directory path is correct
常见问题及解决方案:
“未登录”
→ 执行
npx netlify login“未关联任何站点”
→ 执行或
npx netlify linknpx netlify init“构建失败”
→ 检查netlify.toml或CLI提示中的构建命令和发布目录
→ 验证依赖项是否已安装
→ 查看构建日志中的具体错误
“发布目录未找到”
→ 验证构建命令是否执行成功
→ 检查发布目录路径是否正确
Troubleshooting
故障排除
Escalated Network Access
提升网络访问权限
If deployment fails due to network issues (timeouts, DNS errors, connection resets), rerun the deploy with escalated permissions (use ). The deploy requires escalated network access when sandbox networking blocks outbound requests.
sandbox_permissions=require_escalatedExample guidance to the user:
The deploy needs escalated network access to deploy to Netlify. I can rerun the command with escalated permissions—want me to proceed?若因网络问题(超时、DNS错误、连接重置)导致部署失败,使用提升的权限重新运行部署命令(使用)。当沙箱网络阻止出站请求时,部署需要提升的网络访问权限。
sandbox_permissions=require_escalated给用户的示例指引:
部署需要提升网络访问权限才能部署到Netlify。我可以使用提升的权限重新运行命令——是否继续?Environment Variables
环境变量
For secrets and configuration:
- Never commit secrets to Git
- Set in Netlify dashboard: Site Settings → Environment Variables
- Access in builds via
process.env.VARIABLE_NAME
针对密钥和配置:
- 切勿将密钥提交到Git
- 在Netlify控制台中设置:站点设置 → 环境变量
- 在构建中通过访问
process.env.VARIABLE_NAME
Tips
小贴士
- Use (no
netlify deploy) first to test before production--prod - Run to view site in Netlify dashboard
netlify open - Run to view function logs (if using Netlify Functions)
netlify logs - Use for local development with Netlify Functions
netlify dev
- 先使用(不带
netlify deploy参数)进行测试,再部署到生产环境--prod - 执行在Netlify控制台中查看站点
netlify open - 执行查看函数日志(若使用Netlify Functions)
netlify logs - 执行结合Netlify Functions进行本地开发
netlify dev
Reference
参考资料
- Netlify CLI Docs: https://docs.netlify.com/cli/get-started/
- netlify.toml Reference: https://docs.netlify.com/configure-builds/file-based-configuration/
- Netlify CLI文档:https://docs.netlify.com/cli/get-started/
- netlify.toml参考:https://docs.netlify.com/configure-builds/file-based-configuration/
Bundled References (Load As Needed)
捆绑参考资料(按需加载)
- CLI commands
- Deployment patterns
- netlify.toml guide
- CLI命令
- 部署模式
- netlify.toml指南