UNPKG

html-minifier-next

Version:

Super-configurable and well-tested web page minifier (enhanced successor of HTML Minifier)

207 lines (204 loc) 6.95 kB
// Single source of truth for minifier option names, descriptions, types, and shared defaults const optionDefinitions = { caseSensitive: { description: 'Treat attributes in case-sensitive manner (useful for custom HTML elements)', type: 'boolean' }, collapseAttributeWhitespace: { description: 'Trim and collapse whitespace characters within attribute values', type: 'boolean' }, collapseBooleanAttributes: { description: 'Omit attribute values from boolean attributes', type: 'boolean' }, collapseInlineTagWhitespace: { description: 'Collapse whitespace more aggressively between inline elements—use with `--collapse-whitespace`', type: 'boolean' }, collapseWhitespace: { description: 'Collapse whitespace that contributes to text nodes in a document tree', type: 'boolean' }, conservativeCollapse: { description: 'Always collapse to one space (never remove it entirely)—use with `--collapse-whitespace`', type: 'boolean' }, continueOnMinifyError: { description: 'Abort on minification errors', type: 'invertedBoolean' }, continueOnParseError: { description: 'Handle parse errors instead of aborting', type: 'boolean' }, customAttrAssign: { description: 'Array of regexes that allow to support custom attribute assign expressions (e.g., `<div flex?="{{mode != cover}}"></div>`)', type: 'regexpArray' }, customAttrCollapse: { description: 'Regex that specifies custom attribute to strip newlines from (e.g., `/ng-class/`)', type: 'regexp' }, customAttrSurround: { description: 'Array of regexes that allow to support custom attribute surround expressions (e.g., `<input {{#if value}}checked="checked"{{/if}}>`)', type: 'regexpArray' }, customEventAttributes: { description: 'Array of regexes that allow to support custom event attributes for minifyJS (e.g., `ng-click`)', type: 'regexpArray' }, customFragmentQuantifierLimit: { description: 'Set maximum quantifier limit for custom fragments to prevent ReDoS attacks (default: 200)', type: 'int' }, decodeEntities: { description: 'Use direct Unicode characters whenever possible', type: 'boolean' }, ignoreCustomComments: { description: 'Array of regexes that allow to ignore matching comments', type: 'regexpArray' }, ignoreCustomFragments: { description: 'Array of regexes that allow to ignore certain fragments, when matched (e.g., `<?php \u2026 ?>`, `{{ \u2026 }}`)', type: 'regexpArray' }, includeAutoGeneratedTags: { description: 'Insert elements generated by HTML parser', type: 'boolean' }, inlineCustomElements: { description: 'Array of names of custom elements which are inline, for whitespace handling', type: 'jsonArray' }, keepClosingSlash: { description: 'Keep the trailing slash on void elements', type: 'boolean' }, maxInputLength: { description: 'Maximum input length to prevent ReDoS attacks', type: 'int' }, maxLineLength: { description: 'Specify a maximum line length; compressed output will be split by newlines at valid HTML split-points', type: 'int' }, mergeScripts: { description: 'Merge consecutive inline `script` elements into one', type: 'boolean' }, minifyCSS: { description: 'Minify CSS in `style` elements and attributes (uses Lightning CSS)', type: 'json' }, minifyJS: { description: 'Minify JavaScript in `script` elements and event attributes (uses Terser or SWC; pass `{"engine": "swc"}` for SWC)', type: 'json' }, minifySVG: { description: 'Minify SVG elements (uses SVGO)', type: 'json' }, minifyURLs: { description: 'Minify URLs in various attributes', type: 'json' }, noNewlinesBeforeTagClose: { description: 'Never add a newline before a tag that closes an element', type: 'boolean' }, partialMarkup: { description: 'Treat input as a partial HTML fragment, preserving stray end tags and unclosed tags', type: 'boolean' }, preserveLineBreaks: { description: 'Always collapse to one line break (never remove it entirely) when whitespace between tags includes a line break—use with `--collapse-whitespace`', type: 'boolean' }, preventAttributesEscaping: { description: 'Prevents the escaping of the values of attributes', type: 'boolean' }, processConditionalComments: { description: 'Process contents of conditional comments through minifier', type: 'boolean' }, processScripts: { description: 'Array of strings corresponding to types of `script` elements to process through minifier (e.g., `text/ng-template`, `text/x-handlebars-template`, etc.)', type: 'jsonArray' }, quoteCharacter: { description: 'Type of quote to use for attribute values (`\'` or `"`)', type: 'string' }, removeAttributeQuotes: { description: 'Remove quotes around attributes when possible', type: 'boolean' }, removeComments: { description: 'Strip HTML comments', type: 'boolean' }, removeEmptyAttributes: { description: 'Remove all attributes with whitespace-only values', type: 'boolean' }, removeEmptyElements: { description: 'Remove all elements with empty contents', type: 'boolean' }, removeEmptyElementsExcept: { description: 'Array of elements to preserve when `--remove-empty-elements` is enabled (e.g., `td`, `<span aria-hidden="true">`)', type: 'jsonArray' }, removeOptionalTags: { description: 'Remove optional tags', type: 'boolean' }, removeRedundantAttributes: { description: 'Remove attributes when value matches default', type: 'boolean' }, removeScriptTypeAttributes: { description: 'Remove `type="text/javascript"` from `script` elements; other `type` attribute values are left intact', type: 'boolean' }, removeStyleLinkTypeAttributes: { description: 'Remove `type="text/css"` from `style` and `link` elements; other `type` attribute values are left intact', type: 'boolean' }, removeTagWhitespace: { description: 'Remove space between attributes whenever possible; note that this will result in invalid HTML', type: 'boolean' }, sortAttributes: { description: 'Sort attributes by frequency', type: 'boolean' }, sortClassNames: { description: 'Sort style classes by frequency', type: 'boolean' }, trimCustomFragments: { description: 'Trim whitespace around custom fragments (`--ignore-custom-fragments`)', type: 'boolean' }, useShortDoctype: { description: 'Replaces the doctype with the short HTML doctype', type: 'boolean' } }; const optionDefaults = { continueOnMinifyError: true, ignoreCustomComments: [ /^!/, /^\s*#/ ], ignoreCustomFragments: [ /<%[\s\S]*?%>/, /<\?[\s\S]*?\?>/ ], includeAutoGeneratedTags: false }; export { optionDefinitions, optionDefaults };