@1-/minify_size 0.1.4 → 0.1.6
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 +60 -62
- package/_.js +12 -46
- package/cli.js +1 -1
- package/package.json +1 -2
package/README.md
CHANGED
|
@@ -6,67 +6,66 @@
|
|
|
6
6
|
# @1-/minify_size : Minify JavaScript and report Brotli-compressed size
|
|
7
7
|
|
|
8
8
|
- [@1-/minify_size : Minify JavaScript and report Brotli-compressed size](#1-minify_size-minify-javascript-and-report-brotli-compressed-size)
|
|
9
|
-
- [1.
|
|
10
|
-
- [2. Usage
|
|
11
|
-
- [3. Design
|
|
12
|
-
- [4.
|
|
9
|
+
- [1. Functionality](#1-functionality)
|
|
10
|
+
- [2. Usage](#2-usage)
|
|
11
|
+
- [3. Design](#3-design)
|
|
12
|
+
- [4. Technology Stack](#4-technology-stack)
|
|
13
13
|
- [5. Code Structure](#5-code-structure)
|
|
14
14
|
- [6. History](#6-history)
|
|
15
15
|
- [About](#about)
|
|
16
16
|
|
|
17
|
-
## 1.
|
|
17
|
+
## 1. Functionality
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
Measure JavaScript library transmission size under Brotli-enabled network environments. Processes all `.js` files in a specified directory by:
|
|
20
20
|
|
|
21
|
-
- Bundling
|
|
22
|
-
- UTF-8 encoding
|
|
23
|
-
- Brotli compression via Node.js built-in `node:zlib.brotliCompress`
|
|
24
|
-
-
|
|
21
|
+
- Bundling with `@1-/rolldown` (Rust-based JavaScript bundler)
|
|
22
|
+
- UTF-8 encoding using `@3-/utf8` TextEncoder
|
|
23
|
+
- Brotli compression via Node.js built-in `node:zlib.brotliCompress`
|
|
24
|
+
- Returning total compressed byte count of bundled output
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
Excludes test files matching `/^(|\/)tests?(\/|$)/` and `node_modules` directories.
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
## 2. Usage
|
|
29
|
+
|
|
30
|
+
Install locally:
|
|
29
31
|
|
|
30
32
|
```bash
|
|
31
33
|
npm install @1-/minify_size
|
|
32
34
|
```
|
|
33
35
|
|
|
34
|
-
|
|
36
|
+
Install globally:
|
|
35
37
|
|
|
36
38
|
```bash
|
|
37
39
|
npm install -g @1-/minify_size
|
|
38
40
|
```
|
|
39
41
|
|
|
40
|
-
|
|
42
|
+
Execute with target directory:
|
|
41
43
|
|
|
42
44
|
```bash
|
|
43
45
|
minify_size ./src
|
|
44
46
|
```
|
|
45
47
|
|
|
46
|
-
|
|
48
|
+
Output example:
|
|
47
49
|
|
|
48
50
|
```
|
|
49
|
-
|
|
50
|
-
utils.js 250
|
|
51
|
-
Total bundled size 650
|
|
51
|
+
650
|
|
52
52
|
```
|
|
53
53
|
|
|
54
|
-
## 3. Design
|
|
54
|
+
## 3. Design
|
|
55
55
|
|
|
56
56
|
Execution flow (vertical Mermaid diagram):
|
|
57
57
|
|
|
58
|
-

|
|
59
59
|
|
|
60
|
-
## 4.
|
|
60
|
+
## 4. Technology Stack
|
|
61
61
|
|
|
62
|
-
- **Runtime**: Node.js
|
|
63
|
-
- **Bundler**: `@1-/rolldown` v0.1.7 (Rust-based JavaScript bundler
|
|
64
|
-
- **
|
|
65
|
-
- **
|
|
66
|
-
- **Encoding**: `@3-/utf8` v0.1.1 (TextEncoder-based UTF-8
|
|
67
|
-
- **
|
|
68
|
-
- **
|
|
69
|
-
- **Dependency Management**: npm
|
|
62
|
+
- **Runtime**: Bun / Node.js
|
|
63
|
+
- **Bundler**: `@1-/rolldown` v0.1.7 (Rust-based JavaScript bundler)
|
|
64
|
+
- **Compression**: `node:zlib.brotliCompress` (built-in Brotli)
|
|
65
|
+
- **Argument parsing**: `yargs` v18.0.0
|
|
66
|
+
- **Encoding**: `@3-/utf8` v0.1.1 (TextEncoder-based UTF-8)
|
|
67
|
+
- **File traversal**: `@1-/walk` v0.1.2 (directory traversal utility)
|
|
68
|
+
- **Package management**: npm
|
|
70
69
|
- **Testing**: bun:test
|
|
71
70
|
|
|
72
71
|
## 5. Code Structure
|
|
@@ -74,12 +73,12 @@ Execution flow (vertical Mermaid diagram):
|
|
|
74
73
|
```
|
|
75
74
|
src/
|
|
76
75
|
├── cli.js # CLI entrypoint, parses directory parameter and invokes main function
|
|
77
|
-
└── _.js # Directory traversal, bundling, Brotli compression calculation
|
|
76
|
+
└── _.js # Directory traversal, bundling, Brotli compression calculation
|
|
78
77
|
```
|
|
79
78
|
|
|
80
79
|
## 6. History
|
|
81
80
|
|
|
82
|
-
Brotli was developed by Jyrki Alakuijala and Zoltán Szabadka at Google in 2013.
|
|
81
|
+
Brotli was developed by Jyrki Alakuijala and Zoltán Szabadka at Google in 2013. Initially designed for web font compression, it evolved into a general-purpose algorithm optimized for web transmission and became an industry standard (RFC 7932). Modern JavaScript bundlers like rolldown leverage Rust's performance for sub-second builds while maintaining compatibility with existing JavaScript tooling ecosystems.
|
|
83
82
|
|
|
84
83
|
## About
|
|
85
84
|
|
|
@@ -94,38 +93,40 @@ This library is developed by [WebC.site](https://webc.site).
|
|
|
94
93
|
# @1-/minify_size : Minify JavaScript and report Brotli-compressed size
|
|
95
94
|
|
|
96
95
|
- [@1-/minify_size : Minify JavaScript and report Brotli-compressed size](#1-minify_size-minify-javascript-and-report-brotli-compressed-size)
|
|
97
|
-
- [1.
|
|
98
|
-
- [2.
|
|
96
|
+
- [1. 功能性](#1-功能性)
|
|
97
|
+
- [2. 使用方法](#2-使用方法)
|
|
99
98
|
- [3. 设计思路](#3-设计思路)
|
|
100
99
|
- [4. 技术栈](#4-技术栈)
|
|
101
100
|
- [5. 代码结构](#5-代码结构)
|
|
102
|
-
- [6.
|
|
101
|
+
- [6. 历史背景](#6-历史背景)
|
|
103
102
|
- [关于](#关于)
|
|
104
103
|
|
|
105
|
-
## 1.
|
|
104
|
+
## 1. 功能性
|
|
105
|
+
|
|
106
|
+
测量 JavaScript 库在支持 Brotli 的网络环境中的传输体积。对指定目录中所有 `.js` 文件执行以下操作:
|
|
106
107
|
|
|
107
|
-
|
|
108
|
+
- 使用 `@1-/rolldown`(Rust 实现的 JavaScript 打包器)进行打包
|
|
109
|
+
- 使用 `@3-/utf8` TextEncoder 进行 UTF-8 编码
|
|
110
|
+
- 使用 Node.js 内置 `node:zlib.brotliCompress` 进行 Brotli 压缩
|
|
111
|
+
- 返回整体打包输出的压缩后字节长度
|
|
108
112
|
|
|
109
|
-
|
|
110
|
-
- 将打包后代码编码为 UTF-8 字节流
|
|
111
|
-
- 使用 Node.js 内置 `node:zlib.brotliCompress` 计算 Brotli 压缩后字节长度
|
|
112
|
-
- 汇总各打包产物大小,并计算整体打包压缩后大小
|
|
113
|
+
排除匹配 `/^(|\/)tests?(\/|$)/` 的测试文件和 `node_modules` 目录。
|
|
113
114
|
|
|
114
|
-
## 2.
|
|
115
|
+
## 2. 使用方法
|
|
115
116
|
|
|
116
|
-
|
|
117
|
+
本地安装:
|
|
117
118
|
|
|
118
119
|
```bash
|
|
119
120
|
npm install @1-/minify_size
|
|
120
121
|
```
|
|
121
122
|
|
|
122
|
-
|
|
123
|
+
全局安装:
|
|
123
124
|
|
|
124
125
|
```bash
|
|
125
126
|
npm install -g @1-/minify_size
|
|
126
127
|
```
|
|
127
128
|
|
|
128
|
-
|
|
129
|
+
执行命令并指定目标目录:
|
|
129
130
|
|
|
130
131
|
```bash
|
|
131
132
|
minify_size ./src
|
|
@@ -134,40 +135,37 @@ minify_size ./src
|
|
|
134
135
|
输出示例:
|
|
135
136
|
|
|
136
137
|
```
|
|
137
|
-
|
|
138
|
-
utils.js 250
|
|
139
|
-
整体打包压缩后大小 650
|
|
138
|
+
650
|
|
140
139
|
```
|
|
141
140
|
|
|
142
141
|
## 3. 设计思路
|
|
143
142
|
|
|
144
|
-
|
|
143
|
+
执行流程(垂直 Mermaid 流程图):
|
|
145
144
|
|
|
146
|
-

|
|
147
146
|
|
|
148
147
|
## 4. 技术栈
|
|
149
148
|
|
|
150
|
-
-
|
|
151
|
-
-
|
|
152
|
-
-
|
|
153
|
-
-
|
|
154
|
-
-
|
|
155
|
-
-
|
|
156
|
-
-
|
|
157
|
-
-
|
|
158
|
-
- **Testing**: bun:test
|
|
149
|
+
- **运行时**: Bun / Node.js
|
|
150
|
+
- **打包器**: `@1-/rolldown` v0.1.7 (Rust 实现的 JavaScript 打包器)
|
|
151
|
+
- **压缩算法**: `node:zlib.brotliCompress` (内置 Brotli)
|
|
152
|
+
- **参数解析**: `yargs` v18.0.0
|
|
153
|
+
- **编码**: `@3-/utf8` v0.1.1 (TextEncoder 实现的 UTF-8)
|
|
154
|
+
- **文件遍历**: `@1-/walk` v0.1.2 (目录遍历工具)
|
|
155
|
+
- **包管理**: npm
|
|
156
|
+
- **测试**: bun:test
|
|
159
157
|
|
|
160
158
|
## 5. 代码结构
|
|
161
159
|
|
|
162
160
|
```
|
|
163
161
|
src/
|
|
164
|
-
├── cli.js # CLI
|
|
165
|
-
└── _.js # 目录遍历、打包处理、Brotli
|
|
162
|
+
├── cli.js # CLI 入口,解析目录参数并调用主函数
|
|
163
|
+
└── _.js # 目录遍历、打包处理、Brotli 压缩计算
|
|
166
164
|
```
|
|
167
165
|
|
|
168
|
-
## 6.
|
|
166
|
+
## 6. 历史背景
|
|
169
167
|
|
|
170
|
-
Brotli 由 Google 的 Jyrki Alakuijala 和 Zoltán Szabadka 于 2013
|
|
168
|
+
Brotli 由 Google 的 Jyrki Alakuijala 和 Zoltán Szabadka 于 2013 年开发。最初专为网页字体压缩设计,后发展为通用压缩算法,针对网页传输优化,并成为行业标准(RFC 7932)。现代 JavaScript 打包器如 rolldown 利用 Rust 的性能优势实现亚秒级构建,同时保持与现有 JavaScript 工具生态的兼容性。
|
|
171
169
|
|
|
172
170
|
## 关于
|
|
173
171
|
|
package/_.js
CHANGED
|
@@ -1,50 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { join, isAbsolute } from "node:path";
|
|
2
2
|
import { realpathSync } from "node:fs";
|
|
3
3
|
import { promisify } from "node:util";
|
|
4
4
|
import { brotliCompress } from "node:zlib";
|
|
5
|
-
import Table from "cli-table3";
|
|
6
5
|
import { FILE } from "@1-/walk";
|
|
7
6
|
import walkRelIgnore from "@1-/walk/walkRelIgnore.js";
|
|
8
7
|
import utf8e from "@3-/utf8";
|
|
9
8
|
import bundle from "@1-/rolldown";
|
|
10
9
|
|
|
11
10
|
const BROTLI = promisify(brotliCompress),
|
|
12
|
-
TABLE_STYLE = { "padding-left": 0, "padding-right": 0 },
|
|
13
|
-
NO_BORDER = {
|
|
14
|
-
top: "",
|
|
15
|
-
"top-mid": "",
|
|
16
|
-
"top-left": "",
|
|
17
|
-
"top-right": "",
|
|
18
|
-
bottom: "",
|
|
19
|
-
"bottom-mid": "",
|
|
20
|
-
"bottom-left": "",
|
|
21
|
-
"bottom-right": "",
|
|
22
|
-
left: "",
|
|
23
|
-
"left-mid": "",
|
|
24
|
-
mid: "",
|
|
25
|
-
"mid-mid": "",
|
|
26
|
-
right: "",
|
|
27
|
-
"right-mid": "",
|
|
28
|
-
middle: " ",
|
|
29
|
-
},
|
|
30
11
|
/*
|
|
31
12
|
获取字符串 brotli 压缩后大小
|
|
32
13
|
参数: str 待压缩字符串
|
|
33
14
|
返回值: 字节数
|
|
34
15
|
*/
|
|
35
|
-
br = async (str) => (await BROTLI(utf8e(str))).length
|
|
36
|
-
/*
|
|
37
|
-
输出打包大小表格
|
|
38
|
-
参数:
|
|
39
|
-
list 包含 [相对路径, 大小] 的数组
|
|
40
|
-
total 整体压缩后大小
|
|
41
|
-
*/
|
|
42
|
-
show = (list, total) => {
|
|
43
|
-
const table = new Table({ chars: NO_BORDER, style: TABLE_STYLE });
|
|
44
|
-
list.forEach(([rel_path, size]) => table.push([rel_path, size]));
|
|
45
|
-
table.push(["整体打包压缩后大小", total]);
|
|
46
|
-
console.log(table.toString());
|
|
47
|
-
};
|
|
16
|
+
br = async (str) => (await BROTLI(utf8e(str))).length;
|
|
48
17
|
|
|
49
18
|
/*
|
|
50
19
|
打包并计算指定目录下 JS 文件压缩后大小
|
|
@@ -64,7 +33,6 @@ export default async (dir) => {
|
|
|
64
33
|
});
|
|
65
34
|
|
|
66
35
|
if (!files.length) {
|
|
67
|
-
show([], 0);
|
|
68
36
|
return 0;
|
|
69
37
|
}
|
|
70
38
|
|
|
@@ -74,18 +42,16 @@ export default async (dir) => {
|
|
|
74
42
|
out_map[abs] = abs;
|
|
75
43
|
});
|
|
76
44
|
|
|
77
|
-
const chunks = await bundle(
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
total_size = await br(sizes.map(([, , code]) => code).join(""));
|
|
88
|
-
show(sizes, total_size);
|
|
45
|
+
const chunks = await bundle(
|
|
46
|
+
input,
|
|
47
|
+
{
|
|
48
|
+
external: (id) => !id.startsWith(".") && !isAbsolute(id),
|
|
49
|
+
},
|
|
50
|
+
true,
|
|
51
|
+
real_dir,
|
|
52
|
+
out_map,
|
|
53
|
+
),
|
|
54
|
+
total_size = await br(chunks.map(([, code]) => code).join(""));
|
|
89
55
|
|
|
90
56
|
return total_size;
|
|
91
57
|
};
|
package/cli.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@1-/minify_size",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "Minify JS and output brotli compressed size | 压缩 JS 并输出 brotli 压缩后大小",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"br",
|
|
@@ -28,7 +28,6 @@
|
|
|
28
28
|
"@1-/rolldown": "^0.1.7",
|
|
29
29
|
"@1-/walk": "^0.1.2",
|
|
30
30
|
"@3-/utf8": "^0.1.1",
|
|
31
|
-
"cli-table3": "^0.6.5",
|
|
32
31
|
"yargs": "^18.0.0"
|
|
33
32
|
}
|
|
34
33
|
}
|