Skip to content

Commit

Permalink
Feat html minify (#10)
Browse files Browse the repository at this point in the history
* Update jsx.ts

* Update jsx.ts

* Update deno.json

* Update test.deno.ts

* Update test.node.ts

* Update package.json

* Update package-lock.json

* Update package.json

* Update tests.yml
  • Loading branch information
maddsua authored Dec 28, 2023
1 parent 34dca82 commit 15e1cc1
Show file tree
Hide file tree
Showing 7 changed files with 1,342 additions and 35 deletions.
10 changes: 2 additions & 8 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ jobs:
- name: Install esbuild
run: curl -fsSL https://esbuild.github.io/dl/latest | sh

- name: Build tests
run: deno task build_test

- name: Run tests
- name: Build and run tests
run: deno task test

test-node:
Expand All @@ -51,8 +48,5 @@ jobs:
registry-url: https://registry.npmjs.org/
- run: npm ci

- name: Build tests
run: npm run build_test

- name: Run tests
- name: Build and run tests
run: npm run test
5 changes: 3 additions & 2 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"tasks": {
"test": "deno run --allow-all test/.temp/test.deno.js",
"build_test": "esbuild test/test.deno.ts --format=esm --bundle --loader:.js=text --loader:.css=text --outfile=test/.temp/test.deno.js"
"test:run": "deno run -A test/.temp/test.deno.js",
"test:build": "esbuild test/test.deno.ts --format=esm --bundle --loader:.js=text --loader:.css=text --outfile=test/.temp/test.deno.js",
"test": "deno task test:build && deno task test:run"
}
}
9 changes: 7 additions & 2 deletions lib/jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ const reactNamingConventions = new Map<string, string>([
["className", "class"]
]);

const collapseWhitespaces = (html: string) => html.replace(/[\t ]+/g, ' ').replace(/[\r\n]/g, '');

interface RenderProps {
externalResourcesRoot?: string;
addDoctype?: boolean;
convertBrTagsToNewlines?: boolean;
minifyHTML?: boolean;
};

abstract class JSXNode {
Expand Down Expand Up @@ -76,7 +78,10 @@ class JSXTextNode extends JSXNode {
this.content = text || '';
};

render() {
render(renderProps?: RenderProps) {
if (renderProps?.minifyHTML) {
return collapseWhitespaces(this.content);
}
return this.content;
}
};
Expand Down
Loading

0 comments on commit 15e1cc1

Please sign in to comment.