Skip to content

Commit c8e19b9

Browse files
authored
feat: Add minifySync and examples (#12)
1 parent aab83bb commit c8e19b9

File tree

8 files changed

+34
-25
lines changed

8 files changed

+34
-25
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Built files
22
*.js
3-
!index.js
43
!binding.js
54
*.map
65
*.d.ts

packages/css/examples/index.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const swc = require("../lib/index.js");
2+
3+
const css = `
4+
.foo {
5+
color: #FFFFFF;
6+
margin: 20px;
7+
margin-bottom: 10px;
8+
}
9+
`;
10+
11+
async function main() {
12+
console.time("🚀 minify Time");
13+
const output = await swc.minify(Buffer.from(css), {});
14+
console.timeEnd("🚀 minify Time");
15+
console.log(output.code.length + " bytes");
16+
console.log(output.code, "\n");
17+
}
18+
main();
19+
20+
console.time("🚀 minifySync Time");
21+
const outputSync = swc.minifySync(Buffer.from(css), {});
22+
console.timeEnd("🚀 minifySync Time");
23+
console.log(outputSync.code.length + " bytes");
24+
console.log(outputSync.code, "\n");

packages/css/lib/index.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

packages/css/lib/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ export async function minify(
77
return binding.minify(content, toBuffer(options));
88
}
99

10+
export function minifySync(content: Buffer, options: any) {
11+
return binding.minifySync(content, toBuffer(options));
12+
}
13+
1014
function toBuffer(t: any): Buffer {
1115
return Buffer.from(JSON.stringify(t));
1216
}

packages/css/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.0.11",
44
"description": "Super-fast alternative for postcss",
55
"homepage": "https://swc.rs",
6-
"main": "./index.js",
6+
"main": "./lib/index.js",
77
"author": "강동윤 <kdy1997.dev@gmail.com>",
88
"license": "Apache-2.0",
99
"keywords": [

packages/html/lib/index.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

packages/html/lib/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ export async function minify(content: Buffer, options: any): Promise<string> {
44
return binding.minify(content, toBuffer(options));
55
}
66

7+
export function minifySync(content: Buffer, options: any) {
8+
return binding.minifySync(content, toBuffer(options));
9+
}
10+
711
function toBuffer(t: any): Buffer {
812
return Buffer.from(JSON.stringify(t));
913
}

packages/html/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.0.11",
44
"description": "Super-fast alternative for posthtml",
55
"homepage": "https://swc.rs",
6-
"main": "./index.js",
6+
"main": "./lib/index.js",
77
"author": "강동윤 <kdy1997.dev@gmail.com>",
88
"license": "Apache-2.0",
99
"keywords": [

0 commit comments

Comments
 (0)