The gulp-htmlmin__html of Gulp tutorial

Source: Internet
Author: User
Tags html comment

Original link: http://www.ydcss.com/archives/20

Introduction:

Use Gulp-htmlmin compressed HTML, you can compress the page JavaScript, CSS, remove the page spaces, annotations, delete redundant attributes and so on. 1, install nodejs/Global installation gulp/Local installation gulp/create Package.json and gulpfile.js files

1.1, Gulp Basic use has not yet mastered. See: Gulp Detailed Introductory tutorials

1.2. The sample directory structure is as follows:

2. Local Installation Gulp-htmlmin

2.1, Github:https://github.com/jonschlinkert/gulp-htmlmin

2.2. Installation: Command prompt to perform cnpm install Gulp-htmlmin--save-dev

2.3, note: Do not install CNPM Please use NPM install Gulp-htmlmin--save-dev. What is CNPM and how to install it.

2.4, Description:--save-dev save configuration information to Package.json devdependencies node. Why to save to Package.json.

3. Configure Gulpfile.js

3.1. Basic use

varGulp =require(' Gulp '), Htmlmin =require(' Gulp-htmlmin '); Gulp.task (' Testhtmlmin ',function() {varOptions = {removecomments:true,//Clear HTML commentCollapsewhitespace:true,//Compressed HTMLcollapsebooleanattributes:true,//Omitting the value of the Boolean property <input checked= "true"/> ==> <input/>removeemptyattributes:true,//delete all spaces as attribute values <input id= ""/> ==> <input/>removescripttypeattributes:true,//delete <script> type= "Text/javascript"removestylelinktypeattributes:true,//delete <style> and <link> type= "Text/css"Minifyjs:true,//Compressed page JSMinifycss:trueCompress page CSS}; GULP.SRC (' src/html/*.html '). Pipe (Htmlmin (options)). Pipe (Gulp.dest (' dist/html ')); });

3.2, more compression "parameters" please view Https://github.com/kangax/html-minifier [html-minifer docs] 4, perform Tasks

4.1. Command prompt execution: Gulp testhtmlmin

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.