Z
Z
zatupok30002017-02-10 16:49:21
HTML
zatupok3000, 2017-02-10 16:49:21

gulp-rev not working correctly, what is wrong with my gulp file?

Good afternoon!
Here is part of my gulpfile.js

gulp.task('clean', function(){
    del(['static/build/*.min.*'])
});

gulp.task('build-less', function(){
    gulp.src(['static/legacy/**/*.+(css|less)', 'static/less/**/*.+(css|less)'])
        .pipe(postcss([ nested, short, autoprefixer(), cssnano(), cssnext, cssvariables() ]))
        .pipe(concatCSS('main.css'))
        .pipe(rename('styles.min.css'))
        .pipe(rev())
        .pipe(gulp.dest('static/build'))
        .pipe(rev.manifest({
            base: './',
            merge: true // merge with the existing manifest (if one exists)
        }))
        .pipe(gulp.dest('./'));
});

gulp.task('build-legacy-js', function(){
    gulp.src(['static/legacy/**/*.js'])
        .pipe(concat('all.js'))
        .pipe(rename('bundle.min.js'))
        .pipe(rev())
        .pipe(gulp.dest('static/build'))
        .pipe(rev.manifest({
            base: './',
            merge: true // merge with the existing manifest (if one exists)
        }))
        .pipe(gulp.dest('./'));
});

gulp.task('build-scripts-js', function(){
    gulp.src(['static/js/**/*.js'])
        .pipe(concat('all.js'))
        .pipe(rename('scripts.min.js'))
        .pipe(rev())
        .pipe(gulp.dest('static/build'))
        .pipe(rev.manifest({
            base: './',
            merge: true // merge with the existing manifest (if one exists)
        }))
        .pipe(gulp.dest('./'));
});

gulp.task('default', ['clean', 'build-less', 'build-legacy-js', 'build-scripts-js']);

gulp.task('watch', function(){
    gulp.watch('static/less/*.+(css|less)', ['build-less']);
    gulp.watch('static/js/**/*.js', ['build-scripts-js']);
    gulp.watch('static/legacy/**/*.js', ['build-legacy-js']);
});

The problem is that gulp-rev doesn't always create rev-manifest.json correctly, and I don't understand what the problem is.
For example, inside rev-manifest.json can easily be only
{
  "bundle.min.js": "bundle-af26fd17a0.min.js",
  "scripts.min.js": "scripts-87dd6e8894.min.js"
}

Where is styles.min.css?
It exists in the build folder, but why didn't it get into the manifest?
It is worth noticing that otherwise (after 2, 3) runs of gulp, rev-manifest.json turns out to be correct, but that's not the point - run gulp 20 times!
Help me please.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Dupliy, 2017-05-03
@booomerang

The problem is most likely that gulp runs its tasks asynchronously, i.e. it does not run one after the other, but all at once, and therefore merge sometimes does not work correctly. I had such that the rev manifest file was generally written in parts. And accordingly it was not valid. Something like that:

{
  "bundle.min.js": "bundle-af26fd17a0.min.js"
}4hg28f1v.min.js

I solved the problem by sequential execution of tasks, through return for each, but there are other options .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question