htmlnano 2.1.5 → 3.0.0

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.
Files changed (65) hide show
  1. package/README.md +6 -0
  2. package/dist/_modules/collapseAttributeWhitespace.d.mts +1 -0
  3. package/dist/_modules/collapseAttributeWhitespace.d.ts +1 -0
  4. package/dist/_modules/collapseBooleanAttributes.d.mts +1 -0
  5. package/dist/_modules/collapseBooleanAttributes.d.ts +1 -0
  6. package/dist/_modules/collapseWhitespace.d.mts +1 -0
  7. package/dist/_modules/collapseWhitespace.d.ts +1 -0
  8. package/dist/_modules/custom.d.mts +1 -0
  9. package/dist/_modules/custom.d.ts +1 -0
  10. package/dist/_modules/deduplicateAttributeValues.d.mts +1 -0
  11. package/dist/_modules/deduplicateAttributeValues.d.ts +1 -0
  12. package/dist/_modules/example.d.mts +1 -0
  13. package/dist/_modules/example.d.ts +1 -0
  14. package/dist/_modules/mergeScripts.d.mts +1 -0
  15. package/dist/_modules/mergeScripts.d.ts +1 -0
  16. package/dist/_modules/mergeStyles.d.mts +1 -0
  17. package/dist/_modules/mergeStyles.d.ts +1 -0
  18. package/dist/_modules/mergeStyles.js +1 -2
  19. package/dist/_modules/mergeStyles.mjs +1 -2
  20. package/dist/_modules/minifyConditionalComments.d.mts +1 -0
  21. package/dist/_modules/minifyConditionalComments.d.ts +1 -0
  22. package/dist/_modules/minifyCss.d.mts +1 -0
  23. package/dist/_modules/minifyCss.d.ts +1 -0
  24. package/dist/_modules/minifyJs.d.mts +1 -0
  25. package/dist/_modules/minifyJs.d.ts +1 -0
  26. package/dist/_modules/minifyJson.d.mts +1 -0
  27. package/dist/_modules/minifyJson.d.ts +1 -0
  28. package/dist/_modules/minifyJson.js +1 -1
  29. package/dist/_modules/minifyJson.mjs +1 -1
  30. package/dist/_modules/minifySvg.d.mts +1 -0
  31. package/dist/_modules/minifySvg.d.ts +1 -0
  32. package/dist/_modules/minifySvg.js +3 -3
  33. package/dist/_modules/minifySvg.mjs +3 -3
  34. package/dist/_modules/minifyUrls.d.mts +1 -0
  35. package/dist/_modules/minifyUrls.d.ts +1 -0
  36. package/dist/_modules/minifyUrls.js +1 -1
  37. package/dist/_modules/minifyUrls.mjs +1 -1
  38. package/dist/_modules/normalizeAttributeValues.d.mts +1 -0
  39. package/dist/_modules/normalizeAttributeValues.d.ts +1 -0
  40. package/dist/_modules/removeAttributeQuotes.d.mts +1 -0
  41. package/dist/_modules/removeAttributeQuotes.d.ts +1 -0
  42. package/dist/_modules/removeAttributeQuotes.js +1 -2
  43. package/dist/_modules/removeAttributeQuotes.mjs +1 -2
  44. package/dist/_modules/removeComments.d.mts +1 -0
  45. package/dist/_modules/removeComments.d.ts +1 -0
  46. package/dist/_modules/removeEmptyAttributes.d.mts +1 -0
  47. package/dist/_modules/removeEmptyAttributes.d.ts +1 -0
  48. package/dist/_modules/removeOptionalTags.d.mts +1 -0
  49. package/dist/_modules/removeOptionalTags.d.ts +1 -0
  50. package/dist/_modules/removeRedundantAttributes.d.mts +1 -0
  51. package/dist/_modules/removeRedundantAttributes.d.ts +1 -0
  52. package/dist/_modules/removeUnusedCss.d.mts +1 -0
  53. package/dist/_modules/removeUnusedCss.d.ts +1 -0
  54. package/dist/_modules/sortAttributes.d.mts +1 -0
  55. package/dist/_modules/sortAttributes.d.ts +1 -0
  56. package/dist/_modules/sortAttributesWithLists.d.mts +1 -0
  57. package/dist/_modules/sortAttributesWithLists.d.ts +1 -0
  58. package/dist/bin.js +34 -0
  59. package/dist/index.d.ts +6 -4
  60. package/dist/index.js +7 -5
  61. package/dist/index.mjs +7 -6
  62. package/dist/presets/ampSafe.d.ts +2 -1
  63. package/dist/presets/max.d.ts +2 -1
  64. package/dist/presets/safe.d.ts +2 -1
  65. package/package.json +7 -4
