Gulp-htmlmin of Gulp plug-in

Source: Internet
Author: User

Gulp-htmlmin's introduction:

Gulp-htmlmin plugin is used to compress the HTML file, can compress the page javascript,css, remove the page space, comment, delete the extra attributes and so on.

First, the use of Gulp-htmlmin plug-in

1, install "gulp-htmlmin" plug-in command (in the terminal into the project root directory execution)

NPM Install--save-dev gulp-load-plugins gulp-htmlmin

2, in the project root directory to provide "Gulp-htmlmin" plug-in task configuration required src directory and source files (source files placed in the SRC directory)

mkdir SRC

3. Configure the use of "Gulp-htmlmin" in the Gulpfile.js file

Specific examples:
var gulp = require (' Gulp '),
Plugins = require (' Gulp-load-plugins ') (); Loading plugins

Gulp.task (' Htmlmin ', function () {//Custom "Htmlmin" task
Return gulp.src (' src/html/*.html ')//Blur match all HTML files in src/html directory
. Pipe (Plugins.htmlmin ({
Removecomments:true,//clear HTML annotations
Collapsewhitespace:true,//omit blank
Collapsebooleanattributes:true,//Omit Boolean attribute in all tags
Removeemptyattributes:true,//Clears the property of NULL in all tags
Removescripttypeattributes:true,//clear the type attribute in the <script> tag
Removestylelinktypeattributes:true,//clear the type attribute in the <style> and <link> tags
Minifyjs:true,//compress the JS code inside the HTML page
Minifycss:true//Compress CSS code in HTML pages

}))
. Pipe (Gulp.dest (' dist/html ')); File storage path after compression
});

4, finally run "Gulp htmlmin" command in terminal

PS: If there is no error message, prove that there is no problem. Now go to the project root to see if the "dist/html" directory and the target file are generated. Not to be continued ...




This article from "Luo Chen's Blog" blog, reproduced please contact the author!

Gulp-htmlmin of Gulp plug-in

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.