版本:
CLI version 2.0.1
Local version 4.0.0
環境依賴:
npm install gulp -g
npm install gulp --save-dev
npm install gulp-asset-rev --save-dev
npm install gulp-rev --save-dev
npm install gulp-rev-collector --save-dev
npm install gulp-imagemin --save-dev
npm install gulp-clean --save-dev
依賴文件修改:
1.打開node_modules\gulp-rev\index.js
原文:manifest[originalFile] = revisionedFile;
更新爲: manifest[originalFile] = originalFile + '?v=' + file.revHash;
2.打開node_modules\rev-path\index.js
原文:return modifyFilename(pth, (filename, ext) => `${filename}-${hash}${ext}`);
更新爲: return modifyFilename(pth, (filename, ext) => `${filename}${ext}`);
3.打開node_modules\gulp-rev-collector\index.js
原文:
if (!_.isString(json[key])) {
isRev = 0;
return;
}
var cleanReplacement = path.basename(json[key]).replace(new RegExp( opts.revSuffix ), '' );
if (!~[
path.basename(key),
_mapExtnames(path.basename(key), opts)
].indexOf(cleanReplacement)
) {
isRev = 0;
}
更新爲:
if ( !_.isString(json[key]) || path.basename(json[key]).split('?')[0] !== path.basename(key) ) {
isRev = 0;
}
原文:regexp: new RegExp( '([\/\\\\\'"])' + pattern, 'g' ),
更新爲:regexp: new RegExp( '([\/\\\\\'"])' + pattern+'(\\?v=\\w{10})?', 'g' )
4.打開node_modules\gulp-assets-rev\index.js
原文:var verStr = (options.verConnecter || "-") + md5;
更新爲:var verStr = (options.verConnecter || "") + md5;
原文:src = src.replace(verStr, '').replace(/(\.[^\.]+)$/, verStr + "$1");
更新爲:src=src+"?v="+verStr;
5.運行命令 gulp