Gulp Configuration Version Number tutorial Gulp-rev-append

Source: Internet
Author: User

Brief introduction:

Use Gulp-rev-append to add a version number to the page reference and clear the page reference cache.

1. Install nodejs/Global Installation gulp/Project installation gulp/create Package.json and Gulpfile.js files

1.1, Gulp Basic use has not yet mastered? See: Gulp for a more introductory tutorial

1.2. This example directory is structured as follows:

2, Local installation Gulp-rev-append

2.1, Github:https://github.com/bustardcelly/gulp-rev-append

2.2. Installation: Command Prompt executioncnpm install gulp-rev-append --save-dev

2.3, note: Do not install cnpm please npm install gulp-rev-append --save-dev use what is CNPM, how to install?

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

2.5, the effect is as follows:

3. Configuring HTML page References

3.1. Gulp-rev-append plugin will pass regular (?: href|src) = "(. *) [?] rev= (. *) ["] Find and add a version number to the specified link (by default, the file MD5 generated, so the file does not change, this version number will not change)

JavaScript
12345678910111213 <! DOCTYPE HTML> <html> <head> <link rel="stylesheet" href="Css/[email protected] @hash"> <script src="Js/[email protected" @hash "></script> <script src="Js/js-two.js"></script> </head> <body> <div>Hello, world ! </div> <img src="Img/test.jpg?r[email protected] @hash" alt="" c24>/> <script src="Js/[email protected" @hash "></script> </body> </HTML>
4, Configuration Gulpfile.js

4.1. Basic use (Add a version number to the page reference URL to clear the page cache)

JavaScript
12345678 var gulp = require(' Gulp '), rev = require(' gulp-rev-append '); Gulp. Task(' Testrev ', function () { Gulp. SRC(' src/html/index.html ')         . Pipe(rev())         . Pipe(gulp. Dest(' dist/html ')); });
5. Perform Tasks

5.1. Command prompt execution:Gulp Testrev

6. Concluding remarks

6.1, this article has any mistake, or has any question, welcome the message explanation.

This article was reproduced from: HTTP://WWW.YDCSS.COM/ARCHIVES/49

Gulp Configuration Version Number tutorial Gulp-rev-append

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.