Minify HTML
压缩页面的 HTML 代码
配置参数
- extensions object
The list of extensions this plugin applies to.
Default:[ ".html" ]- options object
Default options for minify-html library
- do_not_minify_doctype boolean
Do not minify DOCTYPEs. Minified DOCTYPEs may not be spec compliant.
Default:true- ensure_spec_compliant_unquoted_attribute_values boolean
Ensure all unquoted attribute values in the output do not contain any characters prohibited by the WHATWG specification.
Default:true- keep_closing_tags boolean
Do not omit closing tags when possible.
Default:false- keep_html_and_head_opening_tags boolean
Do not omit
Default:<html>and<head>opening tags when they don't have attributes.false- keep_spaces_between_attributes boolean
Keep spaces between attributes when possible to conform to HTML standards.
Default:false- keep_comments boolean
Keep all comments.
Default:false- keep_ssi_comments boolean
Keep SSI comments.
- preserve_brace_template_syntax boolean
When
{{,{#, or{%are seen in content, all source code until the subsequent matching closing}},#}, or%}respectively gets piped through untouched.- preserve_chevron_percent_template_syntax boolean
When
<%is seen in content, all source code until the subsequent matching closing%>gets piped through untouched.- minify_js boolean
If enabled, content in
Default:<script>tags with a JS or no MIME type will be minified using minify-js.true- minify_css boolean
If enabled, CSS in
Default:<style>tags andstyleattributes will be minified.true- remove_bangs boolean
Remove all bangs.
Default:false- remove_processing_instructions boolean
Remove all processing_instructions.
Default:false
Description
MinifyHTML 插件使用 minify-html 压缩器来压缩您页面的 HTML 代码。它还可以压缩 CSS 和 JavaScript 代码。
Installation
在您的 _config.ts 文件中导入此插件即可使用它:
import lume from "lume/mod.ts";
import minifyHTML from "lume/plugins/minify_html.ts";
const site = lume();
site.use(minifyHTML(/* Options */)); // 使用选项
export default site;
Configuration
此插件接受一个配置对象。可用的选项包括:
extensions: 一个包含将被压缩文件的扩展名的数组。 默认情况下是[".html"],但是您也可以包含.css和.js来压缩这些文件。options: 一个包含minify-html可用选项的对象。
例如:
site.use(minifyHTML({
extensions: [".html", ".js"],
options: {
minify_js: true,
keep_spaces_between_attributes: true,
keep_closing_tags: true,
keep_html_and_head_opening_tags: true,
},
}));