htmlnano 2.1.3 → 2.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -15
- package/dist/helpers.d.ts +16 -0
- package/dist/index.d.ts +79 -0
- package/dist/presets/ampSafe.d.ts +47 -0
- package/dist/presets/max.d.ts +47 -0
- package/dist/presets/safe.d.ts +47 -0
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -7,21 +7,22 @@ Modular HTML minifier, built on top of the [PostHTML](https://github.com/posthtm
|
|
|
7
7
|
## Benchmarks
|
|
8
8
|
|
|
9
9
|
[html-minifier-terser]: https://www.npmjs.com/package/html-minifier-terser/v/7.2.0
|
|
10
|
-
[html-minifier-next]: https://www.npmjs.com/package/html-minifier-next/v/1.
|
|
11
|
-
[htmlnano]: https://www.npmjs.com/package/htmlnano/v/2.1.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
|
16
|
-
|
|
|
17
|
-
| [
|
|
18
|
-
| [
|
|
19
|
-
| [
|
|
20
|
-
| [
|
|
21
|
-
| [
|
|
22
|
-
| [
|
|
23
|
-
| [
|
|
24
|
-
|
|
|
10
|
+
[html-minifier-next]: https://www.npmjs.com/package/html-minifier-next/v/1.4.0
|
|
11
|
+
[htmlnano]: https://www.npmjs.com/package/htmlnano/v/2.1.3
|
|
12
|
+
[minify]: https://www.npmjs.com/package/@tdewolff/minify/v/2.24.2
|
|
13
|
+
[minify-html]: https://www.npmjs.com/package/@minify-html/node/v/0.16.4
|
|
14
|
+
|
|
15
|
+
| Website | Source (KB) | [html-minifier-terser] | [html-minifier-next] | [htmlnano] | [minify] | [minify-html] |
|
|
16
|
+
| ----------------------------------------------------------- | ----------: | ---------------------: | -------------------: | ---------: | -------: | ------------: |
|
|
17
|
+
| [stackoverflow.blog](https://stackoverflow.blog/) | 166 | 3.3% | 3.3% | 8.3% | 4.6% | 4.0% |
|
|
18
|
+
| [github.com](https://github.com/) | 541 | 3.7% | 3.7% | 18.1% | 7.9% | 6.2% |
|
|
19
|
+
| [en.wikipedia.org](https://en.wikipedia.org/wiki/Main_Page) | 220 | 4.6% | 4.6% | 4.9% | 6.2% | 2.9% |
|
|
20
|
+
| [npmjs.com](https://www.npmjs.com/package/eslint) | 460 | 0.5% | 0.5% | 0.9% | 3.6% | 0.7% |
|
|
21
|
+
| [tc39.es](https://tc39.es/ecma262/) | 7198 | 8.5% | 8.5% | 8.7% | 9.5% | 9.1% |
|
|
22
|
+
| [apple.com](https://www.apple.com/) | 190 | 7.6% | 7.6% | 12.1% | 10.5% | 8.1% |
|
|
23
|
+
| [w3.org](https://www.w3.org/) | 49 | 18.9% | 18.9% | 23.0% | 24.1% | 19.9% |
|
|
24
|
+
| [weather.com](https://weather.com) | 1770 | 0.2% | 0.2% | 12.1% | 11.9% | 0.6% |
|
|
25
|
+
| **Avg. minify rate** | | **5.9%** | **5.9%** | **11.0%** | **9.8%** | **6.4%** |
|
|
25
26
|
|
|
26
27
|
Latest benchmarks: https://github.com/maltsev/html-minifiers-benchmark (updated daily).
|
|
27
28
|
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import PostHTML from 'posthtml';
|
|
2
|
+
|
|
3
|
+
type PostHTMLNodeLike = PostHTML.Node | string;
|
|
4
|
+
|
|
5
|
+
declare function isAmpBoilerplate(node: PostHTML.Node): boolean;
|
|
6
|
+
declare function isComment(content: PostHTMLNodeLike | null): boolean;
|
|
7
|
+
declare function isConditionalComment(content: string): boolean;
|
|
8
|
+
declare function isStyleNode(node: PostHTML.Node): boolean | undefined;
|
|
9
|
+
declare function extractCssFromStyleNode(node: PostHTML.Node): string | undefined;
|
|
10
|
+
declare function isEventHandler(attributeName: string): boolean | "";
|
|
11
|
+
declare function extractTextContentFromNode(node: PostHTML.Node): string;
|
|
12
|
+
declare function optionalImport<Module = unknown, Default = Module>(moduleName: string): Promise<(Module & {
|
|
13
|
+
default?: Default;
|
|
14
|
+
}) | NonNullable<Default> | null>;
|
|
15
|
+
|
|
16
|
+
export { extractCssFromStyleNode, extractTextContentFromNode, isAmpBoilerplate, isComment, isConditionalComment, isEventHandler, isStyleNode, optionalImport };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import PostHTML from 'posthtml';
|
|
2
|
+
import { MinifyOptions } from 'terser';
|
|
3
|
+
import { Options } from 'cssnano';
|
|
4
|
+
import { Config } from 'svgo';
|
|
5
|
+
|
|
6
|
+
type PostHTMLTreeLike = [PostHTML.Node] & PostHTML.NodeAPI & {
|
|
7
|
+
options?: {
|
|
8
|
+
quoteAllAttributes?: boolean | undefined;
|
|
9
|
+
} | undefined;
|
|
10
|
+
render(): string;
|
|
11
|
+
render(node: PostHTML.Node | PostHTMLTreeLike, renderOptions?: any): string;
|
|
12
|
+
};
|
|
13
|
+
type MaybeArray<T> = T | Array<T>;
|
|
14
|
+
type PostHTMLNodeLike = PostHTML.Node | string;
|
|
15
|
+
interface HtmlnanoOptions {
|
|
16
|
+
skipConfigLoading?: boolean;
|
|
17
|
+
skipInternalWarnings?: boolean;
|
|
18
|
+
collapseAttributeWhitespace?: boolean;
|
|
19
|
+
collapseBooleanAttributes?: {
|
|
20
|
+
amphtml?: boolean;
|
|
21
|
+
};
|
|
22
|
+
collapseWhitespace?: 'conservative' | 'all' | 'aggressive';
|
|
23
|
+
custom?: MaybeArray<(tree: PostHTMLTreeLike, options?: any) => (PostHTML.Node | PostHTMLTreeLike)>;
|
|
24
|
+
deduplicateAttributeValues?: boolean;
|
|
25
|
+
minifyUrls?: URL | string | false;
|
|
26
|
+
mergeStyles?: boolean;
|
|
27
|
+
mergeScripts?: boolean;
|
|
28
|
+
minifyCss?: Options | boolean;
|
|
29
|
+
minifyConditionalComments?: boolean;
|
|
30
|
+
minifyJs?: MinifyOptions | boolean;
|
|
31
|
+
minifyJson?: boolean;
|
|
32
|
+
minifySvg?: Config | boolean;
|
|
33
|
+
normalizeAttributeValues?: boolean;
|
|
34
|
+
removeAttributeQuotes?: boolean;
|
|
35
|
+
removeComments?: boolean | 'safe' | 'all' | RegExp | ((comment: string) => boolean);
|
|
36
|
+
removeEmptyAttributes?: boolean;
|
|
37
|
+
removeRedundantAttributes?: boolean;
|
|
38
|
+
removeOptionalTags?: boolean;
|
|
39
|
+
removeUnusedCss?: boolean;
|
|
40
|
+
sortAttributes?: boolean | 'alphabetical' | 'frequency';
|
|
41
|
+
sortAttributesWithLists?: boolean | 'alphabetical' | 'frequency';
|
|
42
|
+
}
|
|
43
|
+
interface HtmlnanoPreset extends Omit<HtmlnanoOptions, 'skipConfigLoading'> {
|
|
44
|
+
}
|
|
45
|
+
type HtmlnanoPredefinedPreset = 'safe' | 'ampSafe' | 'max';
|
|
46
|
+
type HtmlnanoPredefinedPresets = Record<HtmlnanoPredefinedPreset, HtmlnanoPreset>;
|
|
47
|
+
type HtmlnanoOptionsConfigFile = Omit<HtmlnanoOptions, 'skipConfigLoading'> & {
|
|
48
|
+
preset?: HtmlnanoPredefinedPreset;
|
|
49
|
+
};
|
|
50
|
+
type HtmlnanoModuleAttrsHandler = (attrs: Record<string, string | boolean | void>, node: PostHTML.Node) => Record<string, string | boolean | void>;
|
|
51
|
+
type HtmlnanoModuleContentHandler = (content: Array<PostHTMLNodeLike>, node: PostHTML.Node) => MaybeArray<PostHTMLNodeLike>;
|
|
52
|
+
type HtmlnanoModuleNodeHandler = (node: PostHTMLNodeLike) => PostHTML.Node | string;
|
|
53
|
+
type OptionalOptions<T> = T extends boolean | string | Function | number | null | undefined ? T : T extends object ? Partial<T> : T;
|
|
54
|
+
type HtmlnanoModule<Options = any> = {
|
|
55
|
+
onAttrs?: (options: Partial<HtmlnanoOptions>, moduleOptions: OptionalOptions<Options>) => HtmlnanoModuleAttrsHandler;
|
|
56
|
+
onContent?: (options: Partial<HtmlnanoOptions>, moduleOptions: OptionalOptions<Options>) => HtmlnanoModuleContentHandler;
|
|
57
|
+
onNode?: (options: Partial<HtmlnanoOptions>, moduleOptions: OptionalOptions<Options>) => HtmlnanoModuleNodeHandler;
|
|
58
|
+
default?: (tree: PostHTMLTreeLike, options: Partial<HtmlnanoOptions>, moduleOptions: OptionalOptions<Options>) => PostHTMLTreeLike | Promise<PostHTMLTreeLike>;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
declare function loadConfig(options?: HtmlnanoOptions, preset?: HtmlnanoPreset, configPath?: string): [Partial<HtmlnanoOptions>, HtmlnanoPreset];
|
|
62
|
+
declare function htmlnano(optionsRun?: HtmlnanoOptions, presetRun?: HtmlnanoPreset): PostHTML.Plugin<never>;
|
|
63
|
+
declare namespace htmlnano {
|
|
64
|
+
var presets: HtmlnanoPredefinedPresets;
|
|
65
|
+
var getRequiredOptionalDependencies: typeof getRequiredOptionalDependencies;
|
|
66
|
+
var process: typeof process;
|
|
67
|
+
var htmlMinimizerWebpackPluginMinify: typeof htmlMinimizerWebpackPluginMinify;
|
|
68
|
+
var loadConfig: typeof loadConfig;
|
|
69
|
+
}
|
|
70
|
+
declare function getRequiredOptionalDependencies(optionsRun: HtmlnanoOptions, presetRun: HtmlnanoPreset): string[];
|
|
71
|
+
declare function process(html: string, options?: HtmlnanoOptions, preset?: HtmlnanoPreset, postHtmlOptions?: PostHTML.Options): Promise<PostHTML.Result<unknown>>;
|
|
72
|
+
declare function htmlMinimizerWebpackPluginMinify(input: {
|
|
73
|
+
[file: string]: string;
|
|
74
|
+
}, minimizerOptions?: HtmlnanoOptions): Promise<{
|
|
75
|
+
code: string;
|
|
76
|
+
}>;
|
|
77
|
+
|
|
78
|
+
export { htmlnano as default, getRequiredOptionalDependencies, htmlMinimizerWebpackPluginMinify, htmlnano, loadConfig, process };
|
|
79
|
+
export type { HtmlnanoModule, HtmlnanoModuleAttrsHandler, HtmlnanoModuleContentHandler, HtmlnanoModuleNodeHandler, HtmlnanoOptions, HtmlnanoOptionsConfigFile, HtmlnanoPredefinedPreset, HtmlnanoPredefinedPresets, HtmlnanoPreset, PostHTMLNodeLike, PostHTMLTreeLike };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import PostHTML from 'posthtml';
|
|
2
|
+
import { MinifyOptions } from 'terser';
|
|
3
|
+
import { Options } from 'cssnano';
|
|
4
|
+
import { Config } from 'svgo';
|
|
5
|
+
|
|
6
|
+
type PostHTMLTreeLike = [PostHTML.Node] & PostHTML.NodeAPI & {
|
|
7
|
+
options?: {
|
|
8
|
+
quoteAllAttributes?: boolean | undefined;
|
|
9
|
+
} | undefined;
|
|
10
|
+
render(): string;
|
|
11
|
+
render(node: PostHTML.Node | PostHTMLTreeLike, renderOptions?: any): string;
|
|
12
|
+
};
|
|
13
|
+
type MaybeArray<T> = T | Array<T>;
|
|
14
|
+
interface HtmlnanoOptions {
|
|
15
|
+
skipConfigLoading?: boolean;
|
|
16
|
+
skipInternalWarnings?: boolean;
|
|
17
|
+
collapseAttributeWhitespace?: boolean;
|
|
18
|
+
collapseBooleanAttributes?: {
|
|
19
|
+
amphtml?: boolean;
|
|
20
|
+
};
|
|
21
|
+
collapseWhitespace?: 'conservative' | 'all' | 'aggressive';
|
|
22
|
+
custom?: MaybeArray<(tree: PostHTMLTreeLike, options?: any) => (PostHTML.Node | PostHTMLTreeLike)>;
|
|
23
|
+
deduplicateAttributeValues?: boolean;
|
|
24
|
+
minifyUrls?: URL | string | false;
|
|
25
|
+
mergeStyles?: boolean;
|
|
26
|
+
mergeScripts?: boolean;
|
|
27
|
+
minifyCss?: Options | boolean;
|
|
28
|
+
minifyConditionalComments?: boolean;
|
|
29
|
+
minifyJs?: MinifyOptions | boolean;
|
|
30
|
+
minifyJson?: boolean;
|
|
31
|
+
minifySvg?: Config | boolean;
|
|
32
|
+
normalizeAttributeValues?: boolean;
|
|
33
|
+
removeAttributeQuotes?: boolean;
|
|
34
|
+
removeComments?: boolean | 'safe' | 'all' | RegExp | ((comment: string) => boolean);
|
|
35
|
+
removeEmptyAttributes?: boolean;
|
|
36
|
+
removeRedundantAttributes?: boolean;
|
|
37
|
+
removeOptionalTags?: boolean;
|
|
38
|
+
removeUnusedCss?: boolean;
|
|
39
|
+
sortAttributes?: boolean | 'alphabetical' | 'frequency';
|
|
40
|
+
sortAttributesWithLists?: boolean | 'alphabetical' | 'frequency';
|
|
41
|
+
}
|
|
42
|
+
interface HtmlnanoPreset extends Omit<HtmlnanoOptions, 'skipConfigLoading'> {
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
declare const _default: HtmlnanoPreset;
|
|
46
|
+
|
|
47
|
+
export { _default as default };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import PostHTML from 'posthtml';
|
|
2
|
+
import { MinifyOptions } from 'terser';
|
|
3
|
+
import { Options } from 'cssnano';
|
|
4
|
+
import { Config } from 'svgo';
|
|
5
|
+
|
|
6
|
+
type PostHTMLTreeLike = [PostHTML.Node] & PostHTML.NodeAPI & {
|
|
7
|
+
options?: {
|
|
8
|
+
quoteAllAttributes?: boolean | undefined;
|
|
9
|
+
} | undefined;
|
|
10
|
+
render(): string;
|
|
11
|
+
render(node: PostHTML.Node | PostHTMLTreeLike, renderOptions?: any): string;
|
|
12
|
+
};
|
|
13
|
+
type MaybeArray<T> = T | Array<T>;
|
|
14
|
+
interface HtmlnanoOptions {
|
|
15
|
+
skipConfigLoading?: boolean;
|
|
16
|
+
skipInternalWarnings?: boolean;
|
|
17
|
+
collapseAttributeWhitespace?: boolean;
|
|
18
|
+
collapseBooleanAttributes?: {
|
|
19
|
+
amphtml?: boolean;
|
|
20
|
+
};
|
|
21
|
+
collapseWhitespace?: 'conservative' | 'all' | 'aggressive';
|
|
22
|
+
custom?: MaybeArray<(tree: PostHTMLTreeLike, options?: any) => (PostHTML.Node | PostHTMLTreeLike)>;
|
|
23
|
+
deduplicateAttributeValues?: boolean;
|
|
24
|
+
minifyUrls?: URL | string | false;
|
|
25
|
+
mergeStyles?: boolean;
|
|
26
|
+
mergeScripts?: boolean;
|
|
27
|
+
minifyCss?: Options | boolean;
|
|
28
|
+
minifyConditionalComments?: boolean;
|
|
29
|
+
minifyJs?: MinifyOptions | boolean;
|
|
30
|
+
minifyJson?: boolean;
|
|
31
|
+
minifySvg?: Config | boolean;
|
|
32
|
+
normalizeAttributeValues?: boolean;
|
|
33
|
+
removeAttributeQuotes?: boolean;
|
|
34
|
+
removeComments?: boolean | 'safe' | 'all' | RegExp | ((comment: string) => boolean);
|
|
35
|
+
removeEmptyAttributes?: boolean;
|
|
36
|
+
removeRedundantAttributes?: boolean;
|
|
37
|
+
removeOptionalTags?: boolean;
|
|
38
|
+
removeUnusedCss?: boolean;
|
|
39
|
+
sortAttributes?: boolean | 'alphabetical' | 'frequency';
|
|
40
|
+
sortAttributesWithLists?: boolean | 'alphabetical' | 'frequency';
|
|
41
|
+
}
|
|
42
|
+
interface HtmlnanoPreset extends Omit<HtmlnanoOptions, 'skipConfigLoading'> {
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
declare const _default: HtmlnanoPreset;
|
|
46
|
+
|
|
47
|
+
export { _default as default };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import PostHTML from 'posthtml';
|
|
2
|
+
import { MinifyOptions } from 'terser';
|
|
3
|
+
import { Options } from 'cssnano';
|
|
4
|
+
import { Config } from 'svgo';
|
|
5
|
+
|
|
6
|
+
type PostHTMLTreeLike = [PostHTML.Node] & PostHTML.NodeAPI & {
|
|
7
|
+
options?: {
|
|
8
|
+
quoteAllAttributes?: boolean | undefined;
|
|
9
|
+
} | undefined;
|
|
10
|
+
render(): string;
|
|
11
|
+
render(node: PostHTML.Node | PostHTMLTreeLike, renderOptions?: any): string;
|
|
12
|
+
};
|
|
13
|
+
type MaybeArray<T> = T | Array<T>;
|
|
14
|
+
interface HtmlnanoOptions {
|
|
15
|
+
skipConfigLoading?: boolean;
|
|
16
|
+
skipInternalWarnings?: boolean;
|
|
17
|
+
collapseAttributeWhitespace?: boolean;
|
|
18
|
+
collapseBooleanAttributes?: {
|
|
19
|
+
amphtml?: boolean;
|
|
20
|
+
};
|
|
21
|
+
collapseWhitespace?: 'conservative' | 'all' | 'aggressive';
|
|
22
|
+
custom?: MaybeArray<(tree: PostHTMLTreeLike, options?: any) => (PostHTML.Node | PostHTMLTreeLike)>;
|
|
23
|
+
deduplicateAttributeValues?: boolean;
|
|
24
|
+
minifyUrls?: URL | string | false;
|
|
25
|
+
mergeStyles?: boolean;
|
|
26
|
+
mergeScripts?: boolean;
|
|
27
|
+
minifyCss?: Options | boolean;
|
|
28
|
+
minifyConditionalComments?: boolean;
|
|
29
|
+
minifyJs?: MinifyOptions | boolean;
|
|
30
|
+
minifyJson?: boolean;
|
|
31
|
+
minifySvg?: Config | boolean;
|
|
32
|
+
normalizeAttributeValues?: boolean;
|
|
33
|
+
removeAttributeQuotes?: boolean;
|
|
34
|
+
removeComments?: boolean | 'safe' | 'all' | RegExp | ((comment: string) => boolean);
|
|
35
|
+
removeEmptyAttributes?: boolean;
|
|
36
|
+
removeRedundantAttributes?: boolean;
|
|
37
|
+
removeOptionalTags?: boolean;
|
|
38
|
+
removeUnusedCss?: boolean;
|
|
39
|
+
sortAttributes?: boolean | 'alphabetical' | 'frequency';
|
|
40
|
+
sortAttributesWithLists?: boolean | 'alphabetical' | 'frequency';
|
|
41
|
+
}
|
|
42
|
+
interface HtmlnanoPreset extends Omit<HtmlnanoOptions, 'skipConfigLoading'> {
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
declare const _default: HtmlnanoPreset;
|
|
46
|
+
|
|
47
|
+
export { _default as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "htmlnano",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.4",
|
|
4
4
|
"description": "Modular HTML minifier, built on top of the PostHTML",
|
|
5
5
|
"author": "Kirill Maltsev <maltsevkirill@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,22 +21,27 @@
|
|
|
21
21
|
"module": "./dist/index.mjs",
|
|
22
22
|
"exports": {
|
|
23
23
|
"./helpers": {
|
|
24
|
+
"types": "./dist/helpers.d.ts",
|
|
24
25
|
"import": "./dist/helpers.mjs",
|
|
25
26
|
"require": "./dist/helpers.js"
|
|
26
27
|
},
|
|
27
28
|
".": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
28
30
|
"import": "./dist/index.mjs",
|
|
29
31
|
"require": "./dist/index.js"
|
|
30
32
|
},
|
|
31
33
|
"./presets/ampSafe": {
|
|
34
|
+
"types": "./dist/presets/ampSafe.d.ts",
|
|
32
35
|
"import": "./dist/presets/ampSafe.mjs",
|
|
33
36
|
"require": "./dist/presets/ampSafe.js"
|
|
34
37
|
},
|
|
35
38
|
"./presets/max": {
|
|
39
|
+
"types": "./dist/presets/max.d.ts",
|
|
36
40
|
"import": "./dist/presets/max.mjs",
|
|
37
41
|
"require": "./dist/presets/max.js"
|
|
38
42
|
},
|
|
39
43
|
"./presets/safe": {
|
|
44
|
+
"types": "./dist/presets/safe.d.ts",
|
|
40
45
|
"import": "./dist/presets/safe.mjs",
|
|
41
46
|
"require": "./dist/presets/safe.js"
|
|
42
47
|
}
|