gulp-repath
rewrite url(script src,link href, img url...)
Install
$ npm install --save gulp-repath
Usage
Using gulp-repath replace links to assets in html/css templates.
var gulp = ;var repath = ; var repathConf = verMode: 'hash' // origin, hash, param hashName: '{origin}-{hash}' baseMap: 'static': './static' element: 'script' 'style' 'image' excludeFile: replace: '@cdn/': '//localhost:8080/' ; gulp; gulp; gulp; gulp; gulp;
It's output
hash
mode:
in /static/js/api.js
=> /static/js/api-a3b35d82dd89ab76.js
@cdn/static/img/bg.jpg
=> //localhost:8080/static/img/bg-a3b35d82dd89ab76.jpg
param
mode:
in /static/js/api.js
=> /static/js/api.js?ver=a3b35d82dd89ab76
@cdn/static/img/bg.jpg
=> //localhost:8080/static/img/bg.jpg?ver=a3b35d82dd89ab76
Options
verMode
Type : String
One of origin
, hash
, param
, Default value is param
origin
: nothing to do
hash
: rename file name add file's hash use option hashName
"/static/js/api.js" => "/static/js/api-a3b35d82dd89ab76.js"
param
: add ver=hash to url
"/static/js/api.js" => "/static/js/api.js?ver=a3b35d82dd89ab76"
hashName
Type : String
Use only verMode is hash
, {origin} is origin file name, {hash} is file's hash,
Default value is '{origin}-{hash}'
baseMap
Type : Object
url => directories
baseMap: 'static': './static'
url "/static/js/api.js" => local file "./static/js/api.js"
element
Type : Array
Replace element, script
: javascript src, style
: link href, image
: img src or url(xxxx) in css, Default value is ['script', 'style', 'image']
excludeFile
Type : Array
The files no be replace process.
replace
Type : Object
url path to be replace
replace: '@cdn/': '//localhost:8080/'
It will replace "@cdn/static/js/api.js" to "//localhost:8080/satic/js/api.js"