Closed chaochao11 closed 5 years ago
what fail? What did you expect? Explain, please.
I want to automatically introduce the path when it is correct. For example: I sent first Photo
my gulpFile.js
keys in dirReplacements
aren't file extensions. try use something like:
dirReplacements: {
'./script': '/dist/script',
'./css': '/dist/css',
'./assets': '/dist/assets'
}
The problem remains
What problem? You haven't explain it...
You 'rev' task is depended by 'script' and 'style'?
Like gulp.task('rev', [ 'script', 'style'], function () {
...
According to what you said, the hash of the file introduced by index.html under dist was not added after packaging
what contain rev/css/rev-manifest.json
and rev/script/rev-manifest.json
?
yes, contain rev-manifest.json
{
"index.css": "index-653fc57696.css"
}
rev-manifest.json
{
"code.js": "code-1e9c139c3b.js",
"index.js": "index-845e00e6af.js"
}
I dont known what can i do for you. I wrote next test:
'use strict';
var assert = require('assert');
var Vinyl = require('vinyl');
var revCollector = require('./index');
var path = require('path');
var isEqual = require('lodash.isequal');
var man1 = '{"index.css": "index-653fc57696.css"}';
var man2 = '{"code.js": "code-1e9c139c3b.js","index.js": "index-845e00e6af.js"}';
var htmlt = '<html><head><link rel="stylesheet" href="./css/index.css" /><script src=./script/code.js></script><script src=./script/index.js></script></head><body><img src="cdn/image.gif" /></body></html>';
it('should', function (cb) {
var stream = revCollector({
replaceReved: true,
dirReplacements:{
'./script': '/dist/script',
'./css': '/dist/css',
'./assets': '/dist/assets'
}
});
stream.write(new Vinyl({
path: 'rev/css/rev-manifest.json',
contents: new Buffer(man1)
}));
stream.write(new Vinyl({
path: 'rev/script/rev-manifest.json',
contents: new Buffer(man2)
}));
stream.write(new Vinyl({
path: 'index.html',
contents: new Buffer(htmlt)
}));
stream.on('data', function (file) {
var ext = path.extname(file.path);
var contents = file.contents.toString('utf8');
console.log(contents);
});
stream.on('end', function() {
cb();
});
stream.end();
});
all works correctly.
replaced html is next:
<html><head><link rel="stylesheet" href="/dist/css/index-653fc57696.css" /><script src=/dist/script/code-1e9c139c3b.js></script><script src=/dist/script/index-845e00e6af.js></script></head><body><img src="cdn/image.gif" /></body></html>
I can't detect your mistake using gulp-rev-collector
.
replace fail