shonny-ua / gulp-rev-collector

Static asset revision data collector from manifests, with was generated from different streams and replace they's links in html template.
MIT License
149 stars 41 forks source link

path replace auto bug #54

Closed chaochao11 closed 5 years ago

chaochao11 commented 5 years ago

replace fail

chaochao11 commented 5 years ago
wechatimg36112 wechatimg36111
shonny-ua commented 5 years ago

what fail? What did you expect? Explain, please.

chaochao11 commented 5 years ago

I want to automatically introduce the path when it is correct. For example: I sent first Photo

chaochao11 commented 5 years ago

my gulpFile.js image

shonny-ua commented 5 years ago

keys in dirReplacements aren't file extensions. try use something like:

dirReplacements: {
    './script': '/dist/script',
    './css': '/dist/css',
    './assets': '/dist/assets'
}
chaochao11 commented 5 years ago

The problem remains

shonny-ua commented 5 years ago

What problem? You haven't explain it... You 'rev' task is depended by 'script' and 'style'? Like gulp.task('rev', [ 'script', 'style'], function () {...

chaochao11 commented 5 years ago

According to what you said, the hash of the file introduced by index.html under dist was not added after packaging image image

shonny-ua commented 5 years ago

what contain rev/css/rev-manifest.json and rev/script/rev-manifest.json?

chaochao11 commented 5 years ago

yes, contain image rev-manifest.json

{
  "index.css": "index-653fc57696.css"
}

rev-manifest.json

{
  "code.js": "code-1e9c139c3b.js",
  "index.js": "index-845e00e6af.js"
}
shonny-ua commented 5 years ago

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.