@1-/minify_size 0.1.1 → 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.
- package/README.md +2 -2
- package/_.js +3 -3
- package/cli.js +2 -1
- package/file.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -61,7 +61,7 @@ Execution process:
|
|
|
61
61
|
- **Arg Parser**: `yargs`
|
|
62
62
|
- **Encoding**: `@3-/utf8` (TextEncoder-based UTF-8 encoding)
|
|
63
63
|
- **Output Formatting**: `cli-table3` (Formatted tabular output)
|
|
64
|
-
- **File
|
|
64
|
+
- **File Reading**: `@3-/read` (Lightweight file reading utility)
|
|
65
65
|
- **Dependency Management**: npm
|
|
66
66
|
- **Testing**: bun:test
|
|
67
67
|
|
|
@@ -146,7 +146,7 @@ file.js 250
|
|
|
146
146
|
- **Arg Parser**: `yargs`
|
|
147
147
|
- **Encoding**: `@3-/utf8` (TextEncoder-based UTF-8 encoding)
|
|
148
148
|
- **Output Formatting**: `cli-table3` (Formatted tabular output)
|
|
149
|
-
- **File
|
|
149
|
+
- **File Reading**: `@3-/read` (Lightweight file reading utility)
|
|
150
150
|
- **Dependency Management**: npm
|
|
151
151
|
- **Testing**: bun:test
|
|
152
152
|
|
package/_.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { readdir } from "node:fs/promises";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import Table from "cli-table3";
|
|
4
|
-
import
|
|
4
|
+
import minify from "./file.js";
|
|
5
5
|
|
|
6
6
|
const NO_BORDER = {
|
|
7
7
|
top: "",
|
|
@@ -27,10 +27,11 @@ export default async (dir) => {
|
|
|
27
27
|
sizes = await Promise.all(
|
|
28
28
|
js.map(async ({ name }) => {
|
|
29
29
|
const file_path = join(dir, name),
|
|
30
|
-
size = await
|
|
30
|
+
size = await minify(file_path);
|
|
31
31
|
return [name, size];
|
|
32
32
|
}),
|
|
33
33
|
),
|
|
34
|
+
total = sizes.reduce((acc, [, size]) => acc + size, 0),
|
|
34
35
|
table = new Table({
|
|
35
36
|
chars: NO_BORDER,
|
|
36
37
|
style: { "padding-left": 0, "padding-right": 0 },
|
|
@@ -38,7 +39,6 @@ export default async (dir) => {
|
|
|
38
39
|
|
|
39
40
|
sizes.forEach(([name, size]) => table.push([name, size]));
|
|
40
41
|
|
|
41
|
-
const total = sizes.reduce((acc, [, size]) => acc + size, 0);
|
|
42
42
|
table.push(["合计", total]);
|
|
43
43
|
console.log(table.toString());
|
|
44
44
|
return total;
|
package/cli.js
CHANGED
|
@@ -3,9 +3,10 @@ import yargs from "yargs";
|
|
|
3
3
|
import { hideBin } from "yargs/helpers";
|
|
4
4
|
import minify from "./_.js";
|
|
5
5
|
|
|
6
|
+
// 解析参数并压缩指定目录下所有 JS 文件
|
|
6
7
|
const { dir } = yargs(hideBin(process.argv))
|
|
7
8
|
.usage("Usage: $0 <dir>")
|
|
8
|
-
.command("$0 <dir>", "minify js and show
|
|
9
|
+
.command("$0 <dir>", "minify js and show brotli size", (y) => {
|
|
9
10
|
y.positional("dir", {
|
|
10
11
|
describe: "directory to minify",
|
|
11
12
|
type: "string",
|
package/file.js
CHANGED
|
@@ -5,7 +5,7 @@ import { brotliCompress } from "node:zlib";
|
|
|
5
5
|
import utf8e from "@3-/utf8";
|
|
6
6
|
import { basename } from "node:path";
|
|
7
7
|
|
|
8
|
-
const
|
|
8
|
+
const BROTLI = promisify(brotliCompress);
|
|
9
9
|
|
|
10
10
|
// file_path: 文件路径;返回 minify 且 brotli 压缩后的字节数
|
|
11
11
|
export default async (file_path) => {
|
|
@@ -14,6 +14,6 @@ export default async (file_path) => {
|
|
|
14
14
|
compress: { target: "esnext" },
|
|
15
15
|
codegen: { removeWhitespace: true },
|
|
16
16
|
}),
|
|
17
|
-
zip = await
|
|
17
|
+
zip = await BROTLI(utf8e(mini));
|
|
18
18
|
return zip.length;
|
|
19
19
|
};
|