1.0.9 • Published 2 months ago

deploy-nginx-xxjss v1.0.9

Weekly downloads
-
License
ISC
Repository
-
Last release
2 months ago

webpack 的 dist 包 自动化部署 插件

本插件 是-只用 服务部署插件,
基于 centOS 7 + nginx  用于部署 webpack 生成的dist 包,
自动化部署到远程服务器,并实现自动重启nginx 服务

该插件 主要有三个 功能

    1.  初始化服务器 可以自动联网 安装 nginx 环境;
        可通过 nginx.conf 文件配置 远程服务器 nginx 的运行环境;

    2. 远程服务器,自动创建 环境依赖文件-所需存放文件夹、自动创建 项目所需文件夹;
    
    3.  build 项目 为dist 文件 并压缩 为 dist.zip 文件 并上传到 远程服务器 指定目录下  /data/www/dist.zip ;
        远程服务器 解压 dist.zip 文件 到 /data/www/dist 目录下;
        重启 nginx 服务;
        删除 远程服务器 指定目录下的30天以前的(自定义源码可改过期时间,默认30天) dist.zip 文件; 
        删除 本地 dist.zip 文件; 
    

安装

npm i deploy-nginx-xxjss

使用

插件初始化 会在 项目根路径 生成一个配置文件;
    /ssDeploy/deployConfig.js -> 服务器基本信息 和文件存放路径
    /ssDeploy/nginx.conf -> nginx ,配置文件

命令解析

    带有 ‘init’  的命令 表示 该项目初始化命令,主要用于,创建 nginx 运行环境 和项目 存放路径;
    已有 nginx 运行环境 和项目 存放路径 的项目 无需 执行 init 命令;
    
    "zip": "node src/zip.js", // 用于 压缩 dist 包
    
    "nginx": "node src/nginx.js development",// 用于 安装 nginx 环境 并 部署到 远程服务器 -开发环境
    
    "deploy": "yarn build && yarn zip && node src/deploy.js development",//  部署到 远程服务器 -开发环境
    
    "test:nginx": "node src/nginx.js test",// 用于 安装 nginx 环境 并 部署到 远程服务器 -测试环境
    
    "test:deploy": "yarn build && yarn zip && node src/deploy.js test",// 部署到 远程服务器 -测试环境
    
    "pro:nginx": "node src/nginx.js production",// 用于 安装 nginx 环境 并 部署到 远程服务器 -生产环境

    "pro:deploy": "yarn build && yarn zip && node src/deploy.js production"//  部署到 远程服务器 -生产环境

配置 远程服务器

// =============================================== deploy.js==============================

let nginxConfPath = '/usr/local/src/'
// 配置创建安装包目录
let software = '/data/software';
// 配置远程服务器目录
let remoteDirectory = '/data/competition/web';
// 服务地址配置
let serverConfig;

switch (args[0]) {
    case 'production':
        serverConfig = {
            host: '**.***.***.***',
            port: 22,
            username: 'root',
            password: '**************',
        };
        break;
    case 'test':
        serverConfig = {
            host: '**.***.***.***',
            port: 22,
            username: 'root',
            password: '**************',
        };
        break;
    case 'development':
        serverConfig = {
            host: '**.***.***.***',
            port: 22,
            username: 'root',
            password: '**************',
        };
        break;
    default:
        console.error('连接异常:请重新执行dev:deploy、test:deploy、production:deploy');
        process.exit(1);
}
// =============================================== nginx.conf==============================

server {
    listen 80 ;  // 监听端口
    server_name localhost; // 服务器 地址

    location ^~ /{
        root   /path/to your project path /web/dist; // 服务器 前端包地址
        try_files $uri $uri/  /index.html;
    }

    location ^~ /api {
        rewrite ^/api(.*)$ $1 break;
        proxy_pass http://**.**.**; // 服务器 后端代理 地址
    }
}
1.0.9

2 months ago

1.0.8

2 months ago

1.0.7

2 months ago

1.0.6

2 months ago

1.0.5

2 months ago

1.0.4

2 months ago

1.0.3

2 months ago

1.0.2

2 months ago

1.0.1

2 months ago

1.0.0

2 months ago