brunch / auto-reload-brunch

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

Custom file extensions #66

Closed rstacruz closed 7 years ago

rstacruz commented 8 years ago

Would you be open to supporting custom file extensions to define different extensions other than .css and .js?

My setup is that I compile my css to application.css.erb for consumption in Rails. This triggers a needless page reload when stylesheets would do. I'd like .css.erb to trigger a compilation.

Proposed solution

I see there's this code that checks if the changes are JS, CSS, or other:

const isCss = file => sysPath.extname(file.path) === '.css';
const isJs = file => sysPath.extname(file.path) === '.js';

const allCss = didCompile && changedFiles.every(isCss);
const allJs = this.liveJs && didCompile && changedFiles.every(isJs);

I propose we implement an option autoReload.match.css (and js), where the value is an anymatch set:

plugins:
  autoReload:
    match:
      css: ['*.css', '*.css.erb']
      js: '*.js'

So something like this should do it:

cssMatch = plugins.autoReload.match.css || '*.css'
isCss = (file) => anymatch(cssMatch, file.path)

I can make a PR for this if you agree with the change.

denysdovhan commented 7 years ago

Solved in #67