tapio / live-server

A simple development http server with live reload capability.
http://tapiov.net/live-server/
4.37k stars 487 forks source link

Option to treat CSS files like all other files #185

Open kylecordes opened 7 years ago

kylecordes commented 7 years ago

Currently, live-server has a hardcoded mechanism to reload CSS files differently. This is great for many uses, many static and mostly static websites, it saves a full reload.

However, it is broken for certain other cases. For example I am working with a Angular application using in browser tooling, and need to reload the entire page when a CSS file changes: most of my CSS files belong to an Angular component, not to the page overall.

It would be most ideal to have a switch to turn this special CSS handling off. The switch doesn't need to know anything about Angular or any other particular use case.

I could probably implement such a thing, but would love to get a green light that such a PR is likely to be accepted before doing so.

pavel commented 7 years ago

I assume that a good solution would be to create a PR that allows custom injected.html file. Something like PR #120, but with modifications towards replacing default injected content, rather then appending to it.

tapio commented 7 years ago

I think it would be rather trivial to implement this in core (and I'm not opposed to it), i.e. just sending "reload" command instead of "refreshcss" for all files, without the need to modify injected.html. Though @pavel's idea is more generally useful, and this issue's feature could still be built-in by shipping an alternative injected.html (then again that's more maintenance).

kylecordes commented 7 years ago

It's not clear to me how the PR linked by @pavel would help with this. I'm not looking to do some additional generic injection, just to treat CSS files the same as all the rest. But there might be an aspect that don't understand.

@tapio Yes, I'm hoping for something in core, activated by a trivial command line flag. So people using live-server with the use case where the CSS is processed dynamically, get what they need easily.

I will take a peek at the code again and see how easy it might be to make such a change.

kylecordes commented 7 years ago

Yes, it was rather trivial.

https://github.com/tapio/live-server/pull/186

pavel commented 7 years ago

This would work for your case. Though I would advise extending live-server to allow custom injected.html content. For example, some people would like to change client-side logging (see #171).

kylecordes commented 7 years ago

@pavel I agree it would be great to have the ability to override the injected content, although that feature seems prone to lengthy discussion about exactly how it should work. Also, using such a feature is a lot to ask of a user who simply wants to turn off the special CSS handling.

In the meantime, I hope @tapio likes my PR, to just add the simple specific no CSS inject switch.

pavel commented 7 years ago

@kylecordes

Also, using such a feature is a lot to ask of a user who simply wants to turn off the special CSS handling.

It is either maintainers have this piece of job as code to maintain for the life-time of a project, or a user do it once (and then you can copy your custom injected.html around).

dpsthree commented 7 years ago

@pavel I feel like these are two different concerns both worth considering independent of the other. @kylecordes is describing a growing category of application development. Suggesting everyone that works in an environment that dynamically processes css to ask for the "live" aspect of "live-server" seems a bit much. The addition of a switch would be a much better user experience than requiring the user to specifically list all of their assets in question.