第一步安装依赖
            
            
              bash
              
              
            
          
          pnpm install node-ssh
        第二步创建名为deploy.mjs文件
            
            
              javascript
              
              
            
          
          import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { NodeSSH } from 'node-ssh'
const ssh = new NodeSSH()
async function deploy() {
  console.log('打包成功进行部署流程')
  try {
    // 连接到远程服务器
    await ssh.connect({
      host: 'xx.xx.xx.xx',
      username: 'xxx',
      password: 'xxx',
    })
    console.log('服务器连接成功')
    // 获取当前文件的目录路径
    const __dirname = path.dirname(fileURLToPath(import.meta.url))
    const localPath = path.join(__dirname, 'dist') // 本地目录
    const remotePath = '/www/wwwroot/xxxx' // 远程目录
    // 确保 localPath 存在
    console.log(`本地文件路径: ${localPath}`)
    // 上传文件
    await ssh.putDirectory(localPath, remotePath, {
      recursive: true,
      concurrency: 10,
      validate: (itemPath) => {
        // 只上传文件
        return itemPath !== localPath
      },
    })
    console.log('部署成功')
  }
  catch (error) {
    console.error('Error:', error)
  }
  finally {
    // 断开连接
    ssh.dispose()
  }
}
deploy()
        第三步在package.json中scripts里添加(实际用npm、pnpm、yarn都可以自己更换)
            
            
              javascript
              
              
            
          
           "deploy": "pnpm run build && node deploy.mjs"