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

watch content example break #276

Closed
Sunshine168 opened this issue Aug 23, 2018 · 2 comments
Closed

watch content example break #276

Sunshine168 opened this issue Aug 23, 2018 · 2 comments

Comments

@Sunshine168
Copy link

Sunshine168 commented Aug 23, 2018

  • Operating System:macOs High Sierra
  • Node Version:9.8.0
  • NPM Version:5.6
  • webpack Version:4.16.5
  • webpack-serve Version:2.0.2

Expected Behavior

work well

Actual Behavior

server.on is not a function

Code

    serve: {
      hotClient: {
        host: 'localhost',
        port: 8090
      },
      compress: true,
      content: outputPath,
      on: {
        listening(server) {
          console.log(server);
          const socket = new WebSocket('ws://localhost:8090');
          const watchPath = outputPath;
          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();
          });
        }
      }
    }
  // additional code, HEY YO remove this block if you don't need it

How Do We Reproduce?

BTW doc watch content is outdating ,

  // hot may hotClient
  hot: {  
    host: 'localhost',
    port: 8090,
  },
@Sunshine168
Copy link
Author

Sunshine168 commented Aug 23, 2018

i fixed it , Actually the config should be

module.exports.serve = {
  content: [__dirname],
  hotClient: {
    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();
      });
    },
  },
};

@alexander-akait
Copy link
Member

DEPRECATED. Please use webpack-dev-server (he is in support and update mode again). Feel free to create a issue if some features are not implemented in webpack-dev-server.

Why deprecated webpack-serve ?

Thanks for using webpack! We apologize for the inconvenience. In the future, we will avoid such situations.

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

No branches or pull requests

2 participants