BrowserSync / browser-sync

Keep multiple browsers & devices in sync when building websites. https://browsersync.io
https://discord.gg/2d2xUThp
Apache License 2.0
12.18k stars 756 forks source link

Browsersync does not wait for file changes to complete. #1321

Closed bigfanjs closed 7 years ago

bigfanjs commented 7 years ago

Issue details

It seems like Browser-sync is not waiting for files changes until they complete. In a case of a building script where it might take some time to bundle a punch of files, Browsersync only detects when we actually save. Once I save it renders a blank page and I have to refresh the browser manually to see the result.

I would be grateful if there is something like this:

watchify src/javascripts/main.js -o dist/bundle.js --end "browser-sync reload"

Steps to reproduce/test case

{
  "scripts": {
     "build:js": "browserify -d src/javascripts/main.js > dist/bundle.js -t [babelify] -t [uglifyify -cm]",
     "watch:js": "watchify -d src/javascripts/main.js -o dist/bundle.js -t [babelify] -t [uglifyify -cm]",
     "browsersync": "browser-sync start --server \"dist\" --files \"dist\"",
     "watch": "shell-exec \"npm run browsersync\" \"npm run watch:js\""
   }
}

Please specify which version of Browsersync, node and npm you're running

Affected platforms

Browsersync use-case

If CLI, please paste the entire command below

browser-sync start --server "dist" --files "dist"

bigfanjs commented 7 years ago

I came up with a couple of solutions:

The first is to use Nodemon which seems to be waiting for the changed files until they actually finish:

{
   "scirpts": {
       "build:js": "browserify -d src/javascripts/main.js -o dist/bundle.js -t [babelify] -t [uglifyify]",
       "watch:js": "watchify -d src/javascripts/main.js -o dist/bundle.js -t [babelify] -t [uglifyify]",
       "browsersync": "browser-sync start --server \"dist\"",
       "notify": "nodemon --watch dist/ --exec \"browser-sync reload\"",
       "watch": "shell-exec \"browsersync\" \"notify\" \"watch:js\""
   }
}

The second solution is to give up on all these tools and rather rely on Webpack which provides tons of features out of the box including Hot Module Replacment(HMR) which further resolves the issue.