# file-push-webpack-plugin

> This is webpack plugin for sending a zip file to server.

Latest version **1.0.4** (published 2019-03-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install file-push-webpack-plugin
pnpm add file-push-webpack-plugin
yarn add file-push-webpack-plugin
bun add file-push-webpack-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.0.4 |
| Published | 2019-03-07 |
| First published | 2018-11-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 10.4 KB |
| Known vulnerabilities | 0 (+2 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | kenzung |
| Maintainers | kenzung |
| Keywords | webpack, push, file |

## Links

- npm: https://www.npmjs.com/package/file-push-webpack-plugin
- Repository: https://github.com/kenzung/file-push-webpack-plugin
- Homepage: https://github.com/kenzung/file-push-webpack-plugin#readme
- Issues: https://github.com/kenzung/file-push-webpack-plugin/issues
- npm.io page: https://npm.io/package/file-push-webpack-plugin

## Dependencies (3)

- [adm-zip](https://npm.io/package/adm-zip.md) ^0.4.11
- [request](https://npm.io/package/request.md) ^2.88.0
- [request-promise](https://npm.io/package/request-promise.md) ^4.2.2

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 1.0.4 (latest) — 2019-03-07
- 1.0.3 — 2019-03-07
- 1.0.2 — 2018-11-14
- 1.0.1 — 2018-11-14
- 1.0.0 — 2018-11-10

## README

This is webpack plugin for sending a zip file to server.

# Usage
## Example
```javascript
module.export = {
  ...
  plugins: [
    ...
    new FilePushWebpackPlugin({
      url: 'the url you want to send the zip',
      regex: /.*\.map$/,
      shouldRemoveFiles: true,
    }),
  ]
}
```
## Accepting Params
| param | detail | default value |
| :------------ | :------------- | :-------------: |
| regex | find files with a regex. | null |
| shouldRemoveFiles | delete certain files after uploading zip-file | true |
| url | the url which your zip-file will be sent to | null |
| zipFileName | name for zip file | temp.zip |
| success | success callback | null |
| fail | error callback | null |

## For Koa user
If you use koa as your node server, the example below may help you to get the zip-file.

Maybe you use [koa-body](https://github.com/dlau/koa-body) or others lib that can parse formdata.
And, you may need a tool to decompress your zip. I recommend the [adm-zip](https://github.com/cthackers/adm-zip) for your first choice.

I assume that you use `koa-body` and `adm-zip`.
```javascript
const router = require('koa-router')();
const koaBody = require('koa-body');
const fs = require('fs');
const admZip = require('adm-zip');

router.post('/xxx', koaBody({
  multipart: true,
  formidable: {
      maxFileSize: 2000*1024*1024,	// you decide
  }
}), async (ctx) => {
  // This Plugin will send the file with name 'zipFile'
  const { zipFile } = ctx.request.files;
  if (!zipFile) {
    throw Error('no zip');
  }
  try {
    const [filename] = zipFile.name.split('.');
    const zip = new admZip(zipFile.path);
    const dir = `./${filename}`;
    if (!fs.existsSync(dir)) {
      fs.mkdirSync(dir);
    }
    zip.extractAllTo(dir);
  } catch (e) {
    console.log(e);
  }
});
```

## For Express user
```javascript
const multipart = require('connect-multiparty');
const multipartMiddleware = multipart();
app.use('/xxx', multipartMiddleware, function(req, res) {
  const { zipFile } = req.files;
  if (!zipFile) {
    throw Error('no zip');
  }
  try {
    const { path: filePath, originalFilename } = zipFile;
    const [filename] = originalFilename.split('.');
    const zip = new admZip(filePath);
    const dir = path.join(__dirname, `${filename}`);
    if (!fs.existsSync(dir)) {
      fs.mkdirSync(dir);
    }
    zip.extractAllTo(dir);
    fs.unlinkSync(filePath);
  } catch (e) {
    console.log(e);
  }
  res.end();
});
```
# License
MIT.

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