zcompress-vite-plugin 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +92 -20
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,20 +1,23 @@
1
- # zcompress Vite Plugin
1
+ # zcompress-vite-plugin · 中文
2
2
 
3
- High-performance multi-threaded asset compression for Vite production builds, powered by [zcompress](https://github.com/luochuan2008/zcompress) (Zig).
3
+ Vite 生产构建资源压缩插件 gzip / zstd / brotli,多线程并行,比 Node.js 方案快 5-10 倍。
4
4
 
5
- ## Features
6
-
7
- - 🧵 **Multi-threaded** — all CPU cores, not just one
8
- - ⚡ **5-10x faster** than Node.js compression plugins
9
- - 📦 **gzip**, **zstd**, **brotli** — all three algorithms
10
- - 💾 **Incremental cache** — skip unchanged files
11
-
12
- ## Quick Start
5
+ ## 安装 · Install
13
6
 
14
7
  ```bash
15
8
  npm install zcompress-vite-plugin --save-dev
16
9
  ```
17
10
 
11
+ 安装后自动下载对应平台的 zcompress 二进制。如果下载失败,手动安装:
12
+
13
+ | 平台 | 命令 |
14
+ |------|------|
15
+ | macOS | `brew install zstd brotli && zig build -Doptimize=ReleaseFast` |
16
+ | Linux | `apt install libzstd-dev libbrotli-dev && zig build -Doptimize=ReleaseFast` |
17
+ | Windows | 安装 [Zig](https://ziglang.org/download/),`choco install zstandard brotli`,然后 `zig build -Doptimize=ReleaseFast` |
18
+
19
+ ## 使用
20
+
18
21
  ```js
19
22
  // vite.config.js
20
23
  import zcompress from 'zcompress-vite-plugin';
@@ -23,24 +26,93 @@ export default {
23
26
  plugins: [
24
27
  zcompress({
25
28
  algo: 'gzip', // 'gzip' | 'zstd' | 'brotli'
26
- level: 6, // 1-9
27
- threads: 4, // 0 = auto
28
- cache: true, // skip unchanged files
29
+ level: 6, // 压缩级别 1-9
30
+ threads: 4, // 线程数,0=自动
31
+ cache: true, // 跳过未修改文件
32
+ verbose: true, // 显示详细输出
29
33
  })
30
34
  ]
31
35
  };
32
36
  ```
33
37
 
34
- After `vite build`, you'll get a `dist-compressed/` folder with `.gz` (or `.zst`/`.br`) files.
38
+ `vite build` 后,`dist-compressed/` 目录下就是压缩后的文件:
39
+
40
+ ```
41
+ dist-compressed/
42
+ ├── index.html.gz
43
+ ├── style.css.gz
44
+ ├── app.js.gz
45
+ └── logo.svg.gz
46
+ ```
47
+
48
+ 配合 Nginx 的 `gzip_static on` 直接使用。
49
+
50
+ ## 选项
51
+
52
+ | 选项 | 类型 | 默认值 | 说明 |
53
+ |------|------|--------|------|
54
+ | `algo` | `'gzip' \| 'zstd' \| 'brotli'` | `'gzip'` | 压缩算法 |
55
+ | `level` | `number` | `6` | 压缩级别 (1-9) |
56
+ | `threads` | `number` | `0` | 线程数 (0=CPU 核心数) |
57
+ | `verbose` | `boolean` | `false` | 显示详细输出 |
58
+ | `cache` | `boolean` | `false` | 跳过未修改文件 |
59
+ | `include` | `string[]` | `[]` | 额外压缩的扩展名 (如 `['.ts']`) |
60
+ | `exclude` | `string[]` | `[]` | 排除的扩展名 (如 `['.map']`) |
61
+ | `binaryPath` | `string` | 自动 | 手动指定二进制路径 |
35
62
 
36
- ## How It Works
63
+ ## 默认压缩的文件类型
37
64
 
38
- The plugin ships a JS wrapper. On `npm install`, it downloads the prebuilt Zig binary for your platform from GitHub Releases. If the download fails (air-gapped, unsupported arch), it falls back to looking for `zcompress` in your PATH.
65
+ `.js` `.mjs` `.cjs` `.css` `.html` `.htm` `.json` `.svg` `.png` `.jpg` `.jpeg` `.gif` `.ico` `.ttf` `.woff` `.woff2` `.xml` `.csv` `.wasm`
66
+
67
+ ## License
68
+
69
+ MIT
70
+
71
+ ---
72
+
73
+ # zcompress-vite-plugin · English
74
+
75
+ High-performance multi-threaded asset compression for Vite production builds. 5-10x faster than Node.js alternatives.
76
+
77
+ ## Install
39
78
 
40
79
  ```bash
41
- # Manual install (if auto-download fails)
42
- brew install zcompress # macOS
43
- zig build install # from source
80
+ npm install zcompress-vite-plugin --save-dev
81
+ ```
82
+
83
+ The correct platform binary is downloaded automatically. If that fails:
84
+
85
+ ```bash
86
+ brew install zcompress # macOS
87
+ zig build install # from source
88
+ ```
89
+
90
+ ## Usage
91
+
92
+ ```js
93
+ // vite.config.js
94
+ import zcompress from 'zcompress-vite-plugin';
95
+
96
+ export default {
97
+ plugins: [
98
+ zcompress({
99
+ algo: 'brotli', // 'gzip' | 'zstd' | 'brotli'
100
+ level: 11, // 1-9
101
+ threads: 0, // 0 = auto
102
+ cache: true, // skip unchanged files
103
+ })
104
+ ]
105
+ };
106
+ ```
107
+
108
+ After `vite build`, find compressed assets in `dist-compressed/`:
109
+
110
+ ```
111
+ dist-compressed/
112
+ ├── index.html.br
113
+ ├── style.css.br
114
+ ├── app.js.br
115
+ └── logo.svg.br
44
116
  ```
45
117
 
46
118
  ## Options
@@ -49,7 +121,7 @@ zig build install # from source
49
121
  |--------|------|---------|-------------|
50
122
  | `algo` | `'gzip' \| 'zstd' \| 'brotli'` | `'gzip'` | Compression algorithm |
51
123
  | `level` | `number` | `6` | Compression level (1-9) |
52
- | `threads` | `number` | `0` | Thread count (0 = auto) |
124
+ | `threads` | `number` | `0` | Thread count (0=auto) |
53
125
  | `verbose` | `boolean` | `false` | Verbose output |
54
126
  | `cache` | `boolean` | `false` | Skip unchanged files |
55
127
  | `include` | `string[]` | `[]` | Extra extensions to compress |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zcompress-vite-plugin",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "High-performance multi-threaded asset compression for Vite — powered by Zig",
5
5
  "type": "module",
6
6
  "main": "index.js",