npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

ssh-fast-deploy

v1.0.0

Published

一键打包本地文件并通过SSH部署到远程服务器 — 适用于前端/静态站点的快速发布

Readme

ssh-fast-deploy

一键打包本地文件并通过 SSH 部署到远程服务器

npm version license node


为什么用它

前端项目部署到服务器通常需要:npm run build → 手动打包 → 连接服务器 → 上传 → 解压。整个过程繁琐且容易出错。

ssh-fast-deploy 把这一切变成一行命令——打包、上传、远程解压,一步到位。

前提:远程服务器需安装 unzip 命令(CentOS/Ubuntu 默认都有)。


安装

npm install ssh-fast-deploy -D

或全局安装:

npm install ssh-fast-deploy -g

快速开始

1. 生成配置文件

npx sfp init

会生成 .deployrc.json支持 // 行注释):

{
  // ===== 必填 =====
  "host": "your-server.com",          // SSH 服务器 IP 或域名
  "username": "root",                  // SSH 登录用户
  "remotePath": "/www/wwwroot/your-site", // 远程部署目录 (绝对路径)

  // ===== 认证 (二选一) =====
  "privateKey": "~/.ssh/id_rsa",      // 推荐: SSH 私钥路径
  // "password": "your-password",     // 备选: SSH 密码

  // ===== 可选 =====
  "port": 22,                          // SSH 端口,默认 22
  "localDir": "dist",                  // 本地要打包的目录,多目录: "dist,public"
  "backup": false                      // 部署前备份远程文件 (规划中)
}

2. 编辑配置,填入实际信息

{
  // 使用 SSH 密码认证
  "host": "110.42.xxx.xxx",
  "username": "root",
  "password": "your-password",
  "remotePath": "/www/wwwroot/my-site",
  "localDir": "dist"
}

3. 部署

npx sfp

搞定。


使用方式

CLI

# 使用配置文件 + 覆盖参数
sfp --local-dir dist,public

# 完全通过命令行
sfp \
  --host 192.168.1.100 \
  --user root \
  --pass yourpass \
  --remote-path /www/wwwroot/my-site \
  --local-dir dist

# 生成配置模板
sfp init

编程方式 (API)

import { deploy } from 'ssh-fast-deploy';

// 方式1:使用项目中的配置文件
await deploy();

// 方式2:完全通过代码传参
await deploy({
  host: '192.168.1.100',
  port: 22,
  username: 'root',
  password: 'your-password',
  remotePath: '/www/wwwroot/my-site',
  localDir: ['dist', 'public'],  // 支持多目录
  silent: false,                  // 静默模式
});

// 方式3:SSH 密钥认证
await deploy({
  host: '192.168.1.100',
  username: 'root',
  privateKey: '~/.ssh/id_rsa',
  remotePath: '/www/wwwroot/my-site',
});

进阶用法:打包 & 上传分离

import { packFiles, uploadAndExtract } from 'ssh-fast-deploy';

// 先打包
const zipPath = await packFiles(['dist'], '.upload.zip');

// 再上传
await uploadAndExtract(
  { host: '...', username: 'root', password: '...' },
  zipPath,
  '/www/wwwroot/my-site',
);

配置来源优先级

CLI 参数 > .deployrc.json > package.json#deploy > 环境变量 > 默认值

| 方式 | 字段 | 说明 | |------|------|------| | CLI | --host, --user, --pass, --key 等 | sfp --host xxx | | .deployrc.json | 全字段 | 项目根目录的 JSON 配置 | | package.json | "deploy": {...} | 嵌入在 package.json 中 | | 环境变量 | SSH_HOST, SSH_USER 等 | CI/CD 友好 |

package.json 配置示例

{
  "name": "my-project",
  "scripts": {
    "deploy": "sfp"
  },
  "deploy": {
    "host": "110.42.xxx.xxx",
    "username": "root",
    "privateKey": "~/.ssh/id_rsa",
    "remotePath": "/www/wwwroot/my-site",
    "localDir": "dist"
  }
}

然后直接 npm run deploy


配置项

| 字段 | 类型 | 必填 | 说明 | |------|------|------|------| | host | string | ✅ | SSH 服务器地址 | | username | string | ✅ | SSH 用户名 | | remotePath | string | ✅ | 远程目标目录(绝对路径) | | password | string | 二选一 | SSH 密码 | | privateKey | string | 二选一 | SSH 私钥路径,如 ~/.ssh/id_rsa | | port | number | 否 | SSH 端口,默认 22 | | localDir | string/string[] | 否 | 本地要打包的目录,默认 dist,多目录用数组 | | backup | boolean | 否 | 部署前备份远程文件(规划中) |


项目结构

ssh-fast-deploy/
├── bin/
│   └── cli.js            # CLI 入口
├── src/
│   ├── index.js          # API 入口,导出 deploy()
│   ├── deploy.js         # 打包 + SSH 上传 + 远程解压
│   └── config.js         # 多源配置加载
├── package.json
├── README.md
└── LICENSE

License

MIT