maciejwalkowiak / just

Magical 🪄 command line toolkit for developing 🍃 Spring Boot apps
312 stars 6 forks source link

Reload current page upon code changes with Livereload #19

Closed BjoernKW closed 1 year ago

BjoernKW commented 1 year ago

If the Spring Boot application started via just run is a web application (or, more specifically: a web application providing HTML views), Just could launch the default browser with the web application's home page (usually http://localhost:8080) and reload the current page in the browser upon code changes.

While the former (launching a browser from the command line) probably is rather easy, the latter (i.e. live reloading changes) would require a more sophisticated approach, like the live reload servers provided by web frameworks such as Angular or React.

maciejwalkowiak commented 1 year ago

I see this for traditional server side rendered applications but I am not sure how this could be solved for SPA projects. I think usually the frontend code is in the separate git repository. And if it is not, how Just would know what to run and when to run? Suggestions are welcome :-) Also if you have a sample repo somewhere with the setup you have in mind I am happy to take a look.

BjoernKW commented 1 year ago

I see this for traditional server side rendered applications but I am not sure how this could be solved for SPA projects. I think usually the frontend code is in the separate git repository. And if it is not, how Just would know what to run and when

I was specifically thinking about server-side rendering; Thymeleaf, in particular. Like you said, for SPA front-ends that feature is pretty much covered already, for server-side rendering live reloading support for Java applications for the most part is still lacking or involves awkward workarounds with browser extensions.

to run? Suggestions are welcome :-) Also if you have a sample repo somewhere with the setup you have in mind I am happy to take a look.

Sure. Using Wim Deblauwe's Taming Thymeleaf CLI (which is amazing in its own right, by the way) I've created a sample project which shows the behaviour I have in mind (the README.md file contains the required steps for launching the application in live reload mode): https://github.com/BjoernKW/thymeleaf-live-reloading-demo

In a nutshell, just run would have to run an npm run watch command, which in turn would launch a Browsersync instance for implementing the desired behaviour.

maciejwalkowiak commented 1 year ago

Thanks a lot! If I understand it right - it essentially means having live reload of static resources/templates without installing an extension http://livereload.com/extensions/ ..?

BjoernKW commented 1 year ago

Thanks a lot! If I understand it right - it essentially means having live reload of static resources/templates without installing an extension http://livereload.com/extensions/ ..?

Yes, that's it exactly! This makes the project's development setup self-contained and the project ready to be used out-of-the-box.

BjoernKW commented 1 year ago

Thanks a lot! If I understand it right - it essentially means having live reload of static resources/templates without installing an extension http://livereload.com/extensions/ ..?

Besides, with the last update having been made 7 years ago, LiveReload Browser Extensions probably is hopelessly outdated. Their website isn't even available anymore, which really has me wonder why it's still mentioned as a viable solution in the current Spring Boot documentation (https://docs.spring.io/spring-boot/docs/current/reference/html/using.html#using.devtools.livereload), but that's another matter and one Spring Boot core developers probably should have a look at ;-)

Edit: See this issue https://github.com/spring-projects/spring-boot/issues/32111

maciejwalkowiak commented 1 year ago

Thanks @BjoernKW! Got it working in Just 🚀

maciejwalkowiak commented 1 year ago

Because of the dependency on servlet related classes I will make it work for Spring Boot 3.0+

maciejwalkowiak commented 1 year ago

Managed to get it working for both Spring Boot 2.7+ and 3.0+. Only refreshing part. I am not sure if opening browser is the right way to go.