arvil
arvil

Reputation: 920

webpack-dev-server Tell dev server to reload the browser when any file matching a glob got updated?

I have a question. It seems the webpack-dev-server documentation only mentions watchContentBase option which watches the content base directory. But is it possible to use WDS to also watch a glob pattern like ["./**/*.php"] for file changes and reload the browser?

Currently I am using BrowserSync to do this, but I feel this is redundant.

I found an internal method of WDS .watch( <pattern> ), but not sure how to insert this inside the webpack.config.js

Hope somebody can help.

Regards,

Upvotes: 0

Views: 184

Answers (2)

Steve Gallant
Steve Gallant

Reputation: 36

First, thank you because your question was my answer - was trying to figure out where the server._watch method came from after seeing it in a tutorial project.

The way this method was used (successfully) in the tutorial was under the devServer.before method in webpack.config.js:

module.exports = {
  devServer: {
    before: (app, server) => {
      server._watch('./app/**/*.html');
    },
  }
}

Upvotes: 1

felixmosh
felixmosh

Reputation: 35473

You can use extra-watch-webpack-plugin that does exactly that

Upvotes: 1

Related Questions