Skip to content

Commit fe3db66

Browse files
committedFeb 18, 2025·
build: selectively minify js hash impl
1 parent b7c17dd commit fe3db66

File tree

4 files changed

+291
-0
lines changed

4 files changed

+291
-0
lines changed
 

‎build.config.ts

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { defineBuildConfig } from "unbuild";
2+
import { transform } from "esbuild";
3+
import { rm } from "node:fs/promises";
4+
5+
export default defineBuildConfig({
6+
hooks: {
7+
"rollup:options"(ctx, opts) {
8+
opts.plugins.push({
9+
name: "selective-minify",
10+
async transform(code, id) {
11+
if (id.includes("crypto/js")) {
12+
const res = await transform(code, {
13+
minify: true,
14+
});
15+
return res.code;
16+
}
17+
},
18+
});
19+
},
20+
async "build:done"() {
21+
await rm("dist/index.d.ts");
22+
await rm("dist/crypto/js/index.d.ts");
23+
await rm("dist/crypto/node/index.d.ts");
24+
},
25+
},
26+
});

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"@vitest/coverage-v8": "^3.0.6",
4343
"benchmark": "^2.1.4",
4444
"changelogen": "^0.5.7",
45+
"esbuild": "^0.25.0",
4546
"eslint": "^9.20.1",
4647
"eslint-config-unjs": "^0.4.2",
4748
"prettier": "^3.5.1",

‎pnpm-lock.yaml

+261
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎test/crypto.test.ts

+3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ import { describe, expect, it } from "vitest";
33
import * as cryptoJS from "../src/crypto/js";
44
import * as cryptoNode from "../src/crypto/node";
55

6+
// import * as cryptoDistJS from "../dist/crypto/js/index.mjs";
7+
68
const impls = {
79
js: cryptoJS,
810
node: cryptoNode,
11+
// distJs: cryptoDistJS,
912
};
1013

1114
describe("crypto", () => {

0 commit comments

Comments
 (0)
Please sign in to comment.