Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update BrowserSync #1457

Merged
merged 2 commits into from
May 7, 2015
Merged

update BrowserSync #1457

merged 2 commits into from
May 7, 2015

Conversation

joemaller
Copy link
Contributor

This PR switches to BrowserSync's recommended "post 2.0.0 syntax" and uses the cleaner stream method for reloading. The stream method offers glob filtering, so we are able to simplify the reload pipe in writeToManifest a bit.

This is compatible with #1448.

@joemaller joemaller mentioned this pull request May 6, 2015
2 tasks
@austinpray
Copy link
Contributor

This reloads javascript twice due to the fact that the .map file gets through. Have the pattern exclude .map files

screenshot 2015-05-06 11 24 53

edit: wrong screenshot lol

edit again: well actually the map files show up as changed in the previous method as well

screenshot 2015-05-06 11 37 58

But the javascript is still injected twice in this PR and only once in master

@michaelbeil
Copy link

lol @austinpray

@austinpray
Copy link
Contributor

@michaelbeil 👀

@joemaller
Copy link
Contributor Author

I was just about to post a question about that over on Discourse... I think it's actually a problem here:
https://github.com/roots/sage/blob/master/gulpfile.js#L239

image

If you remove path.dist from that line, it works correctly and injects CSS changes without a full reload. I'm currently checking into how much else that would affect.

@retlehs
Copy link
Member

retlehs commented May 6, 2015

please stop making unnecessary comments on github, especially emoji ones. lots of us get email notifications for each comment. thanks!

@joemaller
Copy link
Contributor Author

The extra 'File changed' notice likely results from a change in BrowserSync's matcher. (This would then affect #1448 as well.) As noted above, line 239 now seems be recursively reading path.dist.

Checking against master with only BrowserSync updated, any file changed inside dist is now triggering a full reload.

Rolling back to BrowserSync v2.5, nothing happens when touching dist or changing files inside it?! This means changing images or fonts do not trigger a reload either. 😕

.pipe(function() {
return gulpif('**/*.{js,css}', browserSync.reload({stream:true}));
})
.pipe(browserSync.stream, {match: '**/*.{js,css}'})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually just remove this. With the new version the path.dist in files is enough to make things work.

Everything works exactly as expected when you remove this line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seriously? I'll try that too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep it reloads images and such too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that really works. I'm seeing it picking up every changed file in dist, including source maps. The additional files mess up BrowserSync's asset-injection and force a full page reload. With a lot of files, they can also send multiple reload triggers.

pastedgraphic-2

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JavaScript files should be a full page reload. CSS injecting is working properly over here after omitting the inline reload.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you compare my bs_files-only branch with the code you're running? I'm only seeing full reloads from that, no CSS injection and a ton of changed file notices.

@joemaller
Copy link
Contributor Author

I'm testing two solutions:

  1. Change the BrowserSync files array to include path.dist + '{fonts,images}/**/*'
  2. Remove path.dist from the BrowserSync files array, then explicitly trigger a reload from the images task and fonts task streams with something like .pipe(browserSync.stream())

I think the second option is probably best.

@austinpray
Copy link
Contributor

Option 1 works great, what's wrong with that? I use option 1 more frequently than all this stream stuff.

edit: sorry was confused. Neither of those options are necessary.

@austinpray austinpray changed the title update BrowserSync, filtered stream reload update BrowserSync May 6, 2015
@joemaller
Copy link
Contributor Author

Using BrowserSync's stream support means there's no need to watch output files for changes-- the output files' contents are already being piped through the stream. This saves the overhead of additional file watches and reading back the same file we just wrote from the task. It doesn't make sense to watch a stream's output file for changes when the stream itself is available.

I think this should be nailed down now.

Two other branches were pushed to my fork to isolate the solutions described above for testing: bs_path-dist-mod and bs_files-only.

@austinpray
Copy link
Contributor

I just tested out https://github.com/joemaller/sage/tree/bs_path-dist-mod

Yeah let's definitely do what you have currently on the PR. Works perfectly. Also you are right: the less files we watch the better. Especially on Windows.

@@ -198,7 +196,8 @@ gulp.task('scripts', ['jshint'], function() {
gulp.task('fonts', function() {
return gulp.src(globs.fonts)
.pipe(flatten())
.pipe(gulp.dest(path.dist + 'fonts'));
.pipe(gulp.dest(path.dist + 'fonts'))
.pipe(browserSync.stream());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

austinpray added a commit that referenced this pull request May 7, 2015
@austinpray austinpray merged commit ddb71b3 into roots:master May 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants