Skip to content

Commit 7f76b89

Browse files
feat: modernize minify-literals minifiers and API
Signed-off-by: Henry <mail@henrygressmann.de>
1 parent 766b8e7 commit 7f76b89

15 files changed

Lines changed: 702 additions & 1081 deletions

File tree

bun.lock

Lines changed: 64 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/minify-literals/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# minify-literals
22

3+
## 2.0.0
4+
5+
### Major Changes
6+
7+
- Replace html-minifier-terser/clean-css with html-minifier-next/Lightning CSS and simplify the options API.
8+
- Remove custom strategy/parser/MagicString hooks: use `html`, `css`, `htmlTags`, `cssTags`, and `sourceMap` options instead.
9+
310
## 1.0.10
411

512
### Patch Changes

packages/minify-literals/README.md

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
> Minify HTML & CSS markup inside JavaScript/TypeScript template literal strings.
44
5-
Uses [html-minifier-terser](https://www.npmjs.com/package/html-minifier-terser) to minify HTML and [clean-css](https://www.npmjs.com/package/clean-css) to minify CSS.
5+
Uses [html-minifier-next](https://www.npmjs.com/package/html-minifier-next) to minify HTML and [lightningcss](https://lightningcss.dev/) to minify CSS.
66

77
## Installation
88

@@ -60,22 +60,32 @@ console.log(map);
6060
## Options
6161

6262
```ts
63-
export interface Options {
63+
export type Options = {
64+
/** Source filename used for parsing and source map generation. */
65+
fileName?: string;
66+
6467
/**
65-
* Minify HTML options, see https://github.com/terser/html-minifier-terser#options-quick-reference
66-
* @default .//src/defaultOptions.ts
68+
* Options passed to html-minifier-next, or a custom HTML minifier. Set to false to skip HTML and SVG templates.
6769
*/
68-
minifyOptions?: Partial<minify.Options>;
70+
html?:
71+
| false
72+
| Partial<HTMLMinifyOptions>
73+
| ((html: string) => string | Promise<string>);
6974

7075
/**
71-
* Override the default strategy for how to minify HTML.
72-
* More info:
73-
* https://github.com/explodingcamera/esm/blob/main/packages/minify-literals/lib/strategy.ts
74-
*
75-
* @optional
76+
* Options passed to Lightning CSS, or a custom CSS minifier. Set to false to skip CSS.
7677
*/
77-
strategy: S;
78-
}
78+
css?: false | CSSMinifyOptions | ((css: string) => string | Promise<string>);
79+
80+
/** Template tag substrings treated as HTML. Defaults to ["html", "svg"]. */
81+
htmlTags?: readonly string[];
82+
83+
/** Template tag substrings treated as CSS. Defaults to ["css", "style", "styles", "styled"]. */
84+
cssTags?: readonly string[];
85+
86+
/** Generate a source map for changed code. Defaults to true. */
87+
sourceMap?: boolean;
88+
};
7989
```
8090

8191
## Related Packages
@@ -84,12 +94,4 @@ export interface Options {
8494

8595
## Credits
8696

87-
This package is based on [minify-html-literals](https://github.com/asyncLiz/minify-html-literals) by [Elizabeth Mitchell](https://github.com/asyncLiz)
88-
I've fixed a few bugs, ported it to ES modules, and refactored it a bit.
89-
90-
Some of the fixed bugs:
91-
92-
- https://github.com/asyncLiz/minify-html-literals/issues/37
93-
- https://github.com/asyncLiz/minify-html-literals/issues/45
94-
- https://github.com/asyncLiz/minify-html-literals/issues/46
95-
- https://github.com/asyncLiz/minify-html-literals/issues/40
97+
This package was originally a fork of [minify-html-literals](https://github.com/asyncLiz/minify-html-literals) by [Elizabeth Mitchell](https://github.com/asyncLiz)

0 commit comments

Comments
 (0)