Skip to content

Commit

Permalink
feat: Add minifySync and examples (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
yisibl authored Sep 23, 2022
1 parent aab83bb commit c8e19b9
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 25 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Built files
*.js
!index.js
!binding.js
*.map
*.d.ts
Expand Down
24 changes: 24 additions & 0 deletions packages/css/examples/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const swc = require("../lib/index.js");

const css = `
.foo {
color: #FFFFFF;
margin: 20px;
margin-bottom: 10px;
}
`;

async function main() {
console.time("🚀 minify Time");
const output = await swc.minify(Buffer.from(css), {});
console.timeEnd("🚀 minify Time");
console.log(output.code.length + " bytes");
console.log(output.code, "\n");
}
main();

console.time("🚀 minifySync Time");
const outputSync = swc.minifySync(Buffer.from(css), {});
console.timeEnd("🚀 minifySync Time");
console.log(outputSync.code.length + " bytes");
console.log(outputSync.code, "\n");
11 changes: 0 additions & 11 deletions packages/css/lib/index.js

This file was deleted.

4 changes: 4 additions & 0 deletions packages/css/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ export async function minify(
return binding.minify(content, toBuffer(options));
}

export function minifySync(content: Buffer, options: any) {
return binding.minifySync(content, toBuffer(options));
}

function toBuffer(t: any): Buffer {
return Buffer.from(JSON.stringify(t));
}
2 changes: 1 addition & 1 deletion packages/css/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.11",
"description": "Super-fast alternative for postcss",
"homepage": "https://swc.rs",
"main": "./index.js",
"main": "./lib/index.js",
"author": "강동윤 <[email protected]>",
"license": "Apache-2.0",
"keywords": [
Expand Down
11 changes: 0 additions & 11 deletions packages/html/lib/index.js

This file was deleted.

4 changes: 4 additions & 0 deletions packages/html/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ export async function minify(content: Buffer, options: any): Promise<string> {
return binding.minify(content, toBuffer(options));
}

export function minifySync(content: Buffer, options: any) {
return binding.minifySync(content, toBuffer(options));
}

function toBuffer(t: any): Buffer {
return Buffer.from(JSON.stringify(t));
}
2 changes: 1 addition & 1 deletion packages/html/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.11",
"description": "Super-fast alternative for posthtml",
"homepage": "https://swc.rs",
"main": "./index.js",
"main": "./lib/index.js",
"author": "강동윤 <[email protected]>",
"license": "Apache-2.0",
"keywords": [
Expand Down

0 comments on commit c8e19b9

Please sign in to comment.