vue-compress-upload-plugin
1.2.x
本次版本升级支持多种压缩格式(zip/tar),更新的参数的属性名,使用
1.2.x
的小伙伴记得修改对应参数的属性名 增加了支持同时向多台服务器发布应用的功能、支持上传本地脚本到服务器执行下面展示的两种使用方法,视具体情况使用,一般情况下,我们只需要配置
serverList
或者是server
即可
const 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 srcPath: path serverOptions: uploadPath: '' localCmdScriptPath:'' cmdScriptPath: '' uploadBeforeCmd: '' uploadAfterCmd: '' stdout: false; // 第二种 只有一台服务器需要发布应用 server: host: 'xxx.xxx.xxx.xxx' username: 'xxx' password: 'xxx' uploadPath: '/usr/local/nginx/webapp/dist.zip' localCmdScriptPath: path cmdScriptPath: '/usr/local/nginx/bin/' uploadAfterCmd: 'sh deploy-after.sh' uploadBeforeCmd: 'sh deploy-before.sh' compress: filename: 'dist.zip' outPath: path srcPath: path stdout: true showConfigInfo: true;
参数说明
serverList
本质是集合,[{
server
},{server
},{server
}...]
server
Name | Type | Default | Description |
---|---|---|---|
host |
string |
`` | 主机名 |
username |
string |
当前项目根节点下的dist |
用户名 |
password |
string |
`` | 密码 |
port |
number |
22 |
sftp 端口 |
uploadPath |
string |
`` | 文件上传路径 |
localCmdScriptPath |
string |
`` | 本地脚本路径 |
cmdScriptPath |
string |
`` | 脚本执行路径 |
uploadBeforeCmd |
string |
`` | 文件上传成功前需要执行的脚本命令 |
uploadAfterCmd |
string |
`` | 文件上传成功后需要执行的脚本命令 |
serverOptions
Name | Type | Default | Description |
---|---|---|---|
uploadPath |
string |
`` | 文件上传路径 |
localCmdScriptPath |
string |
`` | 本地脚本路径 |
cmdScriptPath |
string |
`` | 脚本执行路径 |
uploadBeforeCmd |
string |
`` | 文件上传成功前需要执行的脚本命令 |
uploadAfterCmd |
string |
`` | 文件上传成功后需要执行的脚本命令 |
compress
Name | Type | Default | Description |
---|---|---|---|
format |
string |
zip,tar,json |
压缩格式,不建议使用 json |
outPath |
string |
当前项目根节点下的static |
压缩文件输出目录 |
srcPath |
string |
当前项目根节点下的dist |
需要压缩的目录 |
filename |
string |
dist.zip |
压缩的文件名 |
options
Name | Type | Default | Description |
---|---|---|---|
stdout | boolean |
false |
是否输出shell的输出信息 |
showConfigInfo | boolean |
false |
是否输出插件的配置信息 |
这里提供一个Linux脚本案列
deploy-before.sh
cd /nginx/webapp/public
deploy-after.sh
#!/bin/bash cd /nginx/webapp/public# 删除原静态资源目录 rm -rf dist# 解压新的包 unzip dist.zipls -l
NOTE
1. 在打包的时候,请将指定的 `zipName` 排除用 `CopyWebpackPlugin` 排除在外,以避免不必要的性能开销
2. 请确保服务器和本地对应的目录存在