Open myLightLin opened 4 years ago
I got same problem, In gulp4 series. And I found something, But I have no solution.
gulp.task('revCollector', done => {
let dir = fs.readdirSync('/path/to/gen/dist/by/gulp-rev');
// I got notthing , in gulp series
console.log(dir);
// do
done();
})
I found a temporary solution
gulp.task('build-html-rev', function (cb) {
new Promise((resolve, reject) => {
let t = setInterval(() => {
let dir = fs.readdirSync(path.resolve(__dirname, '../../dist'));
if (dir.includes('rev')) {
clearInterval(t);
resolve();
}
}, 10);
}).then(() => {
let dir = fs.readdirSync(path.resolve(__dirname, '../../dist/rev'));
console.log(dir);
gulp.src(['dist/rev/*.json', 'dist/**/*.html'])
.pipe(revCollector())
.pipe(gulp.dest('dist'));
cb();
});
});
Finally I think I solve this problem.
When you call revCollectorTask
before, you should make sure predecessor task over.
But gulp4 official make a bad demo, done
function should use like this.
gulp.task('sass', done => {
gulp.src('./src/css/*.scss')
//....
.pipe(gulp.dest('rev/css'))
.on('finish', () => {done()});
});
Use this code, make gulp when predecessor task over real done
, then call revCollectorTask
@myLightLin
@FantaZZ @myLightLin In gulp4 series.
// .pipe(rename({ suffix: '.min' })) // .pipe(rename({extname: '.min.js'})) // Be careful not to use rename!!!
revCollector config:
.pipe( revCollector({ replaceReved: true, dirReplacements: { // Match original folder path : Output folder path !!! 'assets/css': 'assets/css', '/src/': '/src/assets/js' } }) )
dist html:
`
`
when I run build, the gulp-rev-collector execute does not success Here is my gulpfile.js
And the html file is under the src folder, which looks like this:
And the css rev-manifest.json is :
the js rev-manifest.json is :
Finally, the dist html file does not replace path correctly. What's the problem ?