web 3d图形渲染器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
871 B

  1. /* global __webpack_dev_server_client__ */
  2. const url = require('native-url');
  3. const getSocketUrlParts = require('./utils/getSocketUrlParts');
  4. /**
  5. * Initializes a socket server for HMR for webpack-dev-server.
  6. * @param {function(*): void} messageHandler A handler to consume Webpack compilation messages.
  7. * @param {string} [resourceQuery] Webpack's `__resourceQuery` string.
  8. * @returns {void}
  9. */
  10. function initWDSSocket(messageHandler, resourceQuery) {
  11. if (typeof __webpack_dev_server_client__ !== 'undefined') {
  12. const SocketClient = __webpack_dev_server_client__;
  13. const urlParts = getSocketUrlParts(resourceQuery);
  14. const connection = new SocketClient(url.format(urlParts));
  15. connection.onMessage(function onSocketMessage(data) {
  16. const message = JSON.parse(data);
  17. messageHandler(message);
  18. });
  19. }
  20. }
  21. module.exports = initWDSSocket;