gulp配置版本號碼 教程之gulp-rev-append

來源:互聯網
上載者:User

標籤:

簡介:

使用gulp-rev-append給頁面的引用添加版本號碼,清除頁面引用緩衝。

1、安裝nodejs/全域安裝gulp/項目安裝gulp/建立package.json和gulpfile.js檔案

1.1、gulp基本使用還未掌握?請參看: gulp詳細入門教程

1.2、本樣本目錄結構如下:

2、本地安裝gulp-rev-append

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

2.2、安裝:命令提示字元執行 cnpm install gulp-rev-append --save-dev

2.3、注意:沒有安裝cnpm請使用 npm install gulp-rev-append --save-dev 什麼是cnpm,如何安裝?

2.4、說明:--save-dev 儲存配置資訊至 package.json 的 devDependencies 節點。為什麼要儲存至package.json?

2.5、效果如下:

3、配置html頁面引用

3.1、gulp-rev-append 外掛程式將通過正則(?:href|src)=”(.*)[?]rev=(.*)[“]尋找並給指定連結填加版本號碼(預設根據檔案MD5產生,因此檔案未發生改變,此版本號碼將不會變)

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="" />    <script src="js/[email protected]@hash"></script>  </body></html>
4、配置gulpfile.js

4.1、基本使用(給頁面引用url添加版本號碼,以清除頁面緩衝)

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、執行任務

5.1、命令提示字元執行:gulp testRev

6、結束語

6.1、本文有任何錯誤,或有任何疑問,歡迎留言說明。

 

本文轉載自:http://www.ydcss.com/archives/49

gulp配置版本號碼 教程之gulp-rev-append

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.