CSS merging, compression and MD5 naming and path substitution for the Gulp Learning Guide

Source: Internet
Author: User

1. Introduction of Plugins

varGulp = require ('Gulp'),  //uglify = require (' gulp-uglify '),Concat = require ('Gulp-concat'), Minifycss= Require ('Gulp-minify-css'), Rev= Require ('Gulp-rev'), Revcollector= Require ('Gulp-rev-collector');

Console input

NPM Install gulp gulp-concat gulp-minify-css gulp-rev gulp-rev-collector--save-dev

2. Write code in Gulpfile.js

Gulp.task ('concat', function () {GULP.SRC ('Xingboweb/scenemall/public/static/css/reset.css')//file to compress. Pipe (MINIFYCSS ('Reset.css') //compress CSS. Pipe (rev ())//filename plus MD5 suffix. Pipe (gulp.dest ('Dist/css') //. Pipe (Rev.manifest ())//rev-mainfest.json file, which is a compressed file information. Pipe (Gulp.dest ('Dist/rev'));}); Gulp.task ('Rev', function () {GULP.SRC (['Dist/rev/*.json','xingboweb/scenemall/app/views/home/detail.phtml']//Read the compressed file information, and the file to replace the directory. Pipe (Revcollector ({//) perform replacement replacereved:true, dirreplacements:{'CSS':'Dist/css'}). Pipe (Gulp.dest ('xingboweb/scenemall/app/views/home/'))    //. Pipe (Gulp.dest (' dist/html '))})

Note: minifycss compressed filename must be replaced in the directory of the file name consistent, otherwise the substitution is unsuccessful, such as the file name Reset.css, but the compressed file name is RESET.MIN.CSS, so that cannot replace the successful

3. After running the Gulp in the console, you can replace it successfully.

CSS merging, compression and MD5 naming and path substitution for the Gulp Learning Guide

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.