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