Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions cjs/ucontent.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ class HTML extends UContent {
/**
* @returns {HTML} The HTML instance as minified.
*/
min() {
min(options) {
return this.minified ? this : (
cache.get(this) ||
cache.set(
this,
new HTML(html.minify(this.toString(), htmlOptions), true)
new HTML(html.minify(this.toString(), {...htmlOptions, ...options}), true)
)
);
}
Expand All @@ -86,12 +86,12 @@ class JS extends UContent {
/**
* @returns {JS} The JS instance as minified.
*/
min() {
min(options) {
return this.minified ? this : (
cache.get(this) ||
cache.set(
this,
new JS(Terser.minify(this.toString(), jsOptions).code, true)
new JS(Terser.minify(this.toString(), {...jsOptions, ...options}).code, true)
)
);
}
Expand Down Expand Up @@ -120,12 +120,12 @@ class SVG extends UContent {
/**
* @returns {SVG} The SVG instance as minified.
*/
min() {
min(options) {
return this.minified ? this : (
cache.get(this) ||
cache.set(
this,
new SVG(html.minify(this.toString(), svgOptions), true)
new SVG(html.minify(this.toString(), {...svgOptions, ...options}), true)
)
);
}
Expand Down
4 changes: 2 additions & 2 deletions cjs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ const getValue = value => {
return value == null ? '' : escape(String(value));
};

const minify = ($, svg) => html.minify($, svg ? svgOptions : htmlOptions);
const minify = ($, svg, options) => html.minify($, svg ? {...svgOptions, ...options} : {...htmlOptions, ...options});

const parse = (template, expectedLength, svg, minified) => {
const text = instrument(template, prefix, svg);
const html = minified ? minify(text, svg) : text;
const html = minified ? minify(text, svg, minified) : text;
const updates = [];
let i = 0;
let match = null;
Expand Down
12 changes: 6 additions & 6 deletions esm/ucontent.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ export class HTML extends UContent {
/**
* @returns {HTML} The HTML instance as minified.
*/
min() {
min(options) {
return this.minified ? this : (
cache.get(this) ||
cache.set(
this,
new HTML(html.minify(this.toString(), htmlOptions), true)
new HTML(html.minify(this.toString(), {...htmlOptions, ...options}), true)
)
);
}
Expand All @@ -83,12 +83,12 @@ export class JS extends UContent {
/**
* @returns {JS} The JS instance as minified.
*/
min() {
min(options) {
return this.minified ? this : (
cache.get(this) ||
cache.set(
this,
new JS(Terser.minify(this.toString(), jsOptions).code, true)
new JS(Terser.minify(this.toString(), {...jsOptions, ...options}).code, true)
)
);
}
Expand All @@ -115,12 +115,12 @@ export class SVG extends UContent {
/**
* @returns {SVG} The SVG instance as minified.
*/
min() {
min(options) {
return this.minified ? this : (
cache.get(this) ||
cache.set(
this,
new SVG(html.minify(this.toString(), svgOptions), true)
new SVG(html.minify(this.toString(), {...svgOptions, ...options}), true)
)
);
}
Expand Down
4 changes: 2 additions & 2 deletions esm/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ const getValue = value => {
return value == null ? '' : escape(String(value));
};

const minify = ($, svg) => html.minify($, svg ? svgOptions : htmlOptions);
const minify = ($, svg, options) => html.minify($, svg ? {...svgOptions, ...options} : {...htmlOptions, ...options});

export const parse = (template, expectedLength, svg, minified) => {
const text = instrument(template, prefix, svg);
const html = minified ? minify(text, svg) : text;
const html = minified ? minify(text, svg, minified) : text;
const updates = [];
let i = 0;
let match = null;
Expand Down
26 changes: 26 additions & 0 deletions test/implicit-min.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const {render, html} = require('../cjs');

html.minified = { removeComments: false }

require('http').createServer((req, res) => {
res.writeHead(200, {'content-type': 'text/html;charset=utf-8'});
render(content => res.end(content), html`
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ucontent</title>
</head>
<body>${html`
<h1>Hello There</h1>
<!-- Hello from comments -->
<p>
Thank you for visiting uhtml at ${new Date()}
</p>
`}</body>
</html>
`);
}).listen(8080);

console.log('http://localhost:8080/');
24 changes: 24 additions & 0 deletions test/min-options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const {render, html} = require('../cjs');

require('http').createServer((req, res) => {
res.writeHead(200, {'content-type': 'text/html;charset=utf-8'});
render(content => res.end(content), html`
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ucontent</title>
</head>
<body>${html`
<h1>Hello There</h1>
<!-- Hello from comments -->
<p>
Thank you for visiting uhtml at ${new Date()}
</p>
`}</body>
</html>
`.min({ removeComments: false }));
}).listen(8080);

console.log('http://localhost:8080/');