Webpack-dev-server: hi,How to clear the default startup information?

Created on 11 Mar 2020  ·  6Comments  ·  Source: webpack/webpack-dev-server

  • [ ] This is a bug
  • [x] This is a modification request

Code

// webpack.config.js
// additional code, remove if not needed.
devServer: {
  contentBase: path.join(__dirname, "dist"),
  compress: true,
  port: 9000
}

Expected Behavior

No output from console

Actual Behavior

http://localhost:9000/
webpack output is served from /build/
Content not from webpack is served from /path/to/dist/

For Bugs; How can we reproduce the behavior?

For Features; What is the motivation and/or use-case for the feature?

Take over by a third party

All 6 comments

What do you mean? You already have all infromation

If I understood correctly, they use case is not output at all.

The quiet option is explicitly bypassed for this logging, which is a bit of a pain if you're using the Node.js API and handling startup logging yourself:

https://github.com/webpack/webpack-dev-server/blob/50c09a4b64c013cca0acb6013bdaa28d0f342149/lib/utils/status.js#L9-L16

Do we need another option to bypass the bypass? The least sarcastic option name I can think of for it is quietStart 😋

if (options.quiet === true && options.quietStart !== true) {
  ...
}

Planned for next, can be solved on master, because it is breaking change

Before that, it can be operated in this way

const backups = {};

function prohibitLog() {
  const key = Object.keys(console);
  for (const name of key) {
    const value = console[name];
    backups[name] = value;
    console[name] = () => {};
  }
}

function displayLog() {
  const key = Object.keys(backups);
  for (const name of key) {
    const value = backups[name];
    console[name] = value;
  }
}

If the server is started through nodejs, it will be intercepted before startup and recovered after startup

  prohibitLog();
  server.listen(port, devServerOptions.host, () => {
    displayLog();
  });

@bosens-China Nice hack!

Since the logging is explicitly done at the info level, I've ended up using:

```js
// XXX Temporarily replace console.info() to prevent WDS startup logging which
// is explicitly done at the info level when the quiet option is set.
let info = console.info
console.info = () => {}
server.listen(port, host, (err) => {
console.info = info
// ...
}

Was this page helpful?
0 / 5 - 0 ratings

Related issues

da2018 picture da2018  ·  3Comments

hnqlvs picture hnqlvs  ·  3Comments

MJ111 picture MJ111  ·  3Comments

daryn-k picture daryn-k  ·  3Comments

antoinerousseau picture antoinerousseau  ·  3Comments