codymikol / karma-webpack

Karma webpack Middleware
MIT License
830 stars 221 forks source link

feat(karma-webpack): added livereload capabilities #500

Closed sprilukin closed 3 years ago

sprilukin commented 3 years ago

feat(karma-webpack): added livereload capabilities

This PR contains a:

Motivation / Use-Case

Read use case here: #499

Breaking Changes

The only breaking change is: if the user already used devServer webpack config property karma-webpack will be started in livereload mode. This could be improved by adding some other config property that will tell karma-webpack to use the old behavior

Additional Info

Disclaimer: This PR is not final because i'm not an expert neither in karma-webpack nor in webpack/webpack-dev-server

Some decisions should be made for this PR:

Support for new webpack config property

This PR adds support for webpack devServer config property.

If devServer property is added in the webpack config the following flow is used:

codymikol commented 3 years ago

Hey @sprilukin , thanks for making a PR, its really appreciated.

I'm a bit hesitant to add webpack-dev-server as another dependency to the project. Is there some reason that these reporters cannot work directly with karma-webpack given we add hooks to webpack rebuilds?

sprilukin commented 3 years ago

Hi, @codymikol. karma-webpack hooks can not force the browser page to be reloaded. Instrumentation of the source code should be done to achieve this - client code in the browser should use a socket connection to listen for any changes and reload the page. This is what webpack-dev-server does. At least i did not found any other ways to achieve this behavior.

I managed to create my own plugin based on karma-webpack to achieve the same behavior: https://github.com/sprilukin/karma-webpack-livereload so if you do not think that this could be part of the karma-webpack project, you can simply close this PR.

codymikol commented 3 years ago

Ok, thank you again for your contribution!