Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

Fix to default cfg.match settings #69

Merged
merged 1 commit into from
Apr 6, 2016
Merged

Conversation

nshafer
Copy link

@nshafer nshafer commented Apr 6, 2016

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
Copy link
Member

es128 commented Apr 6, 2016

👍

@paulmillr paulmillr merged commit b4b3bbf into brunch:master Apr 6, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants