htmlnano 2.1.2 → 2.1.3
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 +53 -12
- package/dist/_modules/collapseAttributeWhitespace.d.mts +57 -0
- package/dist/_modules/collapseAttributeWhitespace.d.ts +57 -0
- package/dist/_modules/collapseAttributeWhitespace.js +296 -0
- package/dist/_modules/collapseAttributeWhitespace.mjs +293 -0
- package/dist/_modules/collapseBooleanAttributes.d.mts +60 -0
- package/dist/_modules/collapseBooleanAttributes.d.ts +60 -0
- package/dist/_modules/collapseBooleanAttributes.js +159 -0
- package/{lib/modules → dist/_modules}/collapseBooleanAttributes.mjs +39 -57
- package/dist/_modules/collapseWhitespace.d.mts +57 -0
- package/dist/_modules/collapseWhitespace.d.ts +57 -0
- package/dist/_modules/collapseWhitespace.js +172 -0
- package/dist/_modules/collapseWhitespace.mjs +170 -0
- package/dist/_modules/custom.d.mts +57 -0
- package/dist/_modules/custom.d.ts +57 -0
- package/dist/_modules/custom.js +22 -0
- package/dist/_modules/custom.mjs +20 -0
- package/dist/_modules/deduplicateAttributeValues.d.mts +56 -0
- package/dist/_modules/deduplicateAttributeValues.d.ts +56 -0
- package/dist/_modules/deduplicateAttributeValues.js +38 -0
- package/dist/_modules/deduplicateAttributeValues.mjs +36 -0
- package/dist/_modules/example.d.mts +59 -0
- package/dist/_modules/example.d.ts +59 -0
- package/dist/_modules/example.js +67 -0
- package/dist/_modules/example.mjs +65 -0
- package/dist/_modules/mergeScripts.d.mts +56 -0
- package/dist/_modules/mergeScripts.d.ts +56 -0
- package/dist/_modules/mergeScripts.js +53 -0
- package/dist/_modules/mergeScripts.mjs +51 -0
- package/dist/_modules/mergeStyles.d.mts +56 -0
- package/dist/_modules/mergeStyles.d.ts +56 -0
- package/dist/_modules/mergeStyles.js +42 -0
- package/dist/_modules/mergeStyles.mjs +40 -0
- package/dist/_modules/minifyConditionalComments.d.mts +56 -0
- package/dist/_modules/minifyConditionalComments.d.ts +56 -0
- package/dist/_modules/minifyConditionalComments.js +54 -0
- package/{lib/modules → dist/_modules}/minifyConditionalComments.mjs +21 -22
- package/dist/_modules/minifyCss.d.mts +56 -0
- package/dist/_modules/minifyCss.d.ts +56 -0
- package/dist/_modules/minifyCss.js +84 -0
- package/dist/_modules/minifyCss.mjs +82 -0
- package/dist/_modules/minifyJs.d.mts +56 -0
- package/dist/_modules/minifyJs.d.ts +56 -0
- package/dist/_modules/minifyJs.js +108 -0
- package/dist/_modules/minifyJs.mjs +106 -0
- package/dist/_modules/minifyJson.d.mts +56 -0
- package/dist/_modules/minifyJson.d.ts +56 -0
- package/dist/_modules/minifyJson.js +35 -0
- package/dist/_modules/minifyJson.mjs +33 -0
- package/dist/_modules/minifySvg.d.mts +56 -0
- package/dist/_modules/minifySvg.d.ts +56 -0
- package/dist/_modules/minifySvg.js +40 -0
- package/dist/_modules/minifySvg.mjs +38 -0
- package/dist/_modules/minifyUrls.d.mts +56 -0
- package/dist/_modules/minifyUrls.d.ts +56 -0
- package/dist/_modules/minifyUrls.js +180 -0
- package/dist/_modules/minifyUrls.mjs +178 -0
- package/dist/_modules/normalizeAttributeValues.d.mts +56 -0
- package/dist/_modules/normalizeAttributeValues.d.ts +56 -0
- package/dist/_modules/normalizeAttributeValues.js +234 -0
- package/dist/_modules/normalizeAttributeValues.mjs +232 -0
- package/dist/_modules/removeAttributeQuotes.d.mts +56 -0
- package/dist/_modules/removeAttributeQuotes.d.ts +56 -0
- package/dist/_modules/removeAttributeQuotes.js +15 -0
- package/dist/_modules/removeAttributeQuotes.mjs +13 -0
- package/dist/_modules/removeComments.d.mts +58 -0
- package/dist/_modules/removeComments.d.ts +58 -0
- package/dist/_modules/removeComments.js +83 -0
- package/{lib/modules → dist/_modules}/removeComments.mjs +24 -35
- package/dist/_modules/removeEmptyAttributes.d.mts +56 -0
- package/dist/_modules/removeEmptyAttributes.d.ts +56 -0
- package/dist/_modules/removeEmptyAttributes.js +197 -0
- package/dist/_modules/removeEmptyAttributes.mjs +195 -0
- package/dist/_modules/removeOptionalTags.d.mts +56 -0
- package/dist/_modules/removeOptionalTags.d.ts +56 -0
- package/dist/_modules/removeOptionalTags.js +190 -0
- package/{lib/modules → dist/_modules}/removeOptionalTags.mjs +54 -91
- package/dist/_modules/removeRedundantAttributes.d.mts +57 -0
- package/dist/_modules/removeRedundantAttributes.d.ts +57 -0
- package/dist/_modules/removeRedundantAttributes.js +128 -0
- package/{lib/modules → dist/_modules}/removeRedundantAttributes.mjs +43 -59
- package/dist/_modules/removeUnusedCss.d.mts +60 -0
- package/dist/_modules/removeUnusedCss.d.ts +60 -0
- package/dist/_modules/removeUnusedCss.js +134 -0
- package/dist/_modules/removeUnusedCss.mjs +132 -0
- package/dist/_modules/sortAttributes.d.mts +57 -0
- package/dist/_modules/sortAttributes.d.ts +57 -0
- package/dist/_modules/sortAttributes.js +102 -0
- package/{lib/modules → dist/_modules}/sortAttributes.mjs +39 -58
- package/dist/_modules/sortAttributesWithLists.d.mts +56 -0
- package/dist/_modules/sortAttributesWithLists.d.ts +56 -0
- package/dist/_modules/sortAttributesWithLists.js +118 -0
- package/{lib/modules → dist/_modules}/sortAttributesWithLists.mjs +41 -59
- package/dist/helpers.js +72 -0
- package/dist/helpers.mjs +63 -0
- package/dist/index.js +223 -0
- package/dist/index.mjs +209 -0
- package/dist/presets/ampSafe.js +19 -0
- package/{lib → dist}/presets/ampSafe.mjs +6 -4
- package/dist/presets/max.js +28 -0
- package/{lib → dist}/presets/max.mjs +6 -4
- package/dist/presets/safe.js +60 -0
- package/{lib → dist}/presets/safe.mjs +13 -20
- package/package.json +48 -56
- package/.eslintignore +0 -3
- package/CHANGELOG.md +0 -409
- package/docs/README.md +0 -33
- package/docs/babel.config.js +0 -3
- package/docs/docs/010-introduction.md +0 -22
- package/docs/docs/020-usage.md +0 -117
- package/docs/docs/030-config.md +0 -21
- package/docs/docs/040-presets.md +0 -75
- package/docs/docs/050-modules.md +0 -855
- package/docs/docs/060-contribute.md +0 -16
- package/docs/docusaurus.config.js +0 -65
- package/docs/netlify.toml +0 -4
- package/docs/package-lock.json +0 -21630
- package/docs/package.json +0 -40
- package/docs/sidebars.js +0 -26
- package/docs/versioned_docs/version-1.1.1/010-introduction.md +0 -22
- package/docs/versioned_docs/version-1.1.1/020-usage.md +0 -77
- package/docs/versioned_docs/version-1.1.1/030-config.md +0 -21
- package/docs/versioned_docs/version-1.1.1/040-presets.md +0 -75
- package/docs/versioned_docs/version-1.1.1/050-modules.md +0 -785
- package/docs/versioned_docs/version-1.1.1/060-contribute.md +0 -16
- package/docs/versioned_docs/version-2.0.0/010-introduction.md +0 -22
- package/docs/versioned_docs/version-2.0.0/020-usage.md +0 -77
- package/docs/versioned_docs/version-2.0.0/030-config.md +0 -21
- package/docs/versioned_docs/version-2.0.0/040-presets.md +0 -75
- package/docs/versioned_docs/version-2.0.0/050-modules.md +0 -838
- package/docs/versioned_docs/version-2.0.0/060-contribute.md +0 -16
- package/docs/versioned_sidebars/version-1.1.1-sidebars.json +0 -8
- package/docs/versioned_sidebars/version-2.0.0-sidebars.json +0 -8
- package/docs/versions.json +0 -4
- package/index.cjs +0 -11
- package/index.d.cts +0 -3
- package/index.d.mts +0 -3
- package/index.d.ts +0 -94
- package/index.mjs +0 -2
- package/lib/helpers.cjs +0 -79
- package/lib/helpers.mjs +0 -53
- package/lib/htmlnano.cjs +0 -202
- package/lib/htmlnano.mjs +0 -198
- package/lib/modules/collapseAttributeWhitespace.cjs +0 -86
- package/lib/modules/collapseAttributeWhitespace.mjs +0 -104
- package/lib/modules/collapseBooleanAttributes.cjs +0 -62
- package/lib/modules/collapseWhitespace.cjs +0 -100
- package/lib/modules/collapseWhitespace.mjs +0 -132
- package/lib/modules/custom.cjs +0 -19
- package/lib/modules/custom.mjs +0 -16
- package/lib/modules/deduplicateAttributeValues.cjs +0 -38
- package/lib/modules/deduplicateAttributeValues.mjs +0 -40
- package/lib/modules/example.cjs +0 -85
- package/lib/modules/example.mjs +0 -75
- package/lib/modules/mergeScripts.cjs +0 -54
- package/lib/modules/mergeScripts.mjs +0 -56
- package/lib/modules/mergeStyles.cjs +0 -38
- package/lib/modules/mergeStyles.mjs +0 -36
- package/lib/modules/minifyConditionalComments.cjs +0 -47
- package/lib/modules/minifyCss.cjs +0 -73
- package/lib/modules/minifyCss.mjs +0 -88
- package/lib/modules/minifyJs.cjs +0 -103
- package/lib/modules/minifyJs.mjs +0 -121
- package/lib/modules/minifyJson.cjs +0 -24
- package/lib/modules/minifyJson.mjs +0 -21
- package/lib/modules/minifySvg.cjs +0 -37
- package/lib/modules/minifySvg.mjs +0 -30
- package/lib/modules/minifyUrls.cjs +0 -141
- package/lib/modules/minifyUrls.mjs +0 -229
- package/lib/modules/normalizeAttributeValues.cjs +0 -120
- package/lib/modules/normalizeAttributeValues.mjs +0 -140
- package/lib/modules/removeAttributeQuotes.cjs +0 -17
- package/lib/modules/removeAttributeQuotes.mjs +0 -12
- package/lib/modules/removeComments.cjs +0 -86
- package/lib/modules/removeEmptyAttributes.cjs +0 -72
- package/lib/modules/removeEmptyAttributes.mjs +0 -121
- package/lib/modules/removeOptionalTags.cjs +0 -183
- package/lib/modules/removeRedundantAttributes.cjs +0 -112
- package/lib/modules/removeUnusedCss.cjs +0 -113
- package/lib/modules/removeUnusedCss.mjs +0 -122
- package/lib/modules/sortAttributes.cjs +0 -98
- package/lib/modules/sortAttributesWithLists.cjs +0 -114
- package/lib/presets/ampSafe.cjs +0 -18
- package/lib/presets/max.cjs +0 -27
- package/lib/presets/safe.cjs +0 -65
- package/test.js +0 -23
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = sortAttributes;
|
|
7
|
-
const validOptions = new Set(['frequency', 'alphabetical']);
|
|
8
|
-
const processModuleOptions = options => {
|
|
9
|
-
if (options === true) return 'alphabetical';
|
|
10
|
-
return validOptions.has(options) ? options : false;
|
|
11
|
-
};
|
|
12
|
-
class AttributeTokenChain {
|
|
13
|
-
constructor() {
|
|
14
|
-
this.freqData = new Map(); // <attr, frequency>[]
|
|
15
|
-
}
|
|
16
|
-
addFromNodeAttrs(nodeAttrs) {
|
|
17
|
-
Object.keys(nodeAttrs).forEach(attrName => {
|
|
18
|
-
const attrNameLower = attrName.toLowerCase();
|
|
19
|
-
if (this.freqData.has(attrNameLower)) {
|
|
20
|
-
this.freqData.set(attrNameLower, this.freqData.get(attrNameLower) + 1);
|
|
21
|
-
} else {
|
|
22
|
-
this.freqData.set(attrNameLower, 1);
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
createSortOrder() {
|
|
27
|
-
let _sortOrder = [...this.freqData.entries()];
|
|
28
|
-
_sortOrder.sort((a, b) => b[1] - a[1]);
|
|
29
|
-
this.sortOrder = _sortOrder.map(i => i[0]);
|
|
30
|
-
}
|
|
31
|
-
sortFromNodeAttrs(nodeAttrs) {
|
|
32
|
-
const newAttrs = {};
|
|
33
|
-
|
|
34
|
-
// Convert node.attrs attrName into lower case.
|
|
35
|
-
const loweredNodeAttrs = {};
|
|
36
|
-
Object.entries(nodeAttrs).forEach(([attrName, attrValue]) => {
|
|
37
|
-
loweredNodeAttrs[attrName.toLowerCase()] = attrValue;
|
|
38
|
-
});
|
|
39
|
-
if (!this.sortOrder) {
|
|
40
|
-
this.createSortOrder();
|
|
41
|
-
}
|
|
42
|
-
this.sortOrder.forEach(attrNameLower => {
|
|
43
|
-
// The attrName inside "sortOrder" has been lowered
|
|
44
|
-
if (loweredNodeAttrs[attrNameLower] != null) {
|
|
45
|
-
newAttrs[attrNameLower] = loweredNodeAttrs[attrNameLower];
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
return newAttrs;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/** Sort attibutes */
|
|
53
|
-
function sortAttributes(tree, options, moduleOptions) {
|
|
54
|
-
const sortType = processModuleOptions(moduleOptions);
|
|
55
|
-
if (sortType === 'alphabetical') {
|
|
56
|
-
return sortAttributesInAlphabeticalOrder(tree);
|
|
57
|
-
}
|
|
58
|
-
if (sortType === 'frequency') {
|
|
59
|
-
return sortAttributesByFrequency(tree);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// Invalid configuration
|
|
63
|
-
return tree;
|
|
64
|
-
}
|
|
65
|
-
function sortAttributesInAlphabeticalOrder(tree) {
|
|
66
|
-
tree.walk(node => {
|
|
67
|
-
if (!node.attrs) {
|
|
68
|
-
return node;
|
|
69
|
-
}
|
|
70
|
-
const newAttrs = {};
|
|
71
|
-
Object.keys(node.attrs).sort((a, b) => typeof a.localeCompare === 'function' ? a.localeCompare(b) : a - b).forEach(attr => newAttrs[attr] = node.attrs[attr]);
|
|
72
|
-
node.attrs = newAttrs;
|
|
73
|
-
return node;
|
|
74
|
-
});
|
|
75
|
-
return tree;
|
|
76
|
-
}
|
|
77
|
-
function sortAttributesByFrequency(tree) {
|
|
78
|
-
const tokenchain = new AttributeTokenChain();
|
|
79
|
-
|
|
80
|
-
// Traverse through tree to get frequency
|
|
81
|
-
tree.walk(node => {
|
|
82
|
-
if (!node.attrs) {
|
|
83
|
-
return node;
|
|
84
|
-
}
|
|
85
|
-
tokenchain.addFromNodeAttrs(node.attrs);
|
|
86
|
-
return node;
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
// Traverse through tree again, this time sort the attributes
|
|
90
|
-
tree.walk(node => {
|
|
91
|
-
if (!node.attrs) {
|
|
92
|
-
return node;
|
|
93
|
-
}
|
|
94
|
-
node.attrs = tokenchain.sortFromNodeAttrs(node.attrs);
|
|
95
|
-
return node;
|
|
96
|
-
});
|
|
97
|
-
return tree;
|
|
98
|
-
}
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = collapseAttributeWhitespace;
|
|
7
|
-
var _collapseAttributeWhitespace = require("./collapseAttributeWhitespace.cjs");
|
|
8
|
-
// class, rel, ping
|
|
9
|
-
|
|
10
|
-
const validOptions = new Set(['frequency', 'alphabetical']);
|
|
11
|
-
const processModuleOptions = options => {
|
|
12
|
-
if (options === true) return 'alphabetical';
|
|
13
|
-
return validOptions.has(options) ? options : false;
|
|
14
|
-
};
|
|
15
|
-
class AttributeTokenChain {
|
|
16
|
-
constructor() {
|
|
17
|
-
this.freqData = new Map(); // <attrValue, frequency>[]
|
|
18
|
-
}
|
|
19
|
-
addFromNodeAttrsArray(attrValuesArray) {
|
|
20
|
-
attrValuesArray.forEach(attrValue => {
|
|
21
|
-
if (this.freqData.has(attrValue)) {
|
|
22
|
-
this.freqData.set(attrValue, this.freqData.get(attrValue) + 1);
|
|
23
|
-
} else {
|
|
24
|
-
this.freqData.set(attrValue, 1);
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
createSortOrder() {
|
|
29
|
-
let _sortOrder = [...this.freqData.entries()];
|
|
30
|
-
_sortOrder.sort((a, b) => b[1] - a[1]);
|
|
31
|
-
this.sortOrder = _sortOrder.map(i => i[0]);
|
|
32
|
-
}
|
|
33
|
-
sortFromNodeAttrsArray(attrValuesArray) {
|
|
34
|
-
const resultArray = [];
|
|
35
|
-
if (!this.sortOrder) {
|
|
36
|
-
this.createSortOrder();
|
|
37
|
-
}
|
|
38
|
-
this.sortOrder.forEach(k => {
|
|
39
|
-
if (attrValuesArray.includes(k)) {
|
|
40
|
-
resultArray.push(k);
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
return resultArray;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/** Sort values inside list-like attributes (e.g. class, rel) */
|
|
48
|
-
function collapseAttributeWhitespace(tree, options, moduleOptions) {
|
|
49
|
-
const sortType = processModuleOptions(moduleOptions);
|
|
50
|
-
if (sortType === 'alphabetical') {
|
|
51
|
-
return sortAttributesWithListsInAlphabeticalOrder(tree);
|
|
52
|
-
}
|
|
53
|
-
if (sortType === 'frequency') {
|
|
54
|
-
return sortAttributesWithListsByFrequency(tree);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Invalid configuration
|
|
58
|
-
return tree;
|
|
59
|
-
}
|
|
60
|
-
function sortAttributesWithListsInAlphabeticalOrder(tree) {
|
|
61
|
-
tree.walk(node => {
|
|
62
|
-
if (!node.attrs) {
|
|
63
|
-
return node;
|
|
64
|
-
}
|
|
65
|
-
Object.keys(node.attrs).forEach(attrName => {
|
|
66
|
-
const attrNameLower = attrName.toLowerCase();
|
|
67
|
-
if (!_collapseAttributeWhitespace.attributesWithLists.has(attrNameLower)) {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
const attrValues = node.attrs[attrName].split(/\s/);
|
|
71
|
-
node.attrs[attrName] = attrValues.sort((a, b) => {
|
|
72
|
-
return typeof a.localeCompare === 'function' ? a.localeCompare(b) : a - b;
|
|
73
|
-
}).join(' ');
|
|
74
|
-
});
|
|
75
|
-
return node;
|
|
76
|
-
});
|
|
77
|
-
return tree;
|
|
78
|
-
}
|
|
79
|
-
function sortAttributesWithListsByFrequency(tree) {
|
|
80
|
-
const tokenChainObj = {}; // <attrNameLower: AttributeTokenChain>[]
|
|
81
|
-
|
|
82
|
-
// Traverse through tree to get frequency
|
|
83
|
-
tree.walk(node => {
|
|
84
|
-
if (!node.attrs) {
|
|
85
|
-
return node;
|
|
86
|
-
}
|
|
87
|
-
Object.entries(node.attrs).forEach(([attrName, attrValues]) => {
|
|
88
|
-
const attrNameLower = attrName.toLowerCase();
|
|
89
|
-
if (!_collapseAttributeWhitespace.attributesWithLists.has(attrNameLower)) {
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
tokenChainObj[attrNameLower] = tokenChainObj[attrNameLower] || new AttributeTokenChain();
|
|
93
|
-
tokenChainObj[attrNameLower].addFromNodeAttrsArray(attrValues.split(/\s/));
|
|
94
|
-
});
|
|
95
|
-
return node;
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
// Traverse through tree again, this time sort the attribute values
|
|
99
|
-
tree.walk(node => {
|
|
100
|
-
if (!node.attrs) {
|
|
101
|
-
return node;
|
|
102
|
-
}
|
|
103
|
-
Object.entries(node.attrs).forEach(([attrName, attrValues]) => {
|
|
104
|
-
const attrNameLower = attrName.toLowerCase();
|
|
105
|
-
if (!_collapseAttributeWhitespace.attributesWithLists.has(attrNameLower)) {
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
if (tokenChainObj[attrNameLower]) {
|
|
109
|
-
node.attrs[attrName] = tokenChainObj[attrNameLower].sortFromNodeAttrsArray(attrValues.split(/\s/)).join(' ');
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
return node;
|
|
113
|
-
});
|
|
114
|
-
}
|
package/lib/presets/ampSafe.cjs
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _safe = _interopRequireDefault(require("./safe.cjs"));
|
|
8
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
-
/**
|
|
10
|
-
* A safe preset for AMP pages (https://www.ampproject.org)
|
|
11
|
-
*/
|
|
12
|
-
var _default = exports.default = {
|
|
13
|
-
..._safe.default,
|
|
14
|
-
collapseBooleanAttributes: {
|
|
15
|
-
amphtml: true
|
|
16
|
-
},
|
|
17
|
-
minifyJs: false
|
|
18
|
-
};
|
package/lib/presets/max.cjs
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _safe = _interopRequireDefault(require("./safe.cjs"));
|
|
8
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
-
/**
|
|
10
|
-
* Maximal minification (might break some pages)
|
|
11
|
-
*/
|
|
12
|
-
var _default = exports.default = {
|
|
13
|
-
..._safe.default,
|
|
14
|
-
collapseWhitespace: 'all',
|
|
15
|
-
removeComments: 'all',
|
|
16
|
-
removeAttributeQuotes: true,
|
|
17
|
-
removeRedundantAttributes: true,
|
|
18
|
-
mergeScripts: true,
|
|
19
|
-
mergeStyles: true,
|
|
20
|
-
removeUnusedCss: {},
|
|
21
|
-
minifyCss: {
|
|
22
|
-
preset: 'default'
|
|
23
|
-
},
|
|
24
|
-
minifySvg: {},
|
|
25
|
-
minifyConditionalComments: true,
|
|
26
|
-
removeOptionalTags: true
|
|
27
|
-
};
|
package/lib/presets/safe.cjs
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
/**
|
|
8
|
-
* Minify HTML in a safe way without breaking anything.
|
|
9
|
-
*/
|
|
10
|
-
var _default = exports.default = {
|
|
11
|
-
/* ----------------------------------------
|
|
12
|
-
* Attributes
|
|
13
|
-
* ---------------------------------------- */
|
|
14
|
-
// normalize the case of attribute names and values
|
|
15
|
-
// normalizeAttributeValues will also normalize property value with invalid value default
|
|
16
|
-
// See https://html.spec.whatwg.org/#invalid-value-default
|
|
17
|
-
normalizeAttributeValues: true,
|
|
18
|
-
removeEmptyAttributes: true,
|
|
19
|
-
collapseAttributeWhitespace: true,
|
|
20
|
-
// removeRedundantAttributes will remove attributes when missing value default matches the attribute's value
|
|
21
|
-
// See https://html.spec.whatwg.org/#missing-value-default
|
|
22
|
-
removeRedundantAttributes: false,
|
|
23
|
-
// collapseBooleanAttributes will also collapse those default state can be omitted
|
|
24
|
-
collapseBooleanAttributes: {
|
|
25
|
-
amphtml: false
|
|
26
|
-
},
|
|
27
|
-
deduplicateAttributeValues: true,
|
|
28
|
-
minifyUrls: false,
|
|
29
|
-
sortAttributes: false,
|
|
30
|
-
sortAttributesWithLists: 'alphabetical',
|
|
31
|
-
/* ----------------------------------------
|
|
32
|
-
* Minify HTML content
|
|
33
|
-
* ---------------------------------------- */
|
|
34
|
-
collapseWhitespace: 'conservative',
|
|
35
|
-
removeComments: 'safe',
|
|
36
|
-
minifyConditionalComments: false,
|
|
37
|
-
removeOptionalTags: false,
|
|
38
|
-
removeAttributeQuotes: false,
|
|
39
|
-
/* ----------------------------------------
|
|
40
|
-
* Minify inline <style>, <script> and <svg> tag
|
|
41
|
-
* ---------------------------------------- */
|
|
42
|
-
mergeStyles: false,
|
|
43
|
-
mergeScripts: false,
|
|
44
|
-
minifyCss: {
|
|
45
|
-
preset: 'default'
|
|
46
|
-
},
|
|
47
|
-
minifyJs: {},
|
|
48
|
-
minifyJson: {},
|
|
49
|
-
minifySvg: {
|
|
50
|
-
plugins: [{
|
|
51
|
-
name: 'preset-default',
|
|
52
|
-
params: {
|
|
53
|
-
overrides: {
|
|
54
|
-
collapseGroups: false,
|
|
55
|
-
convertShapeToPath: false
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}]
|
|
59
|
-
},
|
|
60
|
-
removeUnusedCss: false,
|
|
61
|
-
/* ----------------------------------------
|
|
62
|
-
* Miscellaneous
|
|
63
|
-
* ---------------------------------------- */
|
|
64
|
-
custom: []
|
|
65
|
-
};
|
package/test.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
|
|
3
|
-
const htmlnano = require('.');
|
|
4
|
-
// const posthtml = require('posthtml');
|
|
5
|
-
const preset = require('./lib/presets/max.cjs');
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const html = fs.readFileSync('./test.html', 'utf8');
|
|
9
|
-
|
|
10
|
-
const startTime = Date.now();
|
|
11
|
-
|
|
12
|
-
htmlnano
|
|
13
|
-
// "preset" arg might be skipped (see "Presets" section below for more info)
|
|
14
|
-
// "postHtmlOptions" arg might be skipped
|
|
15
|
-
.process(html)
|
|
16
|
-
.then(function (result) {
|
|
17
|
-
// result.html is minified
|
|
18
|
-
// console.log(result.html);
|
|
19
|
-
console.log(`Time taken: ${Date.now() - startTime}ms`);
|
|
20
|
-
})
|
|
21
|
-
.catch(function (err) {
|
|
22
|
-
console.error(err);
|
|
23
|
-
});
|