# vue-compress-upload-plugin

> 将文件打成压缩包，上传到服务器上

Latest version **1.2.3** (published 2020-01-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install vue-compress-upload-plugin
pnpm add vue-compress-upload-plugin
yarn add vue-compress-upload-plugin
bun add vue-compress-upload-plugin
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.3 |
| Published | 2020-01-09 |
| First published | 2019-09-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 375.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | mmyhs |
| Maintainers | mmyhs |
| Keywords | webpack, plugin, compress, upload, sftp, ssh |

## Links

- npm: https://www.npmjs.com/package/vue-compress-upload-plugin
- npm.io page: https://npm.io/package/vue-compress-upload-plugin

## Dependencies (5)

- [colors](https://npm.io/package/colors.md) ^1.3.3
- [lodash](https://npm.io/package/lodash.md) ^4.17.15
- [archiver](https://npm.io/package/archiver.md) ^3.1.1
- [node-ssh](https://npm.io/package/node-ssh.md) ^6.0.0
- [schema-utils](https://npm.io/package/schema-utils.md) ^2.2.0

## Alternatives

- [lodash.startswith](https://npm.io/package/lodash.startswith.md) — 769.7K weekly downloads
- [@tarojs/service](https://npm.io/package/@tarojs/service.md) — 33.9K weekly downloads
- [io.extendreality.tilia.indicators.spatialtargets.unity](https://npm.io/package/io.extendreality.tilia.indicators.spatialtargets.unity.md) — 131 weekly downloads
- [@rtarojs/taro](https://npm.io/package/@rtarojs/taro.md) — 90 weekly downloads
- [node-branch-io](https://npm.io/package/node-branch-io.md) — 50 weekly downloads

## Recent versions

- 1.2.3 (latest) — 2020-01-09
- 1.2.2 — 2020-01-09
- 1.2.1 — 2020-01-09
- 1.2.0 — 2020-01-09
- 1.1.5 — 2019-12-19
- 1.1.3-beta — 2019-10-18
- 1.1.2-beta — 2019-09-20
- 1.1.1-beta — 2019-09-18
- 1.0.13 — 2019-09-17
- 1.0.12-beta — 2019-09-16
- 1.0.11-beta — 2019-09-16
- 1.0.10-beta — 2019-09-16
- 1.0.9-beta — 2019-09-16
- 1.0.8-beta — 2019-09-16
- 1.0.7-beta — 2019-09-16
- … 7 more at https://npm.io/package/vue-compress-upload-plugin/versions

## README

vue-compress-upload-plugin

#### 1.2.x

> 本次版本升级支持多种压缩格式(zip/tar)，更新的参数的属性名，使用 `1.2.x` 的小伙伴记得修改对应参数的属性名
> 增加了支持同时向多台服务器发布应用的功能、支持上传本地脚本到服务器执行
>
> 下面展示的两种使用方法，视具体情况使用，一般情况下，我们只需要配置 `serverList` 或者是 `server`即可

```js
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
});
```

#### 参数说明

```js
CompressUploadPlugin({server,serverList,serverOptions,zip},options)
```
`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`

```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`

```sh
#!/bin/bash
cd /nginx/webapp/public
# 删除原静态资源目录
rm -rf dist
# 解压新的包
unzip dist.zip
ls -l

```



![1578561182884](https://thumbnail0.baidupcs.com/thumbnail/03c1b6040laa7281e0135262b474b269?fid=2425778728-250528-51735319994070&time=1578560400&rt=sh&sign=FDTAER-DCb740ccc5511e5e8fedcff06b081203-QufC33CNgG51LR5XM%2BM%2FKG2MFHk%3D&expires=8h&chkv=0&chkbd=0&chkpc=&dp-logid=202351501153310821&dp-callid=0&size=c710_u400&quality=100&vuk=-&ft=video)



#### NOTE

```
1. 在打包的时候，请将指定的 `zipName` 排除用 `CopyWebpackPlugin` 排除在外，以避免不必要的性能开销
2. 请确保服务器和本地对应的目录存在
```

---
_Source: https://npm.io/package/vue-compress-upload-plugin · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
