https://github.com/KeJunMao/unplugin-compression
Compress dist to zip, tar, taz.
https://github.com/KeJunMao/unplugin-compression
unplugin
Last synced: about 2 months ago
JSON representation
Compress dist to zip, tar, taz.
- Host: GitHub
- URL: https://github.com/KeJunMao/unplugin-compression
- Owner: KeJunMao
- License: mit
- Created: 2022-10-18T11:05:08.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-12-05T23:42:05.000Z (over 1 year ago)
- Last Synced: 2024-11-24T20:08:24.673Z (6 months ago)
- Topics: unplugin
- Language: TypeScript
- Homepage:
- Size: 544 KB
- Stars: 15
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# unplugin-compression
> Compress dist to `zip`, `tar`, `taz`. Powered by [unplugin](https://github.com/unjs/unplugin).
English | [简体中文](./README.zh-CN.md)
## Installation
```bash
pnpm i -D unplugin-compression
```## Usage
Vite
```ts
// vite.config.ts
import Compression from "unplugin-compression/vite";export default defineConfig({
plugins: [
Compression({
/* options */
}),
],
});
```
Rollup
```ts
// rollup.config.js
import Compression from "unplugin-compression/rollup";export default {
plugins: [
Compression({
/* options */
}),
],
};
```
Webpack
```ts
// webpack.config.js
module.exports = {
/* ... */
plugins: [
require("unplugin-compression/webpack")({
/* options */
}),
],
};
```
Vue CLI
```ts
// vue.config.js
module.exports = {
configureWebpack: {
plugins: [
require("unplugin-compression/webpack")({
/* options */
}),
],
},
};
```
esbuild
```ts
// esbuild.config.js
import { build } from "esbuild";build({
/* ... */
plugins: [
require("unplugin-compression/esbuild")({
/* options */
}),
],
});
```
## Configuration
```ts
Compression({
// you can use `zip`, `tar`, `taz`
adapter: "zip",
// relative paths to the directory to compress
source: "dist",
// relative paths to the directory to output
outDir: "./",
// compressed file name
formatter: "{{name}}.{{ext}}",
});
```### `adapter`
Global adapter. When the source does not set the adapter, the global adapter is used.
see [compressing](https://github.com/node-modules/compressing)
### `source`
The compress source, which can be set as `string` or `Source` or `Source[]`
If you use `Source` and set `adapter` or `outDir` or `formatter` options, it's cover global options.
```ts
Compression({
source: [
{
// zip adapter, dist.zip
source: "dist",
},
{
// tar adapter, output.tar
source: "output",
adapter: "tar",
},
],
});
```### `outDir`
The compressed file output dir.
### `formatter`
The compressed filename formatter. default value is `{{name}}.{{ext}}`.
```ts
interface template extends Omit {
name: string;
ext: string;
}
```you can also set a handler
```ts
Compression({
formatter(source) {
return `Hello.${source.adapter}`;
},
});
```### `compressingOptions`
the compressing package opts. see [compressing](https://github.com/node-modules/compressing)
```ts
Compression({
compressingOptions: {
ignoreBase: true,
},
});
```