Skip to content
This repository has been archived by the owner on Apr 8, 2019. It is now read-only.

[feat]: pass options in listening event #132

Closed
1 of 3 tasks
alexander-akait opened this issue May 11, 2018 · 0 comments · Fixed by #136
Closed
1 of 3 tasks

[feat]: pass options in listening event #132

alexander-akait opened this issue May 11, 2018 · 0 comments · Fixed by #136

Comments

@alexander-akait
Copy link
Member

alexander-akait commented May 11, 2018

  • Operating System: Ubuntu 17.10
  • Node Version: 10.1.0
  • NPM Version: 6.0.1
  • webpack Version: 4.8.1
  • webpack-serve Version: 0.3.2

This issue is for a:

  • bug
  • feature request
  • modification request

Code

CLI Command
  $ webpack-serve
webpack.config.js

From https://github.com/webpack-contrib/webpack-serve/blob/master/docs/addons/watch-content.config.js

{
  content: [__dirname],
  hot: {
    host: 'localhost',
    port: 8090,
  },
  on: {
    listening(server) {
      const socket = new WebSocket('ws://localhost:8090');
      const watchPath = __dirname;
      const options = {};
      const watcher = chokidar.watch(watchPath, options);

      watcher.on('change', () => {
        const data = {
          type: 'broadcast',
          data: {
            type: 'window-reload',
            data: {},
          },
        };

        socket.send(stringify(data));
      });

      server.on('close', () => {
        watcher.close();
      });
    },
  },
};

Expected Behavior

Second arguments in listening event should be options

Actual Behavior

Second argument is undefined. Impossible run multiple instances without hack and workaround for watching content

How Do We Reproduce?

Use this repo https://github.com/webpack-contrib/webpack-serve/blob/master/docs/addons/watch-content.config.js (remove hot.port) and run multiple instances.

New Feature Use Case

Why?

When i create const socket = new WebSocket('ws://localhost:8090'); (hardcode host and port) and using auto search available port (i.e. don't use port in settings) it is impossible get resolved port for socket server.

If second argument will be passed i can do like this:

{
  content: [__dirname],
  hot: {
    host: 'localhost',
    port: 8090,
  },
  on: {
    listening(server, options) {
      const socket = new WebSocket(`ws://${options.hot.host}:${options.hot.port}`);
      const watchPath = __dirname;
      const options = {};
      const watcher = chokidar.watch(watchPath, options);

      watcher.on('change', () => {
        const data = {
          type: 'broadcast',
          data: {
            type: 'window-reload',
            data: {},
          },
        };

        socket.send(stringify(data));
      });

      server.on('close', () => {
        watcher.close();
      });
    },
  },
};
shellscape added a commit that referenced this issue May 12, 2018
* feat: improve event parameters

* docs: add, update event documentation

* fixes #132
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants