brunch / auto-reload-brunch

Adds automatic browser reloading support to brunch.
88 stars 30 forks source link

Fix to default cfg.match settings #69

Closed nshafer closed 8 years ago

nshafer commented 8 years ago

A recent change to how CSS and JS files are detected for live injection has broken the behavior for probably most projects. This is specifically in relation to PR #67 and commit 8239eb9. The files being matched are output files, which in a default brunch project will be public/app.css. However, the default glob *.css will fail to match against this pattern due to the directory in the path.

> anymatch('*.css', 'public/app.css')
false

Due to this, all CSS changes are causing a full page reload instead of injection, which is by far the coolest features of this module.

I can think of two ways to revert the behavior to match the old behavior of sysPath.extname(file.path) === '.css':

  1. directory matching glob: **/*.css
  2. Regex: /.css$/

I did a comparison of the two, and regex is faster, so I went with that for this PR.

$ node bench.js 
regex x 703,544 ops/sec ±2.97% (67 runs sampled)
glob x 533,130 ops/sec ±3.79% (66 runs sampled)
Fastest is regex

For now a workaround is to add this to your brunch-config.js:

  plugins: {
    autoReload: {
      match: {
        stylesheets: /.css$/,
        javascripts: /.js$/
      }
    }
  }

I also updated the tests to more reflect a typical path for the module.

Thanks, Nate

es128 commented 8 years ago

👍