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

Manually tell BrowserSync a file has changed through CLI #533

Closed
hgl opened this issue Mar 25, 2015 · 5 comments
Closed

Manually tell BrowserSync a file has changed through CLI #533

hgl opened this issue Mar 25, 2015 · 5 comments

Comments

@hgl
Copy link

hgl commented Mar 25, 2015

I'm using watchman to watch files, and once files changed, it will run my build step.

Currently, I ask BrowserSync to watch the build directory, which seems to be inefficient (watch source file change -> run build step -> watch build file change -> refresh browser).

I wonder if it's possible to manually tell BrowserSync to refresh the browser after my build step is done (watch source file change -> run build step -> refresh browser)?

Maybe something like:

$ browser-sync start --server app &
$ browser-sync refresh # browsers will be refreshed after this command is done

or by sending signal to the running browser-sync instance

$ browser-sync start --server app &
$ kill -HUP $!

Or I'm doing it wrong? What's the correct way to use BrowserSync when there is a build step involved?

@shakyShane
Copy link
Contributor

@hgl - we want to implement this asap - but we are stuck on how to send signals between two node processes. BrowserSync/recipes#2 (comment)

If you could shed some light, we'd be extremely greatful.

@hgl
Copy link
Author

hgl commented Apr 1, 2015

I guess we can send signals via direct http requests? For example, browser-sync start starts a server, browser-sync refresh talks to the server via http to ask it to refresh. karma uses this architecture for its karma start and karma run commands.

However, I now do realize a downside of manual refreshing: BrowserSync is no longer able to know which files are changed. So it's no longer able to do a quick css update. Every manual fresh must fresh the whole page.

I now find out that by setting reloadDelay to 0. It's actually pretty fast for BrowserSync to notice build file changes. The only problem I encounter is that if the html page is updated by the build step, BrowserSync sometimes refresh the browser to a blank page, manually refresh the browser again fixes the problem. I'm still yet to identify the cause. But fixing this should make BrowserSync very pleasant to use.

@shakyShane
Copy link
Contributor

Ahhh the http idea sounds perfect.

We could also send a bunch of files in the request no problem, why not

# kick it off
browser-sync start --server --port 3000

# for file injection
browser-sync reload --port 3000 --files="core.css,styles.css"

# for normal reloading
browser-sync reload --port 3000

This sounds totally do-able to me - the only downside being that the port must be given each time to identify the running instance

@hgl
Copy link
Author

hgl commented Apr 1, 2015

the only downside being that the port must be given each time to identify the running instance

I guess browser-sync reload can read the same config file as browser-sync start does to find the port. If users didn't use a config file then they have to specify the port again.

browser-sync reload --port 3000 --files="core.css,styles.css"

How does this file injection work? To me it looks like telling BrowserSync to only reload those files.

@shakyShane shakyShane changed the title Manually tell BrowserSync a file has changed? Manually tell BrowserSync a file has changed through CLI Apr 2, 2015
@shakyShane
Copy link
Contributor

Docs coming soon, but this is in 2.6.0 check the release notes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants