gulp-rev-append
gulp-rev-append copied to clipboard
如果引入的路径为构建的路径,在当前目录下找不到资源的时候该插件无法使用
利用gulp打包生成合并后的文件,该文件问打包后生成文件,所以没有hash值,导致该插件没有效果。 暂时的解决方案是修改源码,不使用hash算法,直接使用时间戳作为版本号。 将代码
try {
data = fs.readFileSync(dependencyPath);
hash = crypto.createHash('md5');
hash.update(data.toString(), 'utf8');
var _rev=new Date().getTime();
line = line.replace(groups[2], _rev);
}
修改为
try {
var _rev=new Date().getTime();
line = line.replace(groups[2], _rev);
}
即可
if(groups && groups.length > 1) { // are we an "absoulte path"? (e.g. /js/app.js) //file.base="src/main/webapp/WEB-INF/template/"; var normPath = path.normalize(groups[1]); normPath = normPath.replace("${ctx}", ""); /if (normPath.indexOf(path.sep) === 0) { dependencyPath = path.join(file.base, normPath); } else { dependencyPath = path.resolve(path.dirname(file.path), normPath); }/ dependencyPath="src/main/webapp/"+normPath; try { data = fs.readFileSync(dependencyPath); hash = crypto.createHash('md5'); hash.update(data.toString(), 'utf8'); line = line.replace(groups[2], hash.digest('hex')); } catch(e) { // fail silently. } }