gulp-buster icon indicating copy to clipboard operation
gulp-buster copied to clipboard

Multiple busting tasks overwrites busters.json?

Open Dylan190774 opened this issue 8 years ago • 7 comments

I created seperate busting tasks in gulpfor javascript files and for css files, to keep things fast (only build the files that have changed).

When I do just gulp everything works fine: both the css and js files are inbusters.json. But when a busting task is called seperately, for example by a watch, then the old busters.json that contained all files is overwritten and only contains the files that were in that specific task.

Any way to avoid this?

Dylan190774 avatar May 10 '16 23:05 Dylan190774

Can you show the code of your gulp task(s) that cause the issue?

As long as you have the same output name (busters.json) and run the tasks in the same process, the hashes should be joined together in the same file. The point is to pass all files through gulp-buster at least once in the process, so their hashes stay up-to-date and overwrite outdated busters.json.

UltCombo avatar May 10 '16 23:05 UltCombo

My gulpfile looks something like this :

gulp.task('bust_css', ['css_build'],  function() {

  return gulp.src([
                    'public/css/**/*.css'
                 ])
             .pipe(bust('busters.json'))
             .pipe(gulp.dest('public'));

});


gulp.task('bust_js', ['js_build'],  function() {

  return gulp.src([
                    'public/js/**/*.js'                   
                 ])
             .pipe(bust('busters.json'))
             .pipe(gulp.dest('public'));
});

gulp.watch('resources/css/**/*.css', ['css_build','bust_css']);
gulp.watch('resources/js/**/*.js', ['js_build','bust_js']);

The idea is that each watcher only watches certain files (css or js) and then calls its build task and the bust task afterwards. But when gulp watch is active, only one of the two tasks is called, so busters.json gets overwritten. I solved it for now, by using different filenames for css and js, but ideally I would prefer just one manifest file.

The reason I'm not using one big bust task for everything, is because of the dependencies for each bust task, which make sure that the build tasks are done before the busting. And building everything again when only one file changes slows the building down, of course.

Dylan190774 avatar May 11 '16 00:05 Dylan190774

Oh, I see. In fact, I've considered adding this feature in the past, but there were quite a few issues as mentioned in the README:

A feature to allow inputting an already-generated hashes file was considered in order to avoid having to pipe all the to-be-busted files at startup, but that seems to bring more cons than pros -- the auto-cleanup of deleted files' hashes would no longer happen, outdated hashes could stay in the output hashes file if the to-be-busted files were edited while gulp was not running, and finally it'd also be incompatible with the transform and formatter features.

But I believe such a feature could still be useful in some cases. Perhaps we can add an option to pass in an initial hashes object, but the user would have to be mindful of the quirks above.

UltCombo avatar May 11 '16 00:05 UltCombo

Hello @UltCombo

what is the current status on this? I found your package and liked it but ran into the same issue as @Dylan190774 .

Regarding your cons:

  • Normally you don't change your productive asset structure that often. For example if you started with styles.css and scripts.js, you will propably stay with those filenames. And even if you change the scripts.js to local.js and vendor.js later on, it is unlikely that you run into any issues. Because you will adjust the name in your views as well, so there should be no reference anymore to this outdated hash. So although it is unclean to have an invalid reference in your json-file, it won't be a big problem.
  • Normally you don't change your productive asset files manually, because most of the times they are a concatenation of different source files and often even minified/uglyfied. And this is done by gulp.

It is perfectly fine to mention those cons in the README, because the users have to be aware of those pitfalls. But I think those pitfalls are not so bad that the feature @Dylan190774 asked for shouldn't be implemented.

Thanks in advance for any infos or thoughts on this. Cheers

hpawe01 avatar Nov 08 '16 19:11 hpawe01

Yep, I've been considering to add an option such as initialHashes so that you can do:

bust({
  initialHashes: require('busters.json')
})

This option's documentation should have an warning about the pitfalls, I believe that should be enough.

I haven't had much free time lately though, PRs are welcome to speed up the implementation.

UltCombo avatar Nov 08 '16 20:11 UltCombo

Thank you for your reply! Unfortunately I have no experience with PRs or any open source development.

Besides I pursue another build strategy now, so that I need to rev my assets only when preparing my app for production. So I still have different gulp watchers in my development mode, but I don't need to provide each time an existing buster.json as I don't rev the watched files in development mode anymore.

Cheers

hpawe01 avatar Nov 28 '16 10:11 hpawe01

@Dylan190774 - Bust all your static assets at the same time:

gulp.task('bust-all',['js_build','css_build'],function() {
    return gulp.src(['public/js/**/*.js','public/js/**/*.css']).pipe(bust('busters.json'))  
})

gulp.watch([
    'resources/css/**/*.css',
    'resources/css/**/*.js'
],['bust-all']);

akmjenkins avatar Aug 04 '17 22:08 akmjenkins