package/README.md CHANGED
@@ -61,4 +61,10 @@ htmlnano
61
61
  });
62
62
  ```
63
63
 
64
+ Also, you can use it as CLI tool:
65
+
66
+ ```bash
67
+ node_modules/.bin/htmlnano --help
68
+ ```
69
+
64
70
  More usage examples (PostHTML, Gulp, Webpack): https://htmlnano.netlify.app/next/usage
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
@@ -24,9 +24,8 @@ var helpers_js = require('../helpers.js');
24
24
  const styleMedia = nodeAttrs.media || 'all';
25
25
  const styleKey = styleType + '_' + styleMedia;
26
26
  if (styleKey in styleNodes) {
27
- var _styleNodes_styleKey;
27
+ var _styleNodes_styleKey, _content;
28
28
  const styleContent = helpers_js.extractTextContentFromNode(node);
29
- var _content;
30
29
  (_content = (_styleNodes_styleKey = styleNodes[styleKey]).content) != null ? _content : _styleNodes_styleKey.content = [];
31
30
  styleNodes[styleKey].content.push(' ' + styleContent);
32
31
  return ''; // Remove node
@@ -22,9 +22,8 @@ import { isAmpBoilerplate, extractTextContentFromNode } from '../helpers.mjs';
22
22
  const styleMedia = nodeAttrs.media || 'all';
23
23
  const styleKey = styleType + '_' + styleMedia;
24
24
  if (styleKey in styleNodes) {
25
- var _styleNodes_styleKey;
25
+ var _styleNodes_styleKey, _content;
26
26
  const styleContent = extractTextContentFromNode(node);
27
- var _content;
28
27
  (_content = (_styleNodes_styleKey = styleNodes[styleKey]).content) != null ? _content : _styleNodes_styleKey.content = [];
29
28
  styleNodes[styleKey].content.push(' ' + styleContent);
30
29
  return ''; // Remove node
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
@@ -23,7 +23,7 @@ const mod = {
23
23
  return [
24
24
  JSON.stringify(JSON.parse(jsonContent))
25
25
  ];
26
- } catch (e) {
26
+ } catch (unused) {
27
27
  // Invalid JSON
28
28
  }
29
29
  }
@@ -21,7 +21,7 @@ const mod = {
21
21
  return [
22
22
  JSON.stringify(JSON.parse(jsonContent))
23
23
  ];
24
- } catch (e) {
24
+ } catch (unused) {
25
25
  // Invalid JSON
26
26
  }
27
27
  }
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
@@ -24,9 +24,9 @@ var helpers_js = require('../helpers.js');
24
24
  ];
25
25
  return node;
26
26
  } catch (error) {
27
- console.error('htmlnano fails to minify the svg:');
28
- console.error(error);
29
- if (error && typeof error === 'object' && 'name' in error && error.name === 'SvgoParserError') {
27
+ const isSvgoParserError = Boolean(error && typeof error === 'object' && 'name' in error && error.name === 'SvgoParserError');
28
+ if (!options.skipInternalWarnings && !isSvgoParserError) {
29
+ console.error('htmlnano fails to minify the svg:');
30
30
  console.error(error);
31
31
  }
32
32
  // We return the node as-is
@@ -22,9 +22,9 @@ import { optionalImport } from '../helpers.mjs';
22
22
  ];
23
23
  return node;
24
24
  } catch (error) {
25
- console.error('htmlnano fails to minify the svg:');
26
- console.error(error);
27
- if (error && typeof error === 'object' && 'name' in error && error.name === 'SvgoParserError') {
25
+ const isSvgoParserError = Boolean(error && typeof error === 'object' && 'name' in error && error.name === 'SvgoParserError');
26
+ if (!options.skipInternalWarnings && !isSvgoParserError) {
27
+ console.error('htmlnano fails to minify the svg:');
28
28
  console.error(error);
29
29
  }
30
30
  // We return the node as-is
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
@@ -144,7 +144,7 @@ let STORED_URL_BASE;
144
144
  }
145
145
  return item;
146
146
  }));
147
- } catch (e) {
147
+ } catch (unused) {
148
148
  // srcset will throw an Error for invalid srcset.
149
149
  }
150
150
  }
@@ -142,7 +142,7 @@ let STORED_URL_BASE;
142
142
  }
143
143
  return item;
144
144
  }));
145
- } catch (e) {
145
+ } catch (unused) {
146
146
  // srcset will throw an Error for invalid srcset.
147
147
  }
148
148
  }
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
@@ -5,8 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  // See also: https://github.com/posthtml/htmlnano/issues/6#issuecomment-707105334
6
6
  /** Disable quoteAllAttributes while not overriding the configuration */ const mod = {
7
7
  default: function removeAttributeQuotes(tree) {
8
- var _tree_options;
9
- var _quoteAllAttributes;
8
+ var _tree_options, _quoteAllAttributes;
10
9
  if (tree.options) (_quoteAllAttributes = (_tree_options = tree.options).quoteAllAttributes) != null ? _quoteAllAttributes : _tree_options.quoteAllAttributes = false;
11
10
  return tree;
12
11
  }
@@ -3,8 +3,7 @@
3
3
  // See also: https://github.com/posthtml/htmlnano/issues/6#issuecomment-707105334
4
4
  /** Disable quoteAllAttributes while not overriding the configuration */ const mod = {
5
5
  default: function removeAttributeQuotes(tree) {
6
- var _tree_options;
7
- var _quoteAllAttributes;
6
+ var _tree_options, _quoteAllAttributes;
8
7
  if (tree.options) (_quoteAllAttributes = (_tree_options = tree.options).quoteAllAttributes) != null ? _quoteAllAttributes : _tree_options.quoteAllAttributes = false;
9
8
  return tree;
10
9
  }
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
package/dist/bin.js ADDED
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env node
2
+ var commander = require('commander');
3
+ var fs = require('fs');
4
+ var process = require('process');
5
+ var index_js = require('./index.js');
6
+
7
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
8
+
9
+ var fs__default = /*#__PURE__*/_interopDefault(fs);
10
+ var process__default = /*#__PURE__*/_interopDefault(process);
11
+
12
+ commander.program.name('htmlnano').description('Minify HTML with htmlnano').argument('[input]', 'input file', '-').option('-o, --output <file>', 'output file', '-').option('-p, --preset <preset>', 'preset to use', 'safe').option('-c, --config <file>', 'path to config file').action(async (input, options)=>{
13
+ const { preset, output } = options;
14
+ if (!preset || !(preset in index_js.presets)) {
15
+ const available = Object.keys(index_js.presets).join(', ');
16
+ process__default.default.stderr.write(`Unknown preset: ${preset}. Available presets: ${available}\n`);
17
+ process__default.default.exitCode = 1;
18
+ return;
19
+ }
20
+ const html = fs__default.default.readFileSync(input && input !== '-' ? input : 0, 'utf8');
21
+ const key = preset;
22
+ const chosenPreset = index_js.presets[key];
23
+ const htmlnanoOptions = {};
24
+ if (options.config) {
25
+ htmlnanoOptions.configPath = options.config;
26
+ }
27
+ const result = await index_js.process(html, htmlnanoOptions, chosenPreset);
28
+ if (output && output !== '-') {
29
+ fs__default.default.writeFileSync(output, result.html);
30
+ } else {
31
+ process__default.default.stdout.write(result.html);
32
+ }
33
+ });
34
+ commander.program.parse();
package/dist/index.d.ts CHANGED
@@ -14,6 +14,7 @@ type MaybeArray<T> = T | Array<T>;
14
14
  type PostHTMLNodeLike = PostHTML.Node | string;
15
15
  interface HtmlnanoOptions {
16
16
  skipConfigLoading?: boolean;
17
+ configPath?: string;
17
18
  skipInternalWarnings?: boolean;
18
19
  collapseAttributeWhitespace?: boolean;
19
20
  collapseBooleanAttributes?: {
@@ -40,11 +41,11 @@ interface HtmlnanoOptions {
40
41
  sortAttributes?: boolean | 'alphabetical' | 'frequency';
41
42
  sortAttributesWithLists?: boolean | 'alphabetical' | 'frequency';
42
43
  }
43
- interface HtmlnanoPreset extends Omit<HtmlnanoOptions, 'skipConfigLoading'> {
44
+ interface HtmlnanoPreset extends Omit<HtmlnanoOptions, 'skipConfigLoading' | 'configPath'> {
44
45
  }
45
46
  type HtmlnanoPredefinedPreset = 'safe' | 'ampSafe' | 'max';
46
47
  type HtmlnanoPredefinedPresets = Record<HtmlnanoPredefinedPreset, HtmlnanoPreset>;
47
- type HtmlnanoOptionsConfigFile = Omit<HtmlnanoOptions, 'skipConfigLoading'> & {
48
+ type HtmlnanoOptionsConfigFile = Omit<HtmlnanoOptions, 'skipConfigLoading' | 'configPath'> & {
48
49
  preset?: HtmlnanoPredefinedPreset;
49
50
  };
50
51
  type HtmlnanoModuleAttrsHandler = (attrs: Record<string, string | boolean | void>, node: PostHTML.Node) => Record<string, string | boolean | void>;
@@ -58,7 +59,8 @@ type HtmlnanoModule<Options = any> = {
58
59
  default?: (tree: PostHTMLTreeLike, options: Partial<HtmlnanoOptions>, moduleOptions: OptionalOptions<Options>) => PostHTMLTreeLike | Promise<PostHTMLTreeLike>;
59
60
  };
60
61
 
61
- declare function loadConfig(options?: HtmlnanoOptions, preset?: HtmlnanoPreset, configPath?: string): [Partial<HtmlnanoOptions>, HtmlnanoPreset];
62
+ declare const presets: HtmlnanoPredefinedPresets;
63
+ declare function loadConfig(options?: HtmlnanoOptions, preset?: HtmlnanoPreset): [Partial<HtmlnanoOptions>, HtmlnanoPreset];
62
64
  declare const htmlnano: ((optionsRun?: HtmlnanoOptions, presetRun?: HtmlnanoPreset) => PostHTML.Plugin<never>) & {
63
65
  presets: HtmlnanoPredefinedPresets;
64
66
  getRequiredOptionalDependencies: typeof getRequiredOptionalDependencies;
@@ -74,5 +76,5 @@ declare function htmlMinimizerWebpackPluginMinify(input: {
74
76
  code: string;
75
77
  }>;
76
78
 
77
- export { htmlnano as default, getRequiredOptionalDependencies, htmlMinimizerWebpackPluginMinify, loadConfig, process };
79
+ export { htmlnano as default, getRequiredOptionalDependencies, htmlMinimizerWebpackPluginMinify, loadConfig, presets, process };
78
80
  export type { HtmlnanoModule, HtmlnanoModuleAttrsHandler, HtmlnanoModuleContentHandler, HtmlnanoModuleNodeHandler, HtmlnanoOptions, HtmlnanoOptionsConfigFile, HtmlnanoPredefinedPreset, HtmlnanoPredefinedPresets, HtmlnanoPreset, PostHTMLNodeLike, PostHTMLTreeLike };
package/dist/index.js CHANGED
@@ -18,8 +18,8 @@ const presets = {
18
18
  ampSafe: ampSafePreset__default.default,
19
19
  max: maxPreset__default.default
20
20
  };
21
- function loadConfig(options, preset, configPath) {
22
- const { skipConfigLoading = false, ...rest } = options || {};
21
+ function loadConfig(options, preset) {
22
+ const { skipConfigLoading = false, configPath, ...rest } = options || {};
23
23
  let restConfig = rest;
24
24
  if (!skipConfigLoading) {
25
25
  const explorer = cosmiconfig.cosmiconfigSync('htmlnano');
@@ -32,9 +32,10 @@ function loadConfig(options, preset, configPath) {
32
32
  }
33
33
  delete rc.config.preset;
34
34
  }
35
- if (!options) {
36
- restConfig = rc.config;
37
- }
35
+ restConfig = {
36
+ ...rc.config,
37
+ ...restConfig
38
+ };
38
39
  }
39
40
  }
40
41
  return [
@@ -273,4 +274,5 @@ exports.default = htmlnano;
273
274
  exports.getRequiredOptionalDependencies = getRequiredOptionalDependencies;
274
275
  exports.htmlMinimizerWebpackPluginMinify = htmlMinimizerWebpackPluginMinify;
275
276
  exports.loadConfig = loadConfig;
277
+ exports.presets = presets;
276
278
  exports.process = process;
package/dist/index.mjs CHANGED
@@ -9,8 +9,8 @@ const presets = {
9
9
  ampSafe: ampSafePreset,
10
10
  max: maxPreset
11
11
  };
12
- function loadConfig(options, preset, configPath) {
13
- const { skipConfigLoading = false, ...rest } = options || {};
12
+ function loadConfig(options, preset) {
13
+ const { skipConfigLoading = false, configPath, ...rest } = options || {};
14
14
  let restConfig = rest;
15
15
  if (!skipConfigLoading) {
16
16
  const explorer = cosmiconfigSync('htmlnano');
@@ -23,9 +23,10 @@ function loadConfig(options, preset, configPath) {
23
23
  }
24
24
  delete rc.config.preset;
25
25
  }
26
- if (!options) {
27
- restConfig = rc.config;
28
- }
26
+ restConfig = {
27
+ ...rc.config,
28
+ ...restConfig
29
+ };
29
30
  }
30
31
  }
31
32
  return [
@@ -260,4 +261,4 @@ if (typeof module !== 'undefined') {
260
261
  module.exports = htmlnano;
261
262
  }
262
263
 
263
- export { htmlnano as default, getRequiredOptionalDependencies, htmlMinimizerWebpackPluginMinify, loadConfig, process };
264
+ export { htmlnano as default, getRequiredOptionalDependencies, htmlMinimizerWebpackPluginMinify, loadConfig, presets, process };
@@ -13,6 +13,7 @@ type PostHTMLTreeLike = [PostHTML.Node] & PostHTML.NodeAPI & {
13
13
  type MaybeArray<T> = T | Array<T>;
14
14
  interface HtmlnanoOptions {
15
15
  skipConfigLoading?: boolean;
16
+ configPath?: string;
16
17
  skipInternalWarnings?: boolean;
17
18
  collapseAttributeWhitespace?: boolean;
18
19
  collapseBooleanAttributes?: {
@@ -39,7 +40,7 @@ interface HtmlnanoOptions {
39
40
  sortAttributes?: boolean | 'alphabetical' | 'frequency';
40
41
  sortAttributesWithLists?: boolean | 'alphabetical' | 'frequency';
41
42
  }
42
- interface HtmlnanoPreset extends Omit<HtmlnanoOptions, 'skipConfigLoading'> {
43
+ interface HtmlnanoPreset extends Omit<HtmlnanoOptions, 'skipConfigLoading' | 'configPath'> {
43
44
  }
44
45
 
45
46
  declare const _default: HtmlnanoPreset;
@@ -13,6 +13,7 @@ type PostHTMLTreeLike = [PostHTML.Node] & PostHTML.NodeAPI & {
13
13
  type MaybeArray<T> = T | Array<T>;
14
14
  interface HtmlnanoOptions {
15
15
  skipConfigLoading?: boolean;
16
+ configPath?: string;
16
17
  skipInternalWarnings?: boolean;
17
18
  collapseAttributeWhitespace?: boolean;
18
19
  collapseBooleanAttributes?: {
@@ -39,7 +40,7 @@ interface HtmlnanoOptions {
39
40
  sortAttributes?: boolean | 'alphabetical' | 'frequency';
40
41
  sortAttributesWithLists?: boolean | 'alphabetical' | 'frequency';
41
42
  }
42
- interface HtmlnanoPreset extends Omit<HtmlnanoOptions, 'skipConfigLoading'> {
43
+ interface HtmlnanoPreset extends Omit<HtmlnanoOptions, 'skipConfigLoading' | 'configPath'> {
43
44
  }
44
45
 
45
46
  declare const _default: HtmlnanoPreset;
@@ -13,6 +13,7 @@ type PostHTMLTreeLike = [PostHTML.Node] & PostHTML.NodeAPI & {
13
13
  type MaybeArray<T> = T | Array<T>;
14
14
  interface HtmlnanoOptions {
15
15
  skipConfigLoading?: boolean;
16
+ configPath?: string;
16
17
  skipInternalWarnings?: boolean;
17
18
  collapseAttributeWhitespace?: boolean;
18
19
  collapseBooleanAttributes?: {
@@ -39,7 +40,7 @@ interface HtmlnanoOptions {
39
40
  sortAttributes?: boolean | 'alphabetical' | 'frequency';
40
41
  sortAttributesWithLists?: boolean | 'alphabetical' | 'frequency';
41
42
  }
42
- interface HtmlnanoPreset extends Omit<HtmlnanoOptions, 'skipConfigLoading'> {
43
+ interface HtmlnanoPreset extends Omit<HtmlnanoOptions, 'skipConfigLoading' | 'configPath'> {
43
44
  }
44
45
 
45
46
  declare const _default: HtmlnanoPreset;
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "htmlnano",
3
- "version": "2.1.5",
3
+ "version": "3.0.0",
4
4
  "description": "Modular HTML minifier, built on top of the PostHTML",
5
5
  "author": "Kirill Maltsev <maltsevkirill@gmail.com>",
6
6
  "license": "MIT",
7
7
  "scripts": {
8
8
  "clean": "rimraf dist",
9
9
  "build": "npm run clean && bunchee",
10
+ "postbuild": "chmod +x dist/bin.js",
10
11
  "compile": "npm run build",
11
12
  "lint": "eslint --fix .",
12
13
  "pretest": "npm run lint && npm run compile",
@@ -19,6 +20,7 @@
19
20
  ],
20
21
  "main": "./dist/index.js",
21
22
  "module": "./dist/index.mjs",
23
+ "bin": "./dist/bin.js",
22
24
  "exports": {
23
25
  "./helpers": {
24
26
  "types": "./dist/helpers.d.ts",
@@ -55,6 +57,7 @@
55
57
  ],
56
58
  "dependencies": {
57
59
  "@types/relateurl": "^0.2.33",
60
+ "commander": "^14.0.0",
58
61
  "cosmiconfig": "^9.0.0",
59
62
  "posthtml": "^0.16.5"
60
63
  },
@@ -63,7 +66,7 @@
63
66
  "@stylistic/eslint-plugin": "^5.3.1",
64
67
  "@swc-node/register": "^1.10.10",
65
68
  "@types/mocha": "^10.0.10",
66
- "@types/node": "^24.0.0",
69
+ "@types/node": "^25.0.0",
67
70
  "bunchee": "^6.5.1",
68
71
  "cssnano": "^7.0.0",
69
72
  "eslint": "^9.25.1",
@@ -78,8 +81,8 @@
78
81
  "purgecss": "^7.0.2",
79
82
  "relateurl": "^0.2.7",
80
83
  "rimraf": "^6.0.0",
81
- "srcset": "5.0.1",
82
- "svgo": "^3.0.2",
84
+ "srcset": "^5.0.1",
85
+ "svgo": "^4.0.0",
83
86
  "terser": "^5.21.0",
84
87
  "typescript": "^5.8.3",
85
88
  "typescript-eslint": "^8.44.0",