htmlnano 0.2.4 → 0.2.8
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/CHANGELOG.md +79 -10
- package/README.md +318 -18
- package/lib/helpers.js +16 -36
- package/lib/htmlnano.js +33 -73
- package/lib/modules/collapseAttributeWhitespace.js +21 -19
- package/lib/modules/collapseBooleanAttributes.js +34 -48
- package/lib/modules/collapseWhitespace.js +66 -32
- package/lib/modules/custom.js +12 -12
- package/lib/modules/deduplicateAttributeValues.js +34 -36
- package/lib/modules/mergeScripts.js +46 -63
- package/lib/modules/mergeStyles.js +33 -32
- package/lib/modules/minifyConditionalComments.js +52 -0
- package/lib/modules/minifyCss.js +33 -41
- package/lib/modules/minifyJs.js +72 -68
- package/lib/modules/minifyJson.js +23 -17
- package/lib/modules/minifySvg.js +19 -28
- package/lib/modules/minifyUrls.js +117 -0
- package/lib/modules/removeAttributeQuotes.js +19 -0
- package/lib/modules/removeComments.js +52 -34
- package/lib/modules/removeEmptyAttributes.js +19 -21
- package/lib/modules/removeOptionalTags.js +220 -0
- package/lib/modules/removeRedundantAttributes.js +82 -67
- package/lib/modules/removeUnusedCss.js +104 -52
- package/lib/modules/sortAttributes.js +120 -0
- package/lib/modules/sortAttributesWithLists.js +143 -0
- package/lib/presets/ampSafe.js +16 -17
- package/lib/presets/max.js +23 -21
- package/lib/presets/safe.js +38 -25
- package/package.json +29 -19
- package/test.js +29 -6
- package/lib/presets/hard.js +0 -26
package/test.js
CHANGED
|
@@ -1,14 +1,37 @@
|
|
|
1
|
-
const htmlnano = require('
|
|
2
|
-
const
|
|
3
|
-
|
|
1
|
+
const htmlnano = require('.');
|
|
2
|
+
const options = {
|
|
3
|
+
// minifySvg: false,
|
|
4
|
+
// minifyJs: false,
|
|
5
|
+
};
|
|
6
|
+
// // posthtml, posthtml-render, and posthtml-parse options
|
|
7
|
+
// const postHtmlOptions = {
|
|
8
|
+
// sync: true, // https://github.com/posthtml/posthtml#usage
|
|
9
|
+
// lowerCaseTags: true, // https://github.com/posthtml/posthtml-parser#options
|
|
10
|
+
// quoteAllAttributes: false, // https://github.com/posthtml/posthtml-render#options
|
|
11
|
+
// };
|
|
4
12
|
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
13
|
+
const html = `
|
|
14
|
+
<!doctype html>
|
|
15
|
+
<html lang="en">
|
|
16
|
+
<head>
|
|
17
|
+
<meta charset="utf-8">
|
|
18
|
+
<title></title>
|
|
19
|
+
<script class="fob">alert(1)</script>
|
|
20
|
+
<script>alert(2)</script>
|
|
21
|
+
</head>
|
|
22
|
+
<body>
|
|
23
|
+
<script>alert(3)</script>
|
|
24
|
+
<script>alert(4)</script>
|
|
25
|
+
</body>
|
|
26
|
+
</html>
|
|
27
|
+
`;
|
|
8
28
|
|
|
9
29
|
htmlnano
|
|
30
|
+
// "preset" arg might be skipped (see "Presets" section below for more info)
|
|
31
|
+
// "postHtmlOptions" arg might be skipped
|
|
10
32
|
.process(html, options)
|
|
11
33
|
.then(function (result) {
|
|
34
|
+
// result.html is minified
|
|
12
35
|
console.log(result.html);
|
|
13
36
|
})
|
|
14
37
|
.catch(function (err) {
|
package/lib/presets/hard.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
var _objectAssign = require('object-assign');
|
|
8
|
-
|
|
9
|
-
var _objectAssign2 = _interopRequireDefault(_objectAssign);
|
|
10
|
-
|
|
11
|
-
var _safe = require('./safe');
|
|
12
|
-
|
|
13
|
-
var _safe2 = _interopRequireDefault(_safe);
|
|
14
|
-
|
|
15
|
-
function _interopRequireDefault(obj) {
|
|
16
|
-
return obj && obj.__esModule ? obj : { default: obj };
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
*
|
|
21
|
-
*/
|
|
22
|
-
exports.default = (0, _objectAssign2.default)({}, _safe2.default, {
|
|
23
|
-
collapseWhitespace: 'all',
|
|
24
|
-
removeComments: 'all',
|
|
25
|
-
removeRedundantAttributes: true
|
|
26
|
-
});
|