sindresorhus / gulp-rev

Static asset revisioning by appending content hash to filenames: `unicorn.css` → `unicorn-d41d8cd98f.css`
MIT License
1.54k stars 217 forks source link

Garbled manifest file #115

Closed austerus closed 9 years ago

austerus commented 9 years ago

Hello,

I am trying to use gulp-rev to have a cache busting system alongside a Symfony2 application, but when I try to use it my gulp file, it always results in some very random contents of the manifest file.

How it looks like in gulp:

function addCss(paths, output) {
    gulp.src(paths)
        .pipe(plugins.buffer())
        .pipe(plugins.rename(output))
        .pipe(plugins.rev())
        .pipe(gulp.dest(config.webFolder))
        .pipe(plugins.rev.manifest('dist/rev-manifest.json', {base: process.cwd()+'/dist', merge: true}))
        .pipe(gulp.dest('dist'));
}

Task where this is called:

gulp.task('css-all', function() {
    addCss('CoreBundle/Resources/css/inspinia/animate.css', 'css/inspinia/animate.css');
    addCss('CoreBundle/Resources/css/bootstrap.css', 'css/bootstrap.css');
    addCss('CoreBundle/Resources/css/deploy.css', 'css/deploy.css');
})

Resulting manifest file:

{
  "css/core/bootstrap.css": "css/core/bootstrap-dc6f4d3c4a.css"
}ploy.css": "css/core/deploy-dc6f4d3c4a.css"
}8dd.css"
}

The manifest contents changes every time the task runs, sometimes it results in one correct file but most of the times it has this partial content.

This happens regardless whether I use buffer or not.

Is there something I'm doing wrong or is there an issue?

Thanks & regards

gkatsanos commented 9 years ago

+1

danbender commented 9 years ago

+1

web-party commented 9 years ago

:+1:

sinaler commented 9 years ago

++1;

BerkeleyTrue commented 9 years ago

Because you are merging the resulting manifest file and you have concurrent(parallel) tasks running at once, in some situations this will result in two streams trying to write the file at once.

If you instead make these separate task run in series, one after the other completes, that should solve your problem.

Another possible solution is to remove the merge feature, give each manifest its own name, and add a new gulp task that watches the resulting files for changes, src's them, merges them, then outputs it to the desired filename.

chrisnew commented 9 years ago

Still have a similar issue with concurrent rev calls. Would it be possible to lock the rev file while working with it and let the other tasks wait for unlock? merge doesn't for me work, the tasks keep overwriting the manifest file mutually.

bobthecow commented 9 years ago

No, locking is not the right answer. Do what @BerkeleyTrue said and you should be good :)

BerkeleyTrue commented 9 years ago

Here is an example of how I'm accomplishing this. https://github.com/FreeCodeCamp/FreeCodeCamp/blob/staging/gulpfile.js#L274

Apologies for the messy file. I went with option two because I had so many different manifest files.

Anyone out there know of packages that can build manifest files in the same fashion using the command line? At the moment we are using gulp to build these in production, but I would like to remove the need for gulp on our production servers.

ghidinelli commented 9 years ago

Here's my approach to solving this: https://gist.github.com/ghidinelli/e9806063ddbfa74bed7e

Generate the rev-manifest.json file manually from the files in your dist folder and make sure that runs after your parallelized styles/scripts tasks by using the run-sequence plugin.

torifat commented 9 years ago

@austerus Closing this issue. If you still need any assistance then reopen it please. Thanks.