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 🙏

© 2024 – Pkg Stats / Ryan Hefner

deploy-web2

v1.0.1

Published

一键自动化打包、部署前端代码服务

Downloads

2

Readme

deploy-web2

前端一键自动化部署脚手架服务,支持开发、测试、生产多环境配置。配置好后一键即可自动完成部署。参考 deploy-plus

1 安装

全局安装 deploy-web2

npm install deploy-web2 -g

本地安装 deploy-web2

npm install deploy-web2 --save-dev

查看版本,表示安装成功

deploy - web2 - v;

注:本地安装的需要在调用前加 npx

npx deploy-web2 -v

2 使用(以下代码都以全局安装为例)

2.1 查看帮助

deploy-web2 -h

2.2 初始化配置文件(在项目目录下)

deploy-web2 init
# 或者使用简写
deploy-web2 i

根据提示填写内容,会在项目根目录下生成 deploy.config.js 文件,初始化可根据选择的需要部署的环境生成 dev (开发环境)、test (测试环境)、prod (生产环境) 三个配置,再有其他配置可参考模板自行配置。

2.3 手动创建或修改配置文件

在项目根目录下手动创建 deploy.config.js 文件,复制以下代码按情况修改即可。

module.exports = {
  projectName: "myProject", // 项目名称
  privateKey: "/Users/username/.ssh/id_rsa",
  passphrase: "",
  cluster: {
    // 环境对象
    name: "开发环境", // 环境名称
    script: "npm run build", // 打包命令,子集的打包命令无效
    distPath: "dist", // 本地打包生成目录
    zipPattern: "YYMMDDHHmm", //压缩包名支持时间戳
    cluster: ["dev", "test"],
  },
  cluster2: {
    // 环境对象
    name: "开发环境", // 环境名称
    script: "npm run build", // 打包命令
    host: ["192.168.0.1", "192.168.0.2"], // 服务器地址
    // host: "192.168.0.1",
    port: 22, // 服务器端口号
    username: "root", // 服务器登录用户名
    password: "123456", // 服务器登录密码
    distPath: "dist", // 本地打包生成目录
    zipPattern: "YYMMDDHHmm", //压缩包名支持时间戳
    remotePath: "/usr/local/nginx/html", // 服务器部署路径(不可为空或'/')
    isBackupRemote: true, // 是否备份远程文件(默认true)
  }, // 集群部署配置,要同时部署多台配置此属性如: ['dev', 'test', 'prod']
  dev: {
    // 环境对象
    name: "开发环境", // 环境名称
    script: "npm run build", // 打包命令
    host: "192.168.0.1", // 服务器地址
    port: 22, // 服务器端口号
    username: "root", // 服务器登录用户名
    password: "123456", // 服务器登录密码
    distPath: "dist", // 本地打包生成目录
    zipPattern: "YYMMDDHHmm", //压缩包名支持时间戳
    remotePath: "/usr/local/nginx/html", // 服务器部署路径(不可为空或'/')
    serviceReload: true, //服务器中nginx是否重启
    isBackupRemote: true, // 是否备份远程文件(默认true)
  },
  test: {
    // 环境对象
    name: "测试环境", // 环境名称
    script: "npm run build:test", // 打包命令
    host: "192.168.0.1", // 服务器地址
    port: 22, // 服务器端口号
    username: "root", // 服务器登录用户名
    password: "123456", // 服务器登录密码
    distPath: "dist", // 本地打包生成目录
    zipPattern: "", //压缩包名支持时间戳
    remotePath: "/usr/local/nginx/html", // 服务器部署路径(不可为空或'/')
    serviceReload: "service nginx start", //web服务重启命令
    isBackupRemote: true,
  },
  prod: {
    // 环境对象
    name: "生产环境", // 环境名称
    script: "npm run build:prod", // 打包命令
    host: "192.168.0.1", // 服务器地址
    port: 22, // 服务器端口号
    username: "root", // 服务器登录用户名
    password: "123456", // 服务器登录密码
    distPath: "dist", // 本地打包生成目录
    zipPattern: "YYMMDDHHmm", //压缩包名支持时间戳
    remotePath: "/usr/local/nginx/html", // 服务器部署路径(不可为空或'/')
    isBackupRemote: true,
  },
};

2.4 部署 (在项目目录下)

注意:命令后面需要加 --mode 环境对象 (如:--mode dev

deploy-web2 deploy --mode dev
# 或者使用 deploy-web2 d --mode dev
# 或者使用 deploy-web2 d -m dev

输入 Y 确认后即可开始自动部署

如果不需要再打包项目,可以使用 -n 或者 --no-build 命令参数,例如

deploy-web2 deploy --mode dev --no-build
# 或者使用 deploy-web2 d --mode dev -n
# 或者使用 deploy-web2 d -m dev -n

2.5 集群部署 (在项目目录下)

注意:集群配置需要在 deploy-web2 中 配置 cluster 字段 (如:cluster: ['dev', 'test', 'prod']

deploy-web2 deploy # 或者使用 deploy-web2 d

输入 Y 确认后即可开始自动部署

集群部署同样可使用 -n 参数

2.6 更新优化

如果不想把服务器密码保存在配置文件中,也可以在配置文件中删除 password 字段。在部署的时候会弹出输入密码界面。

如果不想在部署前执行打包命令,在配置文件中删除 script 字段即可。

2.7 本地安装扩展

如果使用本地安装命令的话,可以在项目根目录下的 package.json 文件中 scripts 脚本中添加如下代码

"scripts": {
  "serve": "vue-cli-service serve",
  "build": "vue-cli-service build",
  "lint": "vue-cli-service lint",
  "deploy": "deploy-web2 deploy",
  "deploy:dev": "deploy-web2 deploy --mode dev",
  "deploy:test": "deploy-web2 deploy --mode test",
  "deploy:prod": "deploy-web2 deploy --mode prod"
}

然后使用下面代码也可以完成部署操作

npm run deploy:dev