Skip to content

onBeforeSetupMiddleware server isn't accessible #3121

@jimblue

Description

@jimblue
  • Operating System: MacOS v11.2.3

  • Node Version: v15.12.0

  • NPM Version: v7.7.5

  • webpack Version: v5.28.0

  • webpack-dev-server Version: v4.0.0-beta.1

  • Browser: Chrome ARM v89.0.4389.90

  • This is a bug

  • This is a modification request

Code

When I was using webpack-dev-server v3, I was configuring the before option like below.

// webpack.config.js

 before(app, server) {
    const files = [
      path.resolve(rootFolder, 'resources/views/**/*.html.twig'),
      path.resolve(rootFolder, 'content/collections/**/*.md')
    ]

    // Reload the browser on content/template files change
    chokidar.watch(files).on('all', () => {
      server.sockWrite(server.sockets, 'content-changed')
    })
  },

Since I've upgrade to webpack-dev-server v4.0.0-beta.1 this is not working even if I've follow the release notes.
I'm getting an error : TypeError: Cannot read property 'sockWrite' of undefined
I've looked at the source code to understand how the new onBeforeSetupMiddleware but sadly, nothing I've tried worked...

Any help would really appreciated, thank you 😅 !

// webpack.config.js

 onBeforeSetupMiddleware({ server, sockets }) {
    const files = [
      path.resolve(rootFolder, 'resources/views/**/*.html.twig'),
      path.resolve(rootFolder, 'content/collections/**/*.md')
    ]

    // Reload the browser on content/template files change
    chokidar.watch(files).on('all', () => {
      server.sockWrite(sockets, 'content-changed')
    })
  },

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions