alexisvincent / systemjs-hot-reloader

reloads your modules as needed so that you can have satisfyingly fast feedback loop when developing your app
MIT License
228 stars 36 forks source link

Add pattern or callback for deciding which files should trigger a reload #95

Closed nth-commit closed 7 years ago

nth-commit commented 8 years ago

I'm using angular as components, and each component is contained in one directory with component.js (angular module), component-controller.js and component.html. I'm running a watch on all my component.html files, and creating a compiled component.html.js (using gulp-angular-templatecache).

Naturally the hot reloader will handle reloading these scripts and re-bootstrapping the angular page, so I'd like to ignore changes to html files, which, at the moment, cause an unnecessary reload.

A simple matching callback passed into the HotReloader ctor would do the trick. Takes the filename and checks the result for truthiness to decide whether to do the reload.

e.g.

_reloader = new HotReloader('http://localhost:5776', { match: path => path.endsWith('.js') };

Let me know if I'm on the wrong track here. But as far as I could tell there was nothing (in the listener itself, rather than the emitter) that handled this.

Edit: this is my workaround in the meantime: http://pastebin.com/Jr0e1bqz

peteruithoven commented 8 years ago

Coundn't you also handle this by adding ignores to your watcher (for example chokidator-socket-emitter)?

nth-commit commented 8 years ago

@peteruithoven Yeah, you could but is that the best option? The emitter does it's job by notifying of file change events, is it up to the listener to check whether these events are relevant? I guess it's semantics, but is there a use-case where you might attach different listeners to the same emitter to handle different events?

peteruithoven commented 8 years ago

I disagree I think, mainly because watches have costs, you can't watch unlimited files. That's why your probably also ignoring the git ignores and node_modules. So ignoring those html's "right from the gate" also saves you resources.

alexisvincent commented 7 years ago

@nth-commit If you're still wanting this, a PR would be much appreciated.

Best implementation that I can think of would be having the user pass systemjs-hot-reloader a function that accepts the string module name and returns true or false for inclusion. This is more general then a regex or something like that.

For now I'm closing the issue, feel free to reopen if this is still important to you.