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