WHMEventSource.js 898 B

12345678910111213141516171819202122232425262728293031
  1. /**
  2. * The hard-coded singleton key for webpack-hot-middleware's client instance.
  3. *
  4. * [Ref](https://github.com/webpack-contrib/webpack-hot-middleware/blob/cb29abb9dde435a1ac8e9b19f82d7d36b1093198/client.js#L152)
  5. */
  6. const singletonKey = '__webpack_hot_middleware_reporter__';
  7. /**
  8. * Initializes a socket server for HMR for webpack-hot-middleware.
  9. * @param {function(*): void} messageHandler A handler to consume Webpack compilation messages.
  10. * @returns {void}
  11. */
  12. function initWHMEventSource(messageHandler) {
  13. const client = window[singletonKey] || require('webpack-hot-middleware/client');
  14. client.useCustomOverlay({
  15. showProblems: function showProblems(type, data) {
  16. const error = {
  17. type,
  18. data,
  19. };
  20. messageHandler(error);
  21. },
  22. clear: function clear() {
  23. messageHandler({ type: 'ok' });
  24. },
  25. });
  26. }
  27. module.exports = initWHMEventSource;