UNPKG

6.9 kBTypeScriptView Raw
1import * as CleanCSS from "clean-css";
2import * as RelateUrl from "relateurl";
3import * as UglifyJS from "uglify-js";
4
5export function minify(text: string, options?: Options): string;
6
7export interface Options {
8 // Treat attributes in case sensitive manner (useful for custom HTML tags)
9 caseSensitive?: boolean | undefined;
10
11 // Omit attribute values from boolean attributes
12 collapseBooleanAttributes?: boolean | undefined;
13
14 // Don't leave any spaces between display:inline; elements when collapsing. Must be used in conjunction with collapseWhitespace=true
15 collapseInlineTagWhitespace?: boolean | undefined;
16
17 /**
18 * Collapse white space that contributes to text nodes in a document tree
19 * @see http://perfectionkills.com/experimenting-with-html-minifier/#collapse_whitespace
20 */
21 collapseWhitespace?: boolean | undefined;
22
23 // Always collapse to 1 space (never remove it entirely). Must be used in conjunction with collapseWhitespace=true
24 conservativeCollapse?: boolean | undefined;
25 /**
26 * Handle parse errors instead of aborting
27 * @default false
28 */
29 continueOnParseError?: boolean | undefined;
30
31 // Arrays of regex'es that allow to support custom attribute assign expressions (e.g. '<div flex?="{{mode != cover}}"></div>')
32 customAttrAssign?: RegExp[] | undefined;
33
34 // Regex that specifies custom attribute to strip newlines from (e.g. /ng-class/)
35 customAttrCollapse?: RegExp | undefined;
36
37 // Arrays of regex'es that allow to support custom attribute surround expressions (e.g. <input {{#if value}}checked="checked"{{/if}}>)
38 customAttrSurround?: RegExp[] | undefined;
39
40 // Arrays of regex'es that allow to support custom event attributes for minifyJS (e.g. ng-click)
41 customEventAttributes?: RegExp[] | undefined;
42
43 // Use direct Unicode characters whenever possible
44 decodeEntities?: boolean | undefined;
45
46 // Parse input according to HTML5 specifications
47 html5?: boolean | undefined;
48
49 // Array of regex'es that allow to ignore certain comments, when matched
50 ignoreCustomComments?: RegExp[] | undefined;
51
52 // Array of regex'es that allow to ignore certain fragments, when matched (e.g. <?php ... ?>, {{ ... }}, etc.)
53 ignoreCustomFragments?: RegExp[] | undefined;
54
55 // Insert tags generated by HTML parser
56 includeAutoGeneratedTags?: boolean | undefined;
57
58 // Keep the trailing slash on singleton elements
59 keepClosingSlash?: boolean | undefined;
60
61 // Specify a maximum line length. Compressed output will be split by newlines at valid HTML split-points
62 maxLineLength?: number | undefined;
63
64 // Minify CSS in style elements and style attributes (uses clean-css or function specified)
65 minifyCSS?: boolean | CleanCSS.Options | ((text: string) => string) | undefined;
66
67 // Minify JavaScript in script elements and event attributes (uses UglifyJS or function specified)
68 minifyJS?: boolean | UglifyJS.MinifyOptions | ((text: string, inline: boolean) => string) | undefined;
69
70 // Minify URLs in various attributes (uses relateurl or function specified)
71 minifyURLs?: boolean | RelateUrl.Options | ((text: string) => string) | undefined;
72
73 // Always collapse to 1 line break (never remove it entirely) when whitespace between tags include a line break. Must be used in conjunction with collapseWhitespace=true
74 preserveLineBreaks?: boolean | undefined;
75
76 // Prevents the escaping of the values of attributes
77 preventAttributesEscaping?: boolean | undefined;
78
79 // Process contents of conditional comments through minifier
80 processConditionalComments?: boolean | undefined;
81
82 // Array of strings corresponding to types of script elements to process through minifier (e.g. text/ng-template, text/x-handlebars-template, etc.)
83 processScripts?: string[] | undefined;
84
85 // Type of quote to use for attribute values (' or ")
86 quoteCharacter?: string | undefined;
87
88 /**
89 * Remove quotes around attributes when possible
90 * @see http://perfectionkills.com/experimenting-with-html-minifier/#remove_attribute_quotes
91 */
92 removeAttributeQuotes?: boolean | undefined;
93
94 /**
95 * Strip HTML comments
96 * @see http://perfectionkills.com/experimenting-with-html-minifier/#remove_comments
97 */
98 removeComments?: boolean | undefined;
99
100 /**
101 * Remove all attributes with whitespace-only values
102 * @see http://perfectionkills.com/experimenting-with-html-minifier/#remove_empty_or_blank_attributes
103 */
104 removeEmptyAttributes?: boolean | ((attrName: string, tag: string) => boolean) | undefined;
105
106 /**
107 * Remove all elements with empty contents
108 * @see http://perfectionkills.com/experimenting-with-html-minifier/#remove_empty_elements
109 */
110 removeEmptyElements?: boolean | undefined;
111
112 /**
113 * Remove optional tags
114 * @see http://perfectionkills.com/experimenting-with-html-minifier/#remove_optional_tags
115 */
116 removeOptionalTags?: boolean | undefined;
117
118 /**
119 * Remove attributes when value matches default.
120 * @see http://perfectionkills.com/experimenting-with-html-minifier/#remove_redundant_attributes
121 */
122 removeRedundantAttributes?: boolean | undefined;
123
124 // Remove type="text/javascript" from script tags. Other type attribute values are left intact
125 removeScriptTypeAttributes?: boolean | undefined;
126
127 // Remove type="text/css" from style and link tags. Other type attribute values are left intact
128 removeStyleLinkTypeAttributes?: boolean | undefined;
129
130 // Remove space between attributes whenever possible. Note that this will result in invalid HTML!
131 removeTagWhitespace?: boolean | undefined;
132
133 /**
134 * Sort attributes by frequency
135 *
136 * Minifier options like sortAttributes and sortClassName won't impact the plain-text size
137 * of the output. However, they form long repetitive chains of characters that should improve
138 * compression ratio of gzip used in HTTP compression.
139 *
140 * @see https://github.com/kangax/html-minifier#sorting-attributes--style-classes
141 */
142 sortAttributes?: boolean | undefined;
143
144 /**
145 * Sort style classes by frequency
146 *
147 * Minifier options like sortAttributes and sortClassName won't impact the plain-text size
148 * of the output. However, they form long repetitive chains of characters that should improve
149 * compression ratio of gzip used in HTTP compression.
150 *
151 * @see https://github.com/kangax/html-minifier#sorting-attributes--style-classes
152 */
153 sortClassName?: boolean | undefined;
154
155 // Trim white space around ignoreCustomFragments
156 trimCustomFragments?: boolean | undefined;
157
158 /**
159 * Replaces the doctype with the short (HTML5) doctype
160 * @see http://perfectionkills.com/experimenting-with-html-minifier/#use_short_doctype
161 */
162 useShortDoctype?: boolean | undefined;
163}
164
\No newline at end of file