UNPKG

1.63 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.htmlMinifierTerser = htmlMinifierTerser;
7
8/* istanbul ignore next */
9async function htmlMinifierTerser(data, minimizerOptions) {
10 // eslint-disable-next-line global-require,import/no-extraneous-dependencies
11 const htmlMinifier = require("html-minifier-terser");
12
13 const defaultMinimizerOptions = {
14 caseSensitive: true,
15 // `collapseBooleanAttributes` is not always safe, since this can break CSS attribute selectors and not safe for XHTML
16 collapseWhitespace: true,
17 conservativeCollapse: true,
18 keepClosingSlash: true,
19 // We need ability to use cssnano, or setup own function without extra dependencies
20 minifyCSS: true,
21 minifyJS: true,
22 // `minifyURLs` is unsafe, because we can't guarantee what the base URL is
23 // `removeAttributeQuotes` is not safe in some rare cases, also HTML spec recommends against doing this
24 removeComments: true,
25 // `removeEmptyAttributes` is not safe, can affect certain style or script behavior, look at https://github.com/webpack-contrib/html-loader/issues/323
26 // `removeRedundantAttributes` is not safe, can affect certain style or script behavior, look at https://github.com/webpack-contrib/html-loader/issues/323
27 removeScriptTypeAttributes: true,
28 removeStyleLinkTypeAttributes: true // `useShortDoctype` is not safe for XHTML
29
30 };
31 const [[, input]] = Object.entries(data);
32 return {
33 code: htmlMinifier.minify(input, { ...defaultMinimizerOptions,
34 ...minimizerOptions
35 })
36 };
37} // eslint-disable-next-line import/prefer-default-export
\No newline at end of file