@1-/minify_size 0.1.0 → 0.1.1
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.
- package/README.md +16 -37
- package/file.js +6 -2
- package/package.json +6 -9
package/README.md
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
---
|
|
4
4
|
|
|
5
5
|
<a id="en"></a>
|
|
6
|
-
# @1-/minify_size : Minify JS and output
|
|
6
|
+
# @1-/minify_size : Minify JS and output brotli compressed size
|
|
7
7
|
|
|
8
|
-
- [@1-/minify_size : Minify JS and output
|
|
8
|
+
- [@1-/minify_size : Minify JS and output brotli compressed size](#1-minify_size-minify-js-and-output-brotli-compressed-size)
|
|
9
9
|
- [1. Introduction](#1-introduction)
|
|
10
10
|
- [2. Usage Demo](#2-usage-demo)
|
|
11
11
|
- [3. Design Concept](#3-design-concept)
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
|
|
17
17
|
## 1. Introduction
|
|
18
18
|
|
|
19
|
-
Minifies
|
|
20
|
-
Evaluates
|
|
19
|
+
Minifies JavaScript files in a specified directory and calculates their size after Brotli compression.
|
|
20
|
+
Evaluates JavaScript library size under modern network transmission environments supporting Brotli.
|
|
21
21
|
|
|
22
22
|
## 2. Usage Demo
|
|
23
23
|
|
|
@@ -51,13 +51,13 @@ Total 650
|
|
|
51
51
|
|
|
52
52
|
Execution process:
|
|
53
53
|
|
|
54
|
-

|
|
55
55
|
|
|
56
56
|
## 4. Tech Stack
|
|
57
57
|
|
|
58
58
|
- **Runtime**: Node.js / Bun
|
|
59
59
|
- **JS Minifier**: `oxc-minify` (JavaScript minifier implemented in Rust)
|
|
60
|
-
- **
|
|
60
|
+
- **Brotli Engine**: Built-in `node:zlib` (Brotli compression)
|
|
61
61
|
- **Arg Parser**: `yargs`
|
|
62
62
|
- **Encoding**: `@3-/utf8` (TextEncoder-based UTF-8 encoding)
|
|
63
63
|
- **Output Formatting**: `cli-table3` (Formatted tabular output)
|
|
@@ -71,18 +71,12 @@ Execution process:
|
|
|
71
71
|
src/
|
|
72
72
|
├── cli.js # CLI entrypoint, parses directory parameter and invokes main function
|
|
73
73
|
├── _.js # Directory traversal, concurrent file processing, aggregation and formatted output
|
|
74
|
-
└── file.js # Single file processing: reading, oxc-minify compression,
|
|
74
|
+
└── file.js # Single file processing: reading, oxc-minify compression, brotli compression and size calculation
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
-
Key configuration:
|
|
78
|
-
- oxc-minify: `target: "esnext"`, `removeWhitespace: true`
|
|
79
|
-
- zstd compression level: `3` (default)
|
|
80
|
-
- Input validation: Directory parameter required
|
|
81
|
-
- Error handling: Proper exit codes for missing parameters
|
|
82
|
-
|
|
83
77
|
## 6. History
|
|
84
78
|
|
|
85
|
-
|
|
79
|
+
Brotli was developed by Jyrki Alakuijala and Zoltán Szabadka at Google in 2013. It was initially designed for compression of web fonts, and was later extended to become a general-purpose compression algorithm optimized for web transmission, becoming an industry standard (RFC 7932).
|
|
86
80
|
|
|
87
81
|
## About
|
|
88
82
|
|
|
@@ -94,9 +88,9 @@ This library is developed by [WebC.site](https://webc.site).
|
|
|
94
88
|
---
|
|
95
89
|
|
|
96
90
|
<a id="zh"></a>
|
|
97
|
-
# @1-/minify_size :
|
|
91
|
+
# @1-/minify_size : Minify JS and output brotli compressed size
|
|
98
92
|
|
|
99
|
-
- [@1-/minify_size :
|
|
93
|
+
- [@1-/minify_size : Minify JS and output brotli compressed size](#1-minify_size-minify-js-and-output-brotli-compressed-size)
|
|
100
94
|
- [1. 功能介绍](#1-功能介绍)
|
|
101
95
|
- [2. 使用演示](#2-使用演示)
|
|
102
96
|
- [3. 设计思路](#3-设计思路)
|
|
@@ -107,8 +101,8 @@ This library is developed by [WebC.site](https://webc.site).
|
|
|
107
101
|
|
|
108
102
|
## 1. 功能介绍
|
|
109
103
|
|
|
110
|
-
|
|
111
|
-
用于评估
|
|
104
|
+
压缩指定目录中的 JavaScript 文件,并计算经 Brotli 算法压缩后的体积。
|
|
105
|
+
用于评估 JavaScript 库在支持 Brotli 的网络传输环境下的实际传输体积。
|
|
112
106
|
|
|
113
107
|
## 2. 使用演示
|
|
114
108
|
|
|
@@ -142,22 +136,13 @@ file.js 250
|
|
|
142
136
|
|
|
143
137
|
系统执行流程如下:
|
|
144
138
|
|
|
145
|
-
|
|
146
|
-
graph TD
|
|
147
|
-
A[CLI 输入目录] --> B[读取目录下所有 JS 文件]
|
|
148
|
-
B --> C[并发处理每个文件]
|
|
149
|
-
C --> D[使用 oxc-minify 进行压缩]
|
|
150
|
-
D --> E[将压缩代码转换为 UTF-8 编码]
|
|
151
|
-
E --> F[通过 zstd 算法压缩 level 3]
|
|
152
|
-
F --> G[计算压缩后字节长度]
|
|
153
|
-
G --> H[使用 cli-table3 格式化输出结果]
|
|
154
|
-
```
|
|
139
|
+

|
|
155
140
|
|
|
156
141
|
## 4. 技术栈
|
|
157
142
|
|
|
158
143
|
- **Runtime**: Node.js / Bun
|
|
159
144
|
- **JS Minifier**: `oxc-minify` (Rust 实现的 JavaScript 压缩器)
|
|
160
|
-
- **
|
|
145
|
+
- **Brotli Engine**: 内置 `node:zlib` (Brotli 压缩)
|
|
161
146
|
- **Arg Parser**: `yargs`
|
|
162
147
|
- **Encoding**: `@3-/utf8` (TextEncoder-based UTF-8 encoding)
|
|
163
148
|
- **Output Formatting**: `cli-table3` (Formatted tabular output)
|
|
@@ -171,18 +156,12 @@ graph TD
|
|
|
171
156
|
src/
|
|
172
157
|
├── cli.js # CLI 命令行入口,解析目录参数并调用主函数
|
|
173
158
|
├── _.js # 目录遍历、并发调度文件处理、汇总统计并格式化输出
|
|
174
|
-
└── file.js # 单文件处理:读取、oxc-minify 压缩、
|
|
159
|
+
└── file.js # 单文件处理:读取、oxc-minify 压缩、brotli 压缩及大小计算
|
|
175
160
|
```
|
|
176
161
|
|
|
177
|
-
核心配置:
|
|
178
|
-
- oxc-minify: `target: "esnext"`, `removeWhitespace: true`
|
|
179
|
-
- zstd compression level: `3` (default)
|
|
180
|
-
- Input validation: Directory parameter required
|
|
181
|
-
- Error handling: Proper exit codes for missing parameters
|
|
182
|
-
|
|
183
162
|
## 6. 历史故事
|
|
184
163
|
|
|
185
|
-
|
|
164
|
+
Brotli 由 Google 的 Jyrki Alakuijala 和 Zoltán Szabadka 于 2013 年开发。它最初被设计用于压缩网页字体,后来发展为通用压缩算法,用于优化网页传输,并成为行业标准(RFC 7932)。
|
|
186
165
|
|
|
187
166
|
## 关于
|
|
188
167
|
|
package/file.js
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import read from "@3-/read";
|
|
2
2
|
import { minifySync } from "oxc-minify";
|
|
3
|
-
import {
|
|
3
|
+
import { promisify } from "node:util";
|
|
4
|
+
import { brotliCompress } from "node:zlib";
|
|
4
5
|
import utf8e from "@3-/utf8";
|
|
5
6
|
import { basename } from "node:path";
|
|
6
7
|
|
|
8
|
+
const brotli = promisify(brotliCompress);
|
|
9
|
+
|
|
10
|
+
// file_path: 文件路径;返回 minify 且 brotli 压缩后的字节数
|
|
7
11
|
export default async (file_path) => {
|
|
8
12
|
const code = read(file_path),
|
|
9
13
|
{ code: mini } = minifySync(basename(file_path), code, {
|
|
10
14
|
compress: { target: "esnext" },
|
|
11
15
|
codegen: { removeWhitespace: true },
|
|
12
16
|
}),
|
|
13
|
-
zip = await
|
|
17
|
+
zip = await brotli(utf8e(mini));
|
|
14
18
|
return zip.length;
|
|
15
19
|
};
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@1-/minify_size",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Minify JS and output
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Minify JS and output brotli compressed size | 压缩 JS 并输出 brotli 压缩后大小",
|
|
5
5
|
"keywords": [
|
|
6
|
+
"br",
|
|
7
|
+
"brotli",
|
|
6
8
|
"compression",
|
|
7
9
|
"minify",
|
|
8
|
-
"size"
|
|
9
|
-
"zstd"
|
|
10
|
+
"size"
|
|
10
11
|
],
|
|
11
12
|
"homepage": "https://github.com/webc-site/npm/tree/main/minify_size",
|
|
12
13
|
"license": "MulanPSL-2.0",
|
|
@@ -26,12 +27,8 @@
|
|
|
26
27
|
"dependencies": {
|
|
27
28
|
"@3-/read": "^0.1.4",
|
|
28
29
|
"@3-/utf8": "^0.1.1",
|
|
29
|
-
"@mongodb-js/zstd": "^7.0.0",
|
|
30
30
|
"cli-table3": "^0.6.5",
|
|
31
31
|
"oxc-minify": "^0.135.0",
|
|
32
32
|
"yargs": "^18.0.0"
|
|
33
|
-
}
|
|
34
|
-
"trustedDependencies": [
|
|
35
|
-
"@mongodb-js/zstd"
|
|
36
|
-
]
|
|
33
|
+
}
|
|
37
34
|
}
|