1.2.3 • Published 4 years ago

vue-compress-upload-plugin v1.2.3

Weekly downloads
23
License
MIT
Repository
-
Last release
4 years ago

vue-compress-upload-plugin

1.2.x

本次版本升级支持多种压缩格式(zip/tar),更新的参数的属性名,使用 1.2.x 的小伙伴记得修改对应参数的属性名 增加了支持同时向多台服务器发布应用的功能、支持上传本地脚本到服务器执行

下面展示的两种使用方法,视具体情况使用,一般情况下,我们只需要配置 serverList 或者是 server即可

const CompressUploadPlugin = require('vue-compress-upload-plugin');

// 第一种 有多台服务器需要发布应用
new CompressUploadPlugin({
    serverList: [
        {
            host: 'xxx.xxx.xxx.xxx',
            username: 'nginx',
            password: 'xxx',
            uploadPath: '/usr/local/nginx/webapp/dist.zip',
            localCmdScriptPath:'c:/script/bin',
            cmdScriptPath: '/usr/local/nginx/bin',
            uploadAfterCmd: 'sh deploy-after.sh',
            uploadBeforeCmd: 'sh deploy-before.sh'
        },
        {
            host: 'xxx.xxx.xxx.xxx',
            username: 'nginx',
            password: 'xxx',
            uploadPath: '/nginx/webapp/test/dist.zip',
        }
    ],
   	compress:{
        outPath: path.join(__dirname, '../static'),
        srcPath: path.join(__dirname, '../dist')
    },
    serverOptions:{
        uploadPath: '',
        localCmdScriptPath:'',
        cmdScriptPath: '',
        uploadBeforeCmd: '',
        uploadAfterCmd: '',
    }
},{
    stdout: false,
});

// 第二种 只有一台服务器需要发布应用
new CompressUploadPlugin({
  server: {
    host: 'xxx.xxx.xxx.xxx',
    username: 'xxx',
    password: 'xxx',
    uploadPath: '/usr/local/nginx/webapp/dist.zip',
    localCmdScriptPath: path.join(__dirname, '../bin'),
    cmdScriptPath: '/usr/local/nginx/bin/',
    uploadAfterCmd: 'sh deploy-after.sh',
    uploadBeforeCmd: 'sh deploy-before.sh'
  },
  compress: {
    filename: 'dist.zip',
    outPath: path.join(__dirname, '../target'),
    srcPath: path.join(__dirname, '../target/resources/home/static')
  }
}, {
  stdout: true,
  showConfigInfo: true
});

参数说明

CompressUploadPlugin({server,serverList,serverOptions,zip},options)

serverList

本质是集合,{server},{server},{server}...

server

NameTypeDefaultDescription
hoststring | 主机名
usernamestring当前项目根节点下的dist用户名
passwordstring | 密码
portnumber22sftp 端口
uploadPathstring | 文件上传路径
localCmdScriptPathstring | 本地脚本路径
cmdScriptPathstring | 脚本执行路径
uploadBeforeCmdstring | 文件上传成功前需要执行的脚本命令
uploadAfterCmdstring | 文件上传成功后需要执行的脚本命令

serverOptions

NameTypeDefaultDescription
uploadPathstring | 文件上传路径
localCmdScriptPathstring | 本地脚本路径
cmdScriptPathstring | 脚本执行路径
uploadBeforeCmdstring | 文件上传成功前需要执行的脚本命令
uploadAfterCmdstring | 文件上传成功后需要执行的脚本命令

compress

NameTypeDefaultDescription
formatstringzip,tar,json压缩格式,不建议使用 json
outPathstring当前项目根节点下的static压缩文件输出目录
srcPathstring当前项目根节点下的dist需要压缩的目录
filenamestringdist.zip压缩的文件名

options

NameTypeDefaultDescription
stdoutbooleanfalse是否输出shell的输出信息
showConfigInfobooleanfalse是否输出插件的配置信息

这里提供一个Linux脚本案列

deploy-before.sh

cd /nginx/webapp/public
if [ ! -f "/nginx/webapp/public/dist.zip" ];then
echo "dist.zip文件不存在"
else
mv dist.zip dist_backups.zip
fi

deploy-after.sh

#!/bin/bash
cd /nginx/webapp/public
# 删除原静态资源目录
rm -rf dist
# 解压新的包
unzip dist.zip
ls -l

1578561182884

NOTE

1. 在打包的时候,请将指定的 `zipName` 排除用 `CopyWebpackPlugin` 排除在外,以避免不必要的性能开销
2. 请确保服务器和本地对应的目录存在
1.2.3

4 years ago

1.2.2

4 years ago

1.2.0

4 years ago

1.2.1

4 years ago

1.1.5

4 years ago

1.1.3-beta

5 years ago

1.1.2-beta

5 years ago

1.1.1-beta

5 years ago

1.1.0-beta

5 years ago

1.0.13

5 years ago

1.0.12-beta

5 years ago

1.0.11-beta

5 years ago

1.0.10-beta

5 years ago

1.0.9-beta

5 years ago

1.0.8-beta

5 years ago

1.0.7-beta

5 years ago

1.0.6-beta

5 years ago

1.0.5-beta

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